Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: https://github.com/siyuan-note/siyuan/issues/2955

Vanessa4c049b760052
diff --git a/app/electron/main.js b/app/electron/main.js
index 07bef5f1b2..01b53436be 100644
--- a/app/electron/main.js
+++ b/app/electron/main.js
@@ -52,8 +52,10 @@ try {
}
} catch (e) {
console.error(e)
- require('electron').dialog.showErrorBox('创建配置目录失败 Failed to create config directory',
- '思源需要在用户家目录下创建配置文件夹(~/.config/siyuan),请确保该路径具有写入权限。\n\nSiYuan needs to create a configuration folder (~/.config/siyuan) in the user\'s home directory. Please make sure that the path has write permissions.')
+ require('electron').
+ dialog.
+ showErrorBox('创建配置目录失败 Failed to create config directory',
+ '思源需要在用户家目录下创建配置文件夹(~/.config/siyuan),请确保该路径具有写入权限。\n\nSiYuan needs to create a configuration folder (~/.config/siyuan) in the user\'s home directory. Please make sure that the path has write permissions.')
app.exit()
}
@@ -76,7 +78,6 @@ const showErrorWindow = (title, content) => {
frame: false,
icon: path.join(appDir, 'stage', 'icon-large.png'),
webPreferences: {
- nativeWindowOpen: true,
nodeIntegration: true,
webviewTag: true,
webSecurity: false,
@@ -190,7 +191,6 @@ const boot = () => {
trafficLightPosition: {x: 8, y: 8},
webPreferences: {
nodeIntegration: true,
- nativeWindowOpen: true,
webviewTag: true,
webSecurity: false,
contextIsolation: false,
@@ -372,9 +372,6 @@ const initKernel = (workspace, port, lang) => {
frame: false,
icon: path.join(appDir, 'stage', 'icon-large.png'),
transparent: 'linux' !== process.platform,
- webPreferences: {
- nativeWindowOpen: true,
- },
})
const kernelName = 'win32' === process.platform
@@ -390,7 +387,7 @@ const initKernel = (workspace, port, lang) => {
}
if (!isDevEnv || workspaces.length > 0) {
- if (port && "" !== port) {
+ if (port && '' !== port) {
kernelPort = port
} else {
const getAvailablePort = () => {
@@ -421,13 +418,13 @@ const initKernel = (workspace, port, lang) => {
if (isDevEnv && workspaces.length === 0) {
cmds.push('--mode', 'dev')
}
- if (workspace && "" !== workspace) {
+ if (workspace && '' !== workspace) {
cmds.push('--workspace', workspace)
}
- if (port && "" !== port) {
+ if (port && '' !== port) {
cmds.push('--port', port)
}
- if (lang && "" !== lang) {
+ if (lang && '' !== lang) {
cmds.push('--lang', lang)
}
let cmd = `ui version [${appVer}], booting kernel [${kernelPath} ${cmds.join(
@@ -672,7 +669,7 @@ app.whenReady().then(() => {
})
ipcMain.on('siyuan-closetab', (event, data) => {
BrowserWindow.getAllWindows().forEach(item => {
- item.webContents.send('siyuan-closetab', data)
+ item.webContents.send('siyuan-closetab', data)
})
})
ipcMain.on('siyuan-export-pdf', (event, data) => {
@@ -732,6 +729,29 @@ app.whenReady().then(() => {
writeLog('exited ui')
}
})
+ ipcMain.on('siyuan-openwindow', (event, data) => {
+ const win = new BrowserWindow({
+ show: true,
+ backgroundColor: '#FFF',
+ trafficLightPosition: {x: 8, y: 13},
+ width: 1032,
+ height: 650,
+ minWidth: 493,
+ minHeight: 376,
+ fullscreenable: true,
+ frame: 'darwin' === process.platform,
+ icon: path.join(appDir, 'stage', 'icon-large.png'),
+ titleBarStyle: 'hidden',
+ webPreferences: {
+ contextIsolation: false,
+ nodeIntegration: true,
+ webviewTag: true,
+ webSecurity: false,
+ },
+ })
+ win.loadURL(data)
+ require('@electron/remote/main').enable(win.webContents)
+ })
ipcMain.on('siyuan-open-workspace', (event, data) => {
const foundWorkspace = workspaces.find((item, index) => {
if (item.workspaceDir === data.workspace) {
@@ -740,7 +760,7 @@ app.whenReady().then(() => {
}
})
if (!foundWorkspace) {
- initKernel(data.workspace, "", data.lang).then((isSucc) => {
+ initKernel(data.workspace, '', data.lang).then((isSucc) => {
if (isSucc) {
boot()
}
@@ -803,7 +823,6 @@ app.whenReady().then(() => {
})
})
})
-
ipcMain.on('siyuan-lock-screen', () => {
BrowserWindow.getAllWindows().forEach(item => {
item.webContents.send('siyuan-lock-screen')
@@ -818,7 +837,6 @@ app.whenReady().then(() => {
icon: path.join(appDir, 'stage', 'icon-large.png'),
transparent: 'linux' !== process.platform,
webPreferences: {
- nativeWindowOpen: true,
nodeIntegration: true,
webviewTag: true,
webSecurity: false,
@@ -847,7 +865,7 @@ app.whenReady().then(() => {
firstOpenWindow.show()
// 初始化启动
ipcMain.on('siyuan-first-init', (event, data) => {
- initKernel(data.workspace, "", data.lang).then((isSucc) => {
+ initKernel(data.workspace, '', data.lang).then((isSucc) => {
if (isSucc) {
boot()
}
@@ -871,7 +889,7 @@ app.whenReady().then(() => {
if (port) {
writeLog('got arg [--port=' + port + ']')
}
- initKernel(workspace, port, "").then((isSucc) => {
+ initKernel(workspace, port, '').then((isSucc) => {
if (isSucc) {
boot()
}
@@ -889,10 +907,6 @@ app.on('open-url', (event, url) => { // for macOS
}
})
-app.on('browser-window-created', (_, window) => {
- require("@electron/remote/main").enable(window.webContents)
-})
-
app.on('second-instance', (event, argv) => {
writeLog('second-instance [' + argv + ']')
let workspace = argv.find((arg) => arg.startsWith('--workspace='))
@@ -919,7 +933,7 @@ app.on('second-instance', (event, argv) => {
return
}
if (workspace) {
- initKernel(workspace, port, "").then((isSucc) => {
+ initKernel(workspace, port, '').then((isSucc) => {
if (isSucc) {
boot()
}
@@ -969,7 +983,6 @@ app.on('before-quit', (event) => {
})
const {powerMonitor} = require('electron')
-const {write} = require('fs')
powerMonitor.on('suspend', () => {
writeLog('system suspend')
diff --git a/app/src/constants.ts b/app/src/constants.ts
index fa68e68c4a..5b80e191e3 100644
--- a/app/src/constants.ts
+++ b/app/src/constants.ts
@@ -29,6 +29,7 @@ export abstract class Constants {
public static readonly SIYUAN_HOTKEY: string = "siyuan-hotkey";
public static readonly SIYUAN_INIT: string = "siyuan-init";
public static readonly SIYUAN_OPENURL: string = "siyuan-openurl";
+ public static readonly SIYUAN_OPENWINDOW: string = "siyuan-openwindow";
public static readonly SIYUAN_CLOSETAB: string = "siyuan-closetab";
public static readonly SIYUAN_SAVE_CLOSE: string = "siyuan-save-close";
public static readonly SIYUAN_EXPORT_PDF: string = "siyuan-export-pdf";
diff --git a/app/src/window/openNewWindow.ts b/app/src/window/openNewWindow.ts
index bb24bea265..0d2c05fffa 100644
--- a/app/src/window/openNewWindow.ts
+++ b/app/src/window/openNewWindow.ts
@@ -1,30 +1,13 @@
import {layoutToJSON} from "../layout/util";
/// #if !BROWSER
-import {BrowserWindow} from "@electron/remote";
-import * as path from "path";
+import { ipcRenderer } from "electron";
/// #endif
import {Constants} from "../constants";
import {Tab} from "../layout/Tab";
export const openNewWindow = (tab: Tab) => {
- const win = new BrowserWindow({
- show: true,
- trafficLightPosition: {x: 8, y: 13},
- width: 1032,
- height: 650,
- transparent: window.siyuan.config.system.os !== "linux",
- frame: "darwin" === window.siyuan.config.system.os,
- icon: path.join(window.siyuan.config.system.appDir, "stage", "icon-large.png"),
- titleBarStyle: "hidden",
- webPreferences: {
- contextIsolation: false,
- nodeIntegration: true,
- webviewTag: true,
- webSecurity: false,
- },
- });
const json = {};
layoutToJSON(tab, json);
- win.loadURL(`${window.location.protocol}//${window.location.host}/stage/build/app/window.html?v=${Constants.SIYUAN_VERSION}&json=${JSON.stringify(json)}`);
+ ipcRenderer.send(Constants.SIYUAN_OPENWINDOW, `${window.location.protocol}//${window.location.host}/stage/build/app/window.html?v=${Constants.SIYUAN_VERSION}&json=${JSON.stringify(json)}`);
tab.parent.removeTab(tab.id);
};