reload node config when reload window
This commit is contained in:
1 parent
5fb3a650fb
commit
5fb19c5c08
7 files changed
+66
-17
No files matched your search
+33
-8
@@ -109,6 +109,7 @@ if (!app.requestSingleInstanceLock()) {
|
|||||||
|
|
||||||
interface Workspace {
|
interface Workspace {
|
||||||
projectPath?: string;
|
projectPath?: string;
|
||||||
|
files: { path: string; active: boolean }[];
|
||||||
window: BrowserWindow;
|
window: BrowserWindow;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -146,7 +147,7 @@ async function createWindow(projectPath?: string) {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const workspace = { projectPath, window: win };
|
const workspace = { projectPath, window: win, files: [] };
|
||||||
windows.push(workspace);
|
windows.push(workspace);
|
||||||
|
|
||||||
win.maximizable = true;
|
win.maximizable = true;
|
||||||
@@ -164,9 +165,6 @@ async function createWindow(projectPath?: string) {
|
|||||||
// Test actively push message to the Electron-Renderer
|
// Test actively push message to the Electron-Renderer
|
||||||
win.webContents.on("did-finish-load", () => {
|
win.webContents.on("did-finish-load", () => {
|
||||||
win.webContents.setZoomFactor(1);
|
win.webContents.setZoomFactor(1);
|
||||||
if (workspace.projectPath) {
|
|
||||||
win?.webContents.send("open-project", workspace.projectPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
const nextWin = BrowserWindow.getAllWindows().at(-1);
|
const nextWin = BrowserWindow.getAllWindows().at(-1);
|
||||||
if (nextWin) {
|
if (nextWin) {
|
||||||
@@ -224,7 +222,7 @@ app.on("activate", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// New window example arg: new windows url
|
// New window example arg: new windows url
|
||||||
ipcMain.handle("open-win", (event, arg) => {
|
ipcMain.handle("open-win", (e, arg) => {
|
||||||
if (arg) {
|
if (arg) {
|
||||||
let workspace = windows.find((v) => v.projectPath === arg);
|
let workspace = windows.find((v) => v.projectPath === arg);
|
||||||
if (workspace) {
|
if (workspace) {
|
||||||
@@ -232,7 +230,7 @@ ipcMain.handle("open-win", (event, arg) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
workspace = windows.find((v) => v.window.webContents.id === event.sender.id);
|
workspace = windows.find((v) => v.window.webContents.id === e.sender.id);
|
||||||
if (workspace && !workspace.projectPath) {
|
if (workspace && !workspace.projectPath) {
|
||||||
workspace.projectPath = arg;
|
workspace.projectPath = arg;
|
||||||
workspace.window.webContents.send("open-project", arg);
|
workspace.window.webContents.send("open-project", arg);
|
||||||
@@ -243,12 +241,39 @@ ipcMain.handle("open-win", (event, arg) => {
|
|||||||
createWindow(arg);
|
createWindow(arg);
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcMain.handle("trashItem", (_, arg) => {
|
ipcMain.handle("ready-to-show", (e) => {
|
||||||
|
const workspace = windows.find((v) => v.window.webContents.id === e.sender.id);
|
||||||
|
if (workspace && workspace.projectPath) {
|
||||||
|
workspace.window.webContents.send("open-project", workspace.projectPath, workspace.files);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
ipcMain.handle("open-file", (e, path: string) => {
|
||||||
|
const workspace = windows.find((v) => v.window.webContents.id === e.sender.id);
|
||||||
|
if (workspace) {
|
||||||
|
const entry = workspace.files.find((v) => v.path === path);
|
||||||
|
workspace.files.forEach((v) => (v.active = false));
|
||||||
|
if (entry) {
|
||||||
|
entry.active = true;
|
||||||
|
} else {
|
||||||
|
workspace.files.push({ path, active: true });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
ipcMain.handle("close-file", (e, path: string) => {
|
||||||
|
const workspace = windows.find((v) => v.window.webContents.id === e.sender.id);
|
||||||
|
if (workspace) {
|
||||||
|
workspace.files = workspace.files.filter((v) => v.path !== path);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
ipcMain.handle("trash-item", (_, arg) => {
|
||||||
arg = arg.replace(/\//g, path.sep);
|
arg = arg.replace(/\//g, path.sep);
|
||||||
shell.trashItem(arg).catch((e) => console.error(e));
|
shell.trashItem(arg).catch((e) => console.error(e));
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcMain.handle("showItemInFolder", (_, arg) => {
|
ipcMain.handle("show-item-in-folder", (_, arg) => {
|
||||||
arg = arg.replace(/\//g, path.sep);
|
arg = arg.replace(/\//g, path.sep);
|
||||||
shell.showItemInFolder(arg);
|
shell.showItemInFolder(arg);
|
||||||
});
|
});
|
||||||
@@ -351,7 +351,13 @@ export const Editor: FC<EditorProps> = ({ onChange, data: editor, ...props }) =>
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}, [editorSize, workspace.editing, graph, t]);
|
}, [editorSize, workspace.editing, graph]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (graph) {
|
||||||
|
graph.refresh();
|
||||||
|
}
|
||||||
|
}, [t]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
|
|||||||
@@ -481,7 +481,7 @@ const alertDeleteFile = (path: string) => {
|
|||||||
if (path === workspace.editing?.path) {
|
if (path === workspace.editing?.path) {
|
||||||
workspace.close(path);
|
workspace.close(path);
|
||||||
}
|
}
|
||||||
ipcRenderer.invoke("trashItem", path);
|
ipcRenderer.invoke("trash-item", path);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{i18n.t("moveToTrash")}
|
{i18n.t("moveToTrash")}
|
||||||
@@ -526,7 +526,7 @@ const alertDeleteFolder = (path: string) => {
|
|||||||
workspace.close(editor.path);
|
workspace.close(editor.path);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
ipcRenderer.invoke("trashItem", path);
|
ipcRenderer.invoke("trash-item", path);
|
||||||
alert.destroy();
|
alert.destroy();
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
@@ -812,7 +812,7 @@ export const Explorer: FC = () => {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "revealFile":
|
case "revealFile":
|
||||||
ipcRenderer.invoke("showItemInFolder", node.path);
|
ipcRenderer.invoke("show-item-in-folder", node.path);
|
||||||
break;
|
break;
|
||||||
case "rename": {
|
case "rename": {
|
||||||
if (b3util.isTreeFile(node.path)) {
|
if (b3util.isTreeFile(node.path)) {
|
||||||
|
|||||||
@@ -29,8 +29,8 @@ const getFocusedWebContents = () => {
|
|||||||
return BrowserWindow.getFocusedWindow()?.webContents;
|
return BrowserWindow.getFocusedWindow()?.webContents;
|
||||||
};
|
};
|
||||||
|
|
||||||
ipcRenderer.on("open-project", (_, dir) => {
|
ipcRenderer.on("open-project", (_, dir, files) => {
|
||||||
useWorkspace.getState().init(dir);
|
useWorkspace.getState().init(dir, files);
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcRenderer.on("refresh-app-men", () => {
|
ipcRenderer.on("refresh-app-men", () => {
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ const calcTextWith = (text: string, fontSize?: string) => {
|
|||||||
const metrics = ctx.measureText(text);
|
const metrics = ctx.measureText(text);
|
||||||
width = metrics.width;
|
width = metrics.width;
|
||||||
// width = width - (isMacos ? 1.6 : 0.8);
|
// width = width - (isMacos ? 1.6 : 0.8);
|
||||||
width *= isMacos ? 0.88 : 0.95;
|
width *= isMacos ? 0.88 : 0.98;
|
||||||
textWidthMap.set(key, width);
|
textWidthMap.set(key, width);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { ipcRenderer } from "electron";
|
||||||
import { FC } from "react";
|
import { FC } from "react";
|
||||||
import { useSetting } from "../contexts/setting-context";
|
import { useSetting } from "../contexts/setting-context";
|
||||||
import { message, setGlobalHooks } from "../misc/hooks";
|
import { message, setGlobalHooks } from "../misc/hooks";
|
||||||
@@ -5,6 +6,7 @@ import { message, setGlobalHooks } from "../misc/hooks";
|
|||||||
export const Setup: FC = () => {
|
export const Setup: FC = () => {
|
||||||
if (!message) {
|
if (!message) {
|
||||||
useSetting().load();
|
useSetting().load();
|
||||||
|
ipcRenderer.invoke("ready-to-show");
|
||||||
}
|
}
|
||||||
setGlobalHooks();
|
setGlobalHooks();
|
||||||
return <div></div>;
|
return <div></div>;
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ export interface WorkspaceModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export type WorkspaceStore = {
|
export type WorkspaceStore = {
|
||||||
init: (project: string) => void;
|
init: (project: string, files?: { path: string; active: boolean }[]) => void;
|
||||||
createProject: () => void;
|
createProject: () => void;
|
||||||
openProject: (project?: string) => void;
|
openProject: (project?: string) => void;
|
||||||
batchProject: () => void;
|
batchProject: () => void;
|
||||||
@@ -225,7 +225,7 @@ export const useWorkspace = create<WorkspaceStore>((set, get) => ({
|
|||||||
path: "",
|
path: "",
|
||||||
settings: {},
|
settings: {},
|
||||||
|
|
||||||
init: (path) => {
|
init: (path, files) => {
|
||||||
const workspace = get();
|
const workspace = get();
|
||||||
if (!workspace.workdir) {
|
if (!workspace.workdir) {
|
||||||
try {
|
try {
|
||||||
@@ -236,6 +236,20 @@ export const useWorkspace = create<WorkspaceStore>((set, get) => ({
|
|||||||
workspace.loadNodeDefs();
|
workspace.loadNodeDefs();
|
||||||
workspace.watch();
|
workspace.watch();
|
||||||
useSetting.getState().appendRecent(path);
|
useSetting.getState().appendRecent(path);
|
||||||
|
if (files?.length) {
|
||||||
|
for (const entry of files) {
|
||||||
|
try {
|
||||||
|
const editor = new EditorStore(entry.path);
|
||||||
|
workspace.editors.push(editor);
|
||||||
|
if (entry.active) {
|
||||||
|
workspace.open(editor.path);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
message.error(`invalid file: ${path}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
if (!fs.existsSync(path)) {
|
if (!fs.existsSync(path)) {
|
||||||
@@ -505,6 +519,7 @@ export const useWorkspace = create<WorkspaceStore>((set, get) => ({
|
|||||||
if (editor) {
|
if (editor) {
|
||||||
workspace.onEditingTree(editor);
|
workspace.onEditingTree(editor);
|
||||||
}
|
}
|
||||||
|
ipcRenderer.invoke("open-file", path);
|
||||||
},
|
},
|
||||||
|
|
||||||
close: (path) => {
|
close: (path) => {
|
||||||
@@ -523,6 +538,7 @@ export const useWorkspace = create<WorkspaceStore>((set, get) => ({
|
|||||||
set({ editingNode: undefined, editingTree: undefined });
|
set({ editingNode: undefined, editingTree: undefined });
|
||||||
}
|
}
|
||||||
set({ editing: editting, editors: editors });
|
set({ editing: editting, editors: editors });
|
||||||
|
ipcRenderer.invoke("close-file", path);
|
||||||
},
|
},
|
||||||
|
|
||||||
find: (path) => {
|
find: (path) => {
|
||||||
|
|||||||
Reference in new issue
Block a user