mirror of
https://github.com/wavetermdev/backup.git
synced 2026-08-05 13:57:07 -07:00
Add filewatcher for config files (#63)
This adds the filewatcher and forwards events to the frontend. It also sets up the widgets as something that can be controlled with a config file.
This commit is contained in:
@@ -56,6 +56,7 @@ const workspaceAtom: jotai.Atom<Workspace> = jotai.atom((get) => {
|
||||
}
|
||||
return WOS.getObjectValue(WOS.makeORef("workspace", windowData.workspaceid), get);
|
||||
});
|
||||
const settingsConfigAtom = jotai.atom(null) as jotai.PrimitiveAtom<SettingsConfigType>;
|
||||
const tabAtom: jotai.Atom<Tab> = jotai.atom((get) => {
|
||||
const windowData = get(windowDataAtom);
|
||||
if (windowData == null) {
|
||||
@@ -72,6 +73,7 @@ const atoms = {
|
||||
client: clientAtom,
|
||||
waveWindow: windowDataAtom,
|
||||
workspace: workspaceAtom,
|
||||
settingsConfigAtom: settingsConfigAtom,
|
||||
tabAtom: tabAtom,
|
||||
};
|
||||
|
||||
@@ -173,6 +175,13 @@ function handleWSEventMessage(msg: WSEventType) {
|
||||
console.log("unsupported event", msg);
|
||||
return;
|
||||
}
|
||||
if (msg.eventtype == "config") {
|
||||
const data: WatcherUpdate = msg.data;
|
||||
globalStore.set(settingsConfigAtom, data.update);
|
||||
|
||||
console.log("config", data);
|
||||
return;
|
||||
}
|
||||
if (msg.eventtype == "blockfile") {
|
||||
const fileData: WSFileEventData = msg.data;
|
||||
const fileSubject = getFileSubject(fileData.zoneid, fileData.filename);
|
||||
|
||||
@@ -45,12 +45,21 @@ export const ClientService = new ClientServiceType()
|
||||
|
||||
// fileservice.FileService (file)
|
||||
class FileServiceType {
|
||||
AddWidget(arg1: WidgetsConfigType): Promise<void> {
|
||||
return WOS.callBackendService("file", "AddWidget", Array.from(arguments))
|
||||
}
|
||||
GetSettingsConfig(): Promise<any> {
|
||||
return WOS.callBackendService("file", "GetSettingsConfig", Array.from(arguments))
|
||||
}
|
||||
GetWaveFile(arg1: string, arg2: string): Promise<any> {
|
||||
return WOS.callBackendService("file", "GetWaveFile", Array.from(arguments))
|
||||
}
|
||||
ReadFile(arg1: string): Promise<FullFile> {
|
||||
return WOS.callBackendService("file", "ReadFile", Array.from(arguments))
|
||||
}
|
||||
RemoveWidget(arg1: number): Promise<void> {
|
||||
return WOS.callBackendService("file", "RemoveWidget", Array.from(arguments))
|
||||
}
|
||||
StatFile(arg1: string): Promise<FileInfo> {
|
||||
return WOS.callBackendService("file", "StatFile", Array.from(arguments))
|
||||
}
|
||||
|
||||
@@ -4,12 +4,16 @@
|
||||
import { TabBar } from "@/app/tab/tabbar";
|
||||
import { TabContent } from "@/app/tab/tabcontent";
|
||||
import { atoms, createBlock } from "@/store/global";
|
||||
import * as services from "@/store/services";
|
||||
import * as jotai from "jotai";
|
||||
import * as React from "react";
|
||||
import { CenteredDiv } from "../element/quickelems";
|
||||
|
||||
import "./workspace.less";
|
||||
|
||||
function Widgets() {
|
||||
const settingsConfig = jotai.useAtomValue(atoms.settingsConfigAtom);
|
||||
const newWidgetModalVisible = React.useState(false);
|
||||
async function clickTerminal() {
|
||||
const termBlockDef = {
|
||||
controller: "shell",
|
||||
@@ -18,51 +22,37 @@ function Widgets() {
|
||||
createBlock(termBlockDef);
|
||||
}
|
||||
|
||||
async function clickPreview(fileName: string) {
|
||||
const markdownDef = {
|
||||
view: "preview",
|
||||
meta: { file: fileName },
|
||||
};
|
||||
createBlock(markdownDef);
|
||||
}
|
||||
|
||||
async function clickPlot() {
|
||||
const plotDef: BlockDef = {
|
||||
view: "plot",
|
||||
};
|
||||
createBlock(plotDef);
|
||||
}
|
||||
|
||||
async function clickEdit() {
|
||||
const editDef: BlockDef = {
|
||||
view: "codeedit",
|
||||
};
|
||||
createBlock(editDef);
|
||||
}
|
||||
async function handleWidgetSelect(blockDef: BlockDef) {
|
||||
createBlock(blockDef);
|
||||
}
|
||||
|
||||
async function handleCreateWidget(newWidget: WidgetsConfigType) {
|
||||
await services.FileService.AddWidget(newWidget);
|
||||
}
|
||||
|
||||
async function handleRemoveWidget(idx: number) {
|
||||
await services.FileService.RmWidget(idx);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="workspace-widgets">
|
||||
<div className="widget" onClick={() => clickTerminal()}>
|
||||
<i className="fa fa-solid fa-square-terminal fa-fw" />
|
||||
</div>
|
||||
<div className="widget" onClick={() => clickPreview("~/work/wails/thenextwave/README.md")}>
|
||||
<i className="fa fa-solid fa-files fa-fw" />
|
||||
</div>
|
||||
<div className="widget" onClick={() => clickPreview("~/work/wails/thenextwave/go.mod")}>
|
||||
<i className="fa fa-solid fa-files fa-fw" />
|
||||
</div>
|
||||
<div className="widget" onClick={() => clickPreview("~/work/wails/thenextwave/build/appicon.png")}>
|
||||
<i className="fa fa-solid fa-files fa-fw" />
|
||||
</div>
|
||||
<div className="widget" onClick={() => clickPreview("~")}>
|
||||
<i className="fa fa-solid fa-files fa-fw" />
|
||||
</div>
|
||||
<div className="widget" onClick={() => clickPlot()}>
|
||||
<i className="fa fa-solid fa-chart-simple fa-fw" />
|
||||
</div>
|
||||
<div className="widget" onClick={() => clickEdit()}>
|
||||
<i className="fa-sharp fa-solid fa-pen-to-square"></i>
|
||||
</div>
|
||||
{settingsConfig.widgets.map((data, idx) => (
|
||||
<div className="widget" onClick={() => handleWidgetSelect(data.blockdef)} key={`widget-${idx}`}>
|
||||
<i className={data.icon}></i>
|
||||
</div>
|
||||
))}
|
||||
<div className="widget no-hover">
|
||||
<i className="fa fa-solid fa-plus fa-fw" />
|
||||
</div>
|
||||
|
||||
Vendored
+6
@@ -282,6 +282,12 @@ declare global {
|
||||
updates?: WaveObjUpdate[];
|
||||
};
|
||||
|
||||
// wconfig.WidgetsConfigType
|
||||
type WidgetsConfigType = {
|
||||
icon: string;
|
||||
blockdef: BlockDef;
|
||||
};
|
||||
|
||||
// wstore.WinSize
|
||||
type WinSize = {
|
||||
width: number;
|
||||
|
||||
+2
-1
@@ -1,7 +1,7 @@
|
||||
// Copyright 2024, Command Line Inc.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { globalStore, globalWS, initWS } from "@/store/global";
|
||||
import { atoms, globalStore, globalWS, initWS } from "@/store/global";
|
||||
import * as services from "@/store/services";
|
||||
import * as WOS from "@/store/wos";
|
||||
import * as React from "react";
|
||||
@@ -37,6 +37,7 @@ document.addEventListener("DOMContentLoaded", async () => {
|
||||
const client = await WOS.loadAndPinWaveObject<Client>(WOS.makeORef("client", clientId));
|
||||
const waveWindow = await WOS.loadAndPinWaveObject<WaveWindow>(WOS.makeORef("window", windowId));
|
||||
await WOS.loadAndPinWaveObject<Workspace>(WOS.makeORef("workspace", waveWindow.workspaceid));
|
||||
globalStore.set(atoms.settingsConfigAtom, await services.FileService.GetSettingsConfig());
|
||||
services.ObjectService.SetActiveTab(waveWindow.activetabid); // no need to wait
|
||||
const reactElem = React.createElement(App, null, null);
|
||||
const elem = document.getElementById("main");
|
||||
|
||||
Reference in New Issue
Block a user