mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 15:10:12 +01:00
This commit is contained in:
parent
1e312b521a
commit
4c049b7600
3 changed files with 39 additions and 42 deletions
|
|
@ -52,8 +52,10 @@ try {
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e)
|
console.error(e)
|
||||||
require('electron').dialog.showErrorBox('创建配置目录失败 Failed to create config directory',
|
require('electron').
|
||||||
'思源需要在用户家目录下创建配置文件夹(~/.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.')
|
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()
|
app.exit()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -76,7 +78,6 @@ const showErrorWindow = (title, content) => {
|
||||||
frame: false,
|
frame: false,
|
||||||
icon: path.join(appDir, 'stage', 'icon-large.png'),
|
icon: path.join(appDir, 'stage', 'icon-large.png'),
|
||||||
webPreferences: {
|
webPreferences: {
|
||||||
nativeWindowOpen: true,
|
|
||||||
nodeIntegration: true,
|
nodeIntegration: true,
|
||||||
webviewTag: true,
|
webviewTag: true,
|
||||||
webSecurity: false,
|
webSecurity: false,
|
||||||
|
|
@ -190,7 +191,6 @@ const boot = () => {
|
||||||
trafficLightPosition: {x: 8, y: 8},
|
trafficLightPosition: {x: 8, y: 8},
|
||||||
webPreferences: {
|
webPreferences: {
|
||||||
nodeIntegration: true,
|
nodeIntegration: true,
|
||||||
nativeWindowOpen: true,
|
|
||||||
webviewTag: true,
|
webviewTag: true,
|
||||||
webSecurity: false,
|
webSecurity: false,
|
||||||
contextIsolation: false,
|
contextIsolation: false,
|
||||||
|
|
@ -372,9 +372,6 @@ const initKernel = (workspace, port, lang) => {
|
||||||
frame: false,
|
frame: false,
|
||||||
icon: path.join(appDir, 'stage', 'icon-large.png'),
|
icon: path.join(appDir, 'stage', 'icon-large.png'),
|
||||||
transparent: 'linux' !== process.platform,
|
transparent: 'linux' !== process.platform,
|
||||||
webPreferences: {
|
|
||||||
nativeWindowOpen: true,
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const kernelName = 'win32' === process.platform
|
const kernelName = 'win32' === process.platform
|
||||||
|
|
@ -390,7 +387,7 @@ const initKernel = (workspace, port, lang) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isDevEnv || workspaces.length > 0) {
|
if (!isDevEnv || workspaces.length > 0) {
|
||||||
if (port && "" !== port) {
|
if (port && '' !== port) {
|
||||||
kernelPort = port
|
kernelPort = port
|
||||||
} else {
|
} else {
|
||||||
const getAvailablePort = () => {
|
const getAvailablePort = () => {
|
||||||
|
|
@ -421,13 +418,13 @@ const initKernel = (workspace, port, lang) => {
|
||||||
if (isDevEnv && workspaces.length === 0) {
|
if (isDevEnv && workspaces.length === 0) {
|
||||||
cmds.push('--mode', 'dev')
|
cmds.push('--mode', 'dev')
|
||||||
}
|
}
|
||||||
if (workspace && "" !== workspace) {
|
if (workspace && '' !== workspace) {
|
||||||
cmds.push('--workspace', workspace)
|
cmds.push('--workspace', workspace)
|
||||||
}
|
}
|
||||||
if (port && "" !== port) {
|
if (port && '' !== port) {
|
||||||
cmds.push('--port', port)
|
cmds.push('--port', port)
|
||||||
}
|
}
|
||||||
if (lang && "" !== lang) {
|
if (lang && '' !== lang) {
|
||||||
cmds.push('--lang', lang)
|
cmds.push('--lang', lang)
|
||||||
}
|
}
|
||||||
let cmd = `ui version [${appVer}], booting kernel [${kernelPath} ${cmds.join(
|
let cmd = `ui version [${appVer}], booting kernel [${kernelPath} ${cmds.join(
|
||||||
|
|
@ -672,7 +669,7 @@ app.whenReady().then(() => {
|
||||||
})
|
})
|
||||||
ipcMain.on('siyuan-closetab', (event, data) => {
|
ipcMain.on('siyuan-closetab', (event, data) => {
|
||||||
BrowserWindow.getAllWindows().forEach(item => {
|
BrowserWindow.getAllWindows().forEach(item => {
|
||||||
item.webContents.send('siyuan-closetab', data)
|
item.webContents.send('siyuan-closetab', data)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
ipcMain.on('siyuan-export-pdf', (event, data) => {
|
ipcMain.on('siyuan-export-pdf', (event, data) => {
|
||||||
|
|
@ -732,6 +729,29 @@ app.whenReady().then(() => {
|
||||||
writeLog('exited ui')
|
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) => {
|
ipcMain.on('siyuan-open-workspace', (event, data) => {
|
||||||
const foundWorkspace = workspaces.find((item, index) => {
|
const foundWorkspace = workspaces.find((item, index) => {
|
||||||
if (item.workspaceDir === data.workspace) {
|
if (item.workspaceDir === data.workspace) {
|
||||||
|
|
@ -740,7 +760,7 @@ app.whenReady().then(() => {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
if (!foundWorkspace) {
|
if (!foundWorkspace) {
|
||||||
initKernel(data.workspace, "", data.lang).then((isSucc) => {
|
initKernel(data.workspace, '', data.lang).then((isSucc) => {
|
||||||
if (isSucc) {
|
if (isSucc) {
|
||||||
boot()
|
boot()
|
||||||
}
|
}
|
||||||
|
|
@ -803,7 +823,6 @@ app.whenReady().then(() => {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
ipcMain.on('siyuan-lock-screen', () => {
|
ipcMain.on('siyuan-lock-screen', () => {
|
||||||
BrowserWindow.getAllWindows().forEach(item => {
|
BrowserWindow.getAllWindows().forEach(item => {
|
||||||
item.webContents.send('siyuan-lock-screen')
|
item.webContents.send('siyuan-lock-screen')
|
||||||
|
|
@ -818,7 +837,6 @@ app.whenReady().then(() => {
|
||||||
icon: path.join(appDir, 'stage', 'icon-large.png'),
|
icon: path.join(appDir, 'stage', 'icon-large.png'),
|
||||||
transparent: 'linux' !== process.platform,
|
transparent: 'linux' !== process.platform,
|
||||||
webPreferences: {
|
webPreferences: {
|
||||||
nativeWindowOpen: true,
|
|
||||||
nodeIntegration: true,
|
nodeIntegration: true,
|
||||||
webviewTag: true,
|
webviewTag: true,
|
||||||
webSecurity: false,
|
webSecurity: false,
|
||||||
|
|
@ -847,7 +865,7 @@ app.whenReady().then(() => {
|
||||||
firstOpenWindow.show()
|
firstOpenWindow.show()
|
||||||
// 初始化启动
|
// 初始化启动
|
||||||
ipcMain.on('siyuan-first-init', (event, data) => {
|
ipcMain.on('siyuan-first-init', (event, data) => {
|
||||||
initKernel(data.workspace, "", data.lang).then((isSucc) => {
|
initKernel(data.workspace, '', data.lang).then((isSucc) => {
|
||||||
if (isSucc) {
|
if (isSucc) {
|
||||||
boot()
|
boot()
|
||||||
}
|
}
|
||||||
|
|
@ -871,7 +889,7 @@ app.whenReady().then(() => {
|
||||||
if (port) {
|
if (port) {
|
||||||
writeLog('got arg [--port=' + port + ']')
|
writeLog('got arg [--port=' + port + ']')
|
||||||
}
|
}
|
||||||
initKernel(workspace, port, "").then((isSucc) => {
|
initKernel(workspace, port, '').then((isSucc) => {
|
||||||
if (isSucc) {
|
if (isSucc) {
|
||||||
boot()
|
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) => {
|
app.on('second-instance', (event, argv) => {
|
||||||
writeLog('second-instance [' + argv + ']')
|
writeLog('second-instance [' + argv + ']')
|
||||||
let workspace = argv.find((arg) => arg.startsWith('--workspace='))
|
let workspace = argv.find((arg) => arg.startsWith('--workspace='))
|
||||||
|
|
@ -919,7 +933,7 @@ app.on('second-instance', (event, argv) => {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (workspace) {
|
if (workspace) {
|
||||||
initKernel(workspace, port, "").then((isSucc) => {
|
initKernel(workspace, port, '').then((isSucc) => {
|
||||||
if (isSucc) {
|
if (isSucc) {
|
||||||
boot()
|
boot()
|
||||||
}
|
}
|
||||||
|
|
@ -969,7 +983,6 @@ app.on('before-quit', (event) => {
|
||||||
})
|
})
|
||||||
|
|
||||||
const {powerMonitor} = require('electron')
|
const {powerMonitor} = require('electron')
|
||||||
const {write} = require('fs')
|
|
||||||
|
|
||||||
powerMonitor.on('suspend', () => {
|
powerMonitor.on('suspend', () => {
|
||||||
writeLog('system suspend')
|
writeLog('system suspend')
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,7 @@ export abstract class Constants {
|
||||||
public static readonly SIYUAN_HOTKEY: string = "siyuan-hotkey";
|
public static readonly SIYUAN_HOTKEY: string = "siyuan-hotkey";
|
||||||
public static readonly SIYUAN_INIT: string = "siyuan-init";
|
public static readonly SIYUAN_INIT: string = "siyuan-init";
|
||||||
public static readonly SIYUAN_OPENURL: string = "siyuan-openurl";
|
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_CLOSETAB: string = "siyuan-closetab";
|
||||||
public static readonly SIYUAN_SAVE_CLOSE: string = "siyuan-save-close";
|
public static readonly SIYUAN_SAVE_CLOSE: string = "siyuan-save-close";
|
||||||
public static readonly SIYUAN_EXPORT_PDF: string = "siyuan-export-pdf";
|
public static readonly SIYUAN_EXPORT_PDF: string = "siyuan-export-pdf";
|
||||||
|
|
|
||||||
|
|
@ -1,30 +1,13 @@
|
||||||
import {layoutToJSON} from "../layout/util";
|
import {layoutToJSON} from "../layout/util";
|
||||||
/// #if !BROWSER
|
/// #if !BROWSER
|
||||||
import {BrowserWindow} from "@electron/remote";
|
import { ipcRenderer } from "electron";
|
||||||
import * as path from "path";
|
|
||||||
/// #endif
|
/// #endif
|
||||||
import {Constants} from "../constants";
|
import {Constants} from "../constants";
|
||||||
import {Tab} from "../layout/Tab";
|
import {Tab} from "../layout/Tab";
|
||||||
|
|
||||||
export const openNewWindow = (tab: 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 = {};
|
const json = {};
|
||||||
layoutToJSON(tab, 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);
|
tab.parent.removeTab(tab.id);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue