This commit is contained in:
Vanessa 2023-10-09 01:24:30 +08:00
parent f600cc1bde
commit d7666659c3
11 changed files with 286 additions and 209 deletions

View file

@ -182,12 +182,12 @@
})
document.getElementById('close').addEventListener('click', () => {
const {getCurrentWindow} = require('@electron/remote')
getCurrentWindow().destroy()
const {ipcRenderer} = require('electron')
ipcRenderer.send("siyuan-cmd", "destroy");
})
document.getElementById('min').addEventListener('click', () => {
const {getCurrentWindow} = require('@electron/remote')
getCurrentWindow().minimize()
const {ipcRenderer} = require('electron')
ipcRenderer.send("siyuan-cmd", "minimize");
})
</script>
</body>

View file

@ -343,13 +343,12 @@
ipcRenderer.send('siyuan-first-quit')
})
document.getElementById('min').addEventListener('click', () => {
const {getCurrentWindow} = require('@electron/remote')
getCurrentWindow().minimize()
const {ipcRenderer} = require('electron')
ipcRenderer.send("siyuan-cmd", "minimize");
})
document.querySelectorAll('.choosePath').forEach((item) => {
item.addEventListener('click', () => {
const {dialog} = require('@electron/remote')
item.addEventListener('click', async () => {
const path = require('path')
const fs = require('fs')
@ -358,50 +357,48 @@
fs.mkdirSync(defaultWorkspace, {mode: 0o755, recursive: true})
}
dialog.showOpenDialog({
const {ipcRenderer} = require('electron')
const result = await ipcRenderer.invoke(Constants.SIYUAN_GET, {
cmd: "showOpenDialog",
defaultPath: defaultWorkspace,
properties: ['openDirectory', 'createDirectory'],
}).then((result) => {
if (result.canceled) {
return
}
});
const {ipcRenderer} = require('electron')
const initPath = result.filePaths[0]
if (result.canceled) {
return
}
const initPath = result.filePaths[0]
if (isICloudPath(initPath)) {
let msg = '⚠️ This folder is under the iCloud sync path, please change another path'
if (isChinese(currentLang)) {
msg = '⚠️ 该文件夹位于 iCloud 同步路径下,请更换其他路径'
}
alert(msg)
return
}
if (isCloudDrivePath(initPath)) {
let msg = '⚠️ The folder path can not contain onedrive, dropbox, google drive, pcloud and 坚果云, please change another path'
if (isChinese(currentLang)) {
msg = '⚠️ 文件夹路径不能包含 onedrive、dropbox、google drive、pcloud 和 坚果云,请更换其他路径'
}
alert(msg)
return
}
let msg = '⚠️ Do not set the workspace under the path of a third-party sync disk, otherwise the data will be damaged (iCloud/OneDrive/Dropbox/Google Drive/Nutstore/Baidu Netdisk/Tencent Weiyun, etc.), continue?'
if (isICloudPath(initPath)) {
let msg = '⚠️ This folder is under the iCloud sync path, please change another path'
if (isChinese(currentLang)) {
msg = '⚠️ 请勿将工作空间设置在第三方同步盘路径下否则数据会被损坏iCloud/OneDrive/Dropbox/Google Drive/坚果云/百度网盘/腾讯微云等),是否继续?'
}
if (!confirm(msg)) {
return
msg = '⚠️ 该文件夹位于 iCloud 同步路径下,请更换其他路径'
}
alert(msg)
return
}
if (!fs.existsSync(initPath)) {
fs.mkdirSync(initPath, {mode: 0o755, recursive: true})
if (isCloudDrivePath(initPath)) {
let msg = '⚠️ The folder path can not contain onedrive, dropbox, google drive, pcloud and 坚果云, please change another path'
if (isChinese(currentLang)) {
msg = '⚠️ 文件夹路径不能包含 onedrive、dropbox、google drive、pcloud 和 坚果云,请更换其他路径'
}
ipcRenderer.send('siyuan-first-init', {
workspace: initPath,
lang: document.querySelector('.lang').value
})
alert(msg)
return
}
let msg = '⚠️ Do not set the workspace under the path of a third-party sync disk, otherwise the data will be damaged (iCloud/OneDrive/Dropbox/Google Drive/Nutstore/Baidu Netdisk/Tencent Weiyun, etc.), continue?'
if (isChinese(currentLang)) {
msg = '⚠️ 请勿将工作空间设置在第三方同步盘路径下否则数据会被损坏iCloud/OneDrive/Dropbox/Google Drive/坚果云/百度网盘/腾讯微云等),是否继续?'
}
if (!confirm(msg)) {
return
}
if (!fs.existsSync(initPath)) {
fs.mkdirSync(initPath, {mode: 0o755, recursive: true})
}
ipcRenderer.send('siyuan-first-init', {
workspace: initPath,
lang: document.querySelector('.lang').value
})
})
})

View file

@ -31,7 +31,6 @@ let firstOpen = false;
let workspaces = []; // workspaceDir, id, browserWindow, tray
let kernelPort = 6806;
let resetWindowStateOnRestart = false;
require("@electron/remote/main").initialize();
if (!app.requestSingleInstanceLock()) {
app.quit();
@ -160,7 +159,6 @@ const showErrorWindow = (title, content) => {
nodeIntegration: true, webviewTag: true, webSecurity: false, contextIsolation: false,
},
});
require("@electron/remote/main").enable(errWindow.webContents);
errWindow.loadFile(errorHTMLPath, {
query: {
home: app.getPath("home"),
@ -281,7 +279,6 @@ const boot = () => {
icon: path.join(appDir, "stage", "icon-large.png"),
});
windowStateInitialized ? currentWindow.setPosition(x, y) : currentWindow.center();
require("@electron/remote/main").enable(currentWindow.webContents);
currentWindow.webContents.userAgent = "SiYuan/" + appVer + " https://b3log.org/siyuan Electron " + currentWindow.webContents.userAgent;
currentWindow.webContents.session.setSpellCheckerLanguages(["en-US"]);
@ -674,6 +671,9 @@ app.whenReady().then(() => {
if (data.cmd === "isFullScreen") {
return getWindowByContentId(event.sender.id).isFullScreen();
}
if (data.cmd === "isMaximized") {
return getWindowByContentId(event.sender.id).isMaximized();
}
if (data.cmd === "getMicrophone") {
return systemPreferences.getMediaAccessStatus("microphone");
}
@ -700,6 +700,29 @@ app.whenReady().then(() => {
return hasMatch
}
});
ipcMain.once("siyuan-event", (event) => {
const currentWindow = getWindowByContentId(event.sender.id);
currentWindow.on("focus", () => {
event.sender.send("siyuan-event", "focus");
});
currentWindow.on("blur", () => {
event.sender.send("siyuan-event", "blur");
});
if ("darwin" !== process.platform) {
currentWindow.on("maximize", () => {
event.sender.send("siyuan-event", "maximize");
});
currentWindow.on("unmaximize", () => {
event.sender.send("siyuan-event", "unmaximize");
});
}
currentWindow.on("enter-full-screen", () => {
event.sender.send("siyuan-event", "enter-full-screen");
});
currentWindow.on("leave-full-screen", () => {
event.sender.send("siyuan-event", "leave-full-screen");
});
})
ipcMain.on("siyuan-cmd", (event, data) => {
let cmd = data;
let webContentsId = event.sender.id
@ -720,9 +743,28 @@ app.whenReady().then(() => {
case "hide":
currentWindow.hide();
break;
case "minimize":
currentWindow.minimize();
break;
case "maximize":
currentWindow.maximize();
break;
case "restore":
if (currentWindow.isFullScreen()) {
currentWindow.setFullScreen(false);
} else {
currentWindow.unmaximize();
}
break;
case "focus":
currentWindow.focus();
break;
case "setAlwaysOnTopFalse":
currentWindow.setAlwaysOnTop(false);
break;
case "setAlwaysOnTopTrue":
currentWindow.setAlwaysOnTop(true, "pop-up-menu");
break;
case "clearCache":
event.sender.session.clearCache();
break;
@ -735,6 +777,16 @@ app.whenReady().then(() => {
case "destroy":
currentWindow.destroy();
break;
case "closeButtonBehavior":
if (currentWindow.isFullScreen()) {
currentWindow.once("leave-full-screen", () => {
currentWindow.hide();
});
currentWindow.setFullScreen(false);
} else {
currentWindow.hide();
}
break;
case "setProxy":
event.sender.session.closeAllConnections().then(() => {
event.sender.session.setProxy({proxyRules: data.proxyURL}).then(() => {
@ -842,7 +894,6 @@ app.whenReady().then(() => {
if (mainScreen.id !== targetScreen.id) {
win.setBounds(targetScreen.workArea);
}
require("@electron/remote/main").enable(win.webContents);
});
ipcMain.on("siyuan-open-workspace", (event, data) => {
const foundWorkspace = workspaces.find((item) => {
@ -960,7 +1011,6 @@ app.whenReady().then(() => {
nodeIntegration: true, webviewTag: true, webSecurity: false, contextIsolation: false,
},
});
require("@electron/remote/main").enable(firstOpenWindow.webContents);
let initHTMLPath = path.join(appDir, "app", "electron", "init.html");
if (isDevEnv) {
initHTMLPath = path.join(appDir, "electron", "init.html");

View file

@ -72,8 +72,5 @@
"webpack": "^5.76.0",
"webpack-bundle-analyzer": "^4.5.0",
"webpack-cli": "^4.10.0"
},
"dependencies": {
"@electron/remote": "^2.0.11"
}
}

84
app/pnpm-lock.yaml generated
View file

@ -4,11 +4,6 @@ settings:
autoInstallPeers: true
excludeLinksFromLockfile: false
dependencies:
'@electron/remote':
specifier: ^2.0.11
version: 2.0.11(electron@26.3.0)
devDependencies:
'@types/node':
specifier: ^18.13.0
@ -134,6 +129,7 @@ packages:
global-agent: 3.0.0
transitivePeerDependencies:
- supports-color
dev: true
/@electron/notarize@1.2.4:
resolution: {integrity: sha512-W5GQhJEosFNafewnS28d3bpQ37/s91CDWqxVchHfmv2dQSTWpOzNlUVQwYzC1ay5bChRV/A9BTL68yj0Pa+TSg==}
@ -160,14 +156,6 @@ packages:
- supports-color
dev: true
/@electron/remote@2.0.11(electron@26.3.0):
resolution: {integrity: sha512-PYEs7W3GrQNuhgiMHjFEvL5MbAL6C7m1AwSAHGqC+xc33IdP7rcGtJSdTP2eg1ssyB3oI00KwTsiSlsQbAoXpA==}
peerDependencies:
electron: '>= 13.0.0'
dependencies:
electron: 26.3.0
dev: false
/@electron/universal@1.3.4:
resolution: {integrity: sha512-BdhBgm2ZBnYyYRLRgOjM5VHkyFItsbggJ0MHycOjKWdFGYwK97ZFXH54dTvUWEfha81vfvwr5On6XBjt99uDcg==}
engines: {node: '>=8.6'}
@ -497,12 +485,14 @@ packages:
/@sindresorhus/is@4.6.0:
resolution: {integrity: sha512-t09vSN3MdfsyCHoFcTRCH/iUtG7OJ0CsjzB8cjAmKc/va/kIgeDI/TxsigdncE/4be734m0cvIYwNaV4i2XqAw==}
engines: {node: '>=10'}
dev: true
/@szmarczak/http-timer@4.0.6:
resolution: {integrity: sha512-4BAffykYOgO+5nzBWYwE3W90sBgLJoUPRWWcL8wlyiM8IB8ipJz3UMJ9KXQd1RKQXpKp8Tutn80HZtWsu2u76w==}
engines: {node: '>=10'}
dependencies:
defer-to-connect: 2.0.1
dev: true
/@tootallnate/once@2.0.0:
resolution: {integrity: sha512-XCuKFP5PS55gnMVu3dty8KPatLqUoy/ZYzDzAGCQ8JNFCkLXzmI7vNHCR+XpbZaMWQK/vQubr7PkYq8g470J/A==}
@ -516,6 +506,7 @@ packages:
'@types/keyv': 3.1.4
'@types/node': 18.13.0
'@types/responselike': 1.0.0
dev: true
/@types/debug@4.1.7:
resolution: {integrity: sha512-9AonUzyTjXXhEOa0DnqpzZi6VHlqKMswga9EXjpXnnqxwLtdvPPtlO8evrI5D9S6asFRCQ6v+wpiUKbw+vKqyg==}
@ -560,6 +551,7 @@ packages:
/@types/http-cache-semantics@4.0.1:
resolution: {integrity: sha512-SZs7ekbP8CN0txVG2xVRH6EgKmEm31BOxA07vkFaETzZz1xh+cbt8BcI0slpymvwhx5dlFnQG2rTlPVQn+iRPQ==}
dev: true
/@types/json-schema@7.0.11:
resolution: {integrity: sha512-wOuvG1SN4Us4rez+tylwwwCV1psiNVOkJeM3AUWUNWg/jDQY2+HE/444y5gc+jBmRqASOm2Oeh5c1axHobwRKQ==}
@ -569,6 +561,7 @@ packages:
resolution: {integrity: sha512-BQ5aZNSCpj7D6K2ksrRCTmKRLEpnPvWDiLPfoGyhZ++8YtiK9d/3DBKPJgry359X/P1PfruyYwvnvwFjuEiEIg==}
dependencies:
'@types/node': 18.13.0
dev: true
/@types/minimatch@5.1.2:
resolution: {integrity: sha512-K0VQKziLUWkVKiRVrx4a40iPaxTUefQmjtkQofBkYRcoaaL/8rhwDWww9qWbrgicNOgnpIsMxyNIUM4+n6dUIA==}
@ -580,6 +573,7 @@ packages:
/@types/node@18.13.0:
resolution: {integrity: sha512-gC3TazRzGoOnoKAhUx+Q0t8S9Tzs74z7m0ipwGpSqQrleP14hKxP4/JUeEQcD3W1/aIpnWl8pHowI7WokuZpXg==}
dev: true
/@types/plist@3.0.2:
resolution: {integrity: sha512-ULqvZNGMv0zRFvqn8/4LSPtnmN4MfhlPNtJCTpKuIIxGVGZ2rYWzFXrvEBoh9CVyqSE7D6YFRJ1hydLHI6kbWw==}
@ -594,6 +588,7 @@ packages:
resolution: {integrity: sha512-85Y2BjiufFzaMIlvJDvTTB8Fxl2xfLo4HgmHzVBz08w4wDePCTjYw66PdrolO0kzli3yam/YCgRufyo1DdQVTA==}
dependencies:
'@types/node': 18.13.0
dev: true
/@types/verror@1.10.6:
resolution: {integrity: sha512-NNm+gdePAX1VGvPcGZCDKQZKYSiAWigKhKaz5KF94hG6f2s8de9Ow5+7AbXoeKxL8gavZfk4UquSAygOF2duEQ==}
@ -606,6 +601,7 @@ packages:
requiresBuild: true
dependencies:
'@types/node': 18.13.0
dev: true
optional: true
/@typescript-eslint/eslint-plugin@5.30.6(@typescript-eslint/parser@5.30.6)(eslint@8.19.0)(typescript@4.7.4):
@ -1113,6 +1109,7 @@ packages:
/boolean@3.2.0:
resolution: {integrity: sha512-d0II/GO9uf9lfUHH2BQsjxzRJZBdsjgsBiW4BvhWk/3qoKwQFjIDVN19PfX8F2D/r9PCMTtLWjYVCFrpeYUzsw==}
requiresBuild: true
dev: true
optional: true
/brace-expansion@1.1.11:
@ -1148,6 +1145,7 @@ packages:
/buffer-crc32@0.2.13:
resolution: {integrity: sha512-VO9Ht/+p3SN7SKWqcrgEzjGbRSJYTx+Q1pTQC0wrWqHx0vpJraQ6GtHx8tvcg1rlK1byhU5gccxgOgj7B0TDkQ==}
dev: true
/buffer-equal@1.0.0:
resolution: {integrity: sha512-tcBWO2Dl4e7Asr9hTGcpVrCe+F7DubpmqWCTbj4FHLmjqO2hIaC383acQubWtRJhdceqs5uBHs6Es+Sk//RKiQ==}
@ -1203,6 +1201,7 @@ packages:
/cacheable-lookup@5.0.4:
resolution: {integrity: sha512-2/kNscPhpcxrOigMZzbiWF7dz8ilhb/nIHU3EyZiXWXpeq/au8qJ8VhdftMkty3n7Gj6HIGalQG8oiBNB3AJgA==}
engines: {node: '>=10.6.0'}
dev: true
/cacheable-request@7.0.2:
resolution: {integrity: sha512-pouW8/FmiPQbuGpkXQ9BAPv/Mo5xDGANgSNXzTzJ8DrKGuXOssM4wIQRjfanNRh3Yu5cfYPvcorqbhg2KIJtew==}
@ -1215,6 +1214,7 @@ packages:
lowercase-keys: 2.0.0
normalize-url: 6.1.0
responselike: 2.0.1
dev: true
/callsites@3.1.0:
resolution: {integrity: sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ==}
@ -1329,6 +1329,7 @@ packages:
resolution: {integrity: sha512-yjLXh88P599UOyPTFX0POsd7WxnbsVsGohcwzHOLspIhhpalPw1BcqED8NblyZLKcGrL8dTgMlcaZxV2jAD41Q==}
dependencies:
mimic-response: 1.0.1
dev: true
/color-convert@2.0.1:
resolution: {integrity: sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==}
@ -1469,12 +1470,14 @@ packages:
optional: true
dependencies:
ms: 2.1.2
dev: true
/decompress-response@6.0.0:
resolution: {integrity: sha512-aW35yZM6Bb/4oJlZncMH2LCoZtJXTRxES17vE3hoRiowU2kWHaJKFkSBDnDR+cm9J+9QhXmREyIfv0pji9ejCQ==}
engines: {node: '>=10'}
dependencies:
mimic-response: 3.1.0
dev: true
/deep-is@0.1.4:
resolution: {integrity: sha512-oIPzksmTg4/MriiaYGO+okXDT7ztn/w3Eptv/+gSIdMdKsJo0u4CfYNFJPy+4SKMuCqGw2wxnA+URMg3t8a/bQ==}
@ -1483,6 +1486,7 @@ packages:
/defer-to-connect@2.0.1:
resolution: {integrity: sha512-4tvttepXG1VaYGrRibk5EwJd1t4udunSOVMdLSAL6mId1ix438oPwPZMALY41FCijukO1L0twNcGsdzS7dHgDg==}
engines: {node: '>=10'}
dev: true
/define-properties@1.1.4:
resolution: {integrity: sha512-uckOqKcfaVvtBdsVkdPv3XjveQJsNQqmhXgRi8uhvWWuPYZCNlzT8qAyblUgNoXdHdjMTzAqeGjAoli8f+bzPA==}
@ -1491,6 +1495,7 @@ packages:
dependencies:
has-property-descriptors: 1.0.0
object-keys: 1.1.1
dev: true
optional: true
/del@4.1.1:
@ -1514,6 +1519,7 @@ packages:
/detect-node@2.1.0:
resolution: {integrity: sha512-T0NIuQpnTvFDATNuHN5roPwSBG83rFsuO+MXXH9/3N1eFbn4wcPjttvjMLEPWJ0RGUYgQE7cGgS3tNxbqCGM7g==}
requiresBuild: true
dev: true
optional: true
/dir-compare@3.3.0:
@ -1680,6 +1686,7 @@ packages:
extract-zip: 2.0.1
transitivePeerDependencies:
- supports-color
dev: true
/emoji-regex@8.0.0:
resolution: {integrity: sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==}
@ -1701,6 +1708,7 @@ packages:
resolution: {integrity: sha512-+uw1inIHVPQoaVuHzRyXd21icM+cnt4CzD5rW+NC1wjOUSTOs+Te7FOv7AhN7vS9x/oIyhLP5PR1H+phQAHu5Q==}
dependencies:
once: 1.4.0
dev: true
/enhanced-resolve@5.10.0:
resolution: {integrity: sha512-T0yTFjdpldGY8PmuXXR0PyQ1ufZpEGiHVrp7zHKB7jdR4qlmZHhONVM5AQOAWXuF/w3dnHbEQVrNptJgt7F+cQ==}
@ -1717,6 +1725,7 @@ packages:
/env-paths@2.2.1:
resolution: {integrity: sha512-+h1lkLKhZMTYjog1VEpJNG7NZJWcuc2DDk/qsqSTRRCOXiLjeQ1d1/udrUGhqMxUgAlwKNZ0cf2uqan5GLuS2A==}
engines: {node: '>=6'}
dev: true
/envinfo@7.8.1:
resolution: {integrity: sha512-/o+BXHmB7ocbHEAs6F2EnG0ogybVVUdkRunTT2glZU9XAaGmhqskrvKwqXuDfNjEO0LZKWdejEEpnq8aM0tOaw==}
@ -1731,6 +1740,7 @@ packages:
/es6-error@4.1.1:
resolution: {integrity: sha512-Um/+FxMr9CISWh0bi5Zv0iOD+4cFh5qLeks1qhAopKVAJw3drgKbKySikp7wGhDL0HPeaja0P5ULZrxLkniUVg==}
requiresBuild: true
dev: true
optional: true
/esbuild-loader@3.0.1(webpack@5.76.0):
@ -1783,6 +1793,7 @@ packages:
/escape-string-regexp@4.0.0:
resolution: {integrity: sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA==}
engines: {node: '>=10'}
dev: true
/eslint-scope@5.1.1:
resolution: {integrity: sha512-2NxwbF/hZ0KpepYN0cNbo+FN6XoK7GaHlQhgx/hIZl6Va0bF45RQOOwhLIy8lQDbuCiadSLCBnH2CFYquit5bw==}
@ -1919,6 +1930,7 @@ packages:
'@types/yauzl': 2.10.0
transitivePeerDependencies:
- supports-color
dev: true
/extsprintf@1.4.1:
resolution: {integrity: sha512-Wrk35e8ydCKDj/ArClo1VrPVmN8zph5V4AtHwIuHhvMXsKf73UT3BOD+azBIW+3wOJ4FhEH7zyaJCFvChjYvMA==}
@ -1964,6 +1976,7 @@ packages:
resolution: {integrity: sha512-cE1qsB/VwyQozZ+q1dGxR8LBYNZeofhEdUNGSMbQD3Gw2lAzX9Zb3uIU6Ebc/Fmyjo9AWWfnn0AUCHqtevs/8g==}
dependencies:
pend: 1.2.0
dev: true
/file-entry-cache@6.0.1:
resolution: {integrity: sha512-7Gps/XWymbLk2QLYK4NzpMOrYjMhdIxXuIvy2QBsLE6ljuodKvdkWs/cpyJJ3CVIVpH0Oi1Hvg1ovbMzLdFBBg==}
@ -2041,6 +2054,7 @@ packages:
graceful-fs: 4.2.11
jsonfile: 4.0.0
universalify: 0.1.2
dev: true
/fs-extra@9.1.0:
resolution: {integrity: sha512-hcg3ZmepS30/7BSFqRvoo3DOMQu7IjqxO5nCDt+zM9XWjb33Wg7ziNT+Qvqbuc3+gWpzO02JubVyk2G4Zvo1OQ==}
@ -2074,6 +2088,7 @@ packages:
/function-bind@1.1.1:
resolution: {integrity: sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==}
requiresBuild: true
dev: true
/functional-red-black-tree@1.0.1:
resolution: {integrity: sha512-dsKNQNdj6xA3T+QlADDA7mOSlX0qiMINjn0cgr+eGHGsbSHzTabcIogz2+p/iqP1Xs6EP/sS2SbqH+brGTbq0g==}
@ -2091,6 +2106,7 @@ packages:
function-bind: 1.1.1
has: 1.0.3
has-symbols: 1.0.3
dev: true
optional: true
/get-stream@5.2.0:
@ -2098,6 +2114,7 @@ packages:
engines: {node: '>=8'}
dependencies:
pump: 3.0.0
dev: true
/get-tsconfig@4.4.0:
resolution: {integrity: sha512-0Gdjo/9+FzsYhXCEFueo2aY1z1tpXrxWZzP7k8ul9qt1U5o8rYJwTJYmaeHdrVosYIVYkOy2iwCJ9FdpocJhPQ==}
@ -2143,6 +2160,7 @@ packages:
roarr: 2.15.4
semver: 7.5.4
serialize-error: 7.0.1
dev: true
optional: true
/globals@13.16.0:
@ -2158,6 +2176,7 @@ packages:
requiresBuild: true
dependencies:
define-properties: 1.1.4
dev: true
optional: true
/globby@11.1.0:
@ -2198,9 +2217,11 @@ packages:
lowercase-keys: 2.0.0
p-cancelable: 2.1.1
responselike: 2.0.1
dev: true
/graceful-fs@4.2.11:
resolution: {integrity: sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==}
dev: true
/gzip-size@6.0.0:
resolution: {integrity: sha512-ax7ZYomf6jqPTQ4+XCpUGyXKHk5WweS+e05MBO4/y3WJ5RkmPXNKvX+bx1behVILVwr6JSQvZAku021CHPXG3Q==}
@ -2219,12 +2240,14 @@ packages:
requiresBuild: true
dependencies:
get-intrinsic: 1.1.2
dev: true
optional: true
/has-symbols@1.0.3:
resolution: {integrity: sha512-l3LCuF6MgDNwTDKkdYGEihYjt5pRPbEg46rtlmnSPlUbgmB8LOIrKJbYYFBSbnPaJexMKtiPO8hmeRjRz2Td+A==}
engines: {node: '>= 0.4'}
requiresBuild: true
dev: true
optional: true
/has@1.0.3:
@ -2232,6 +2255,7 @@ packages:
engines: {node: '>= 0.4.0'}
dependencies:
function-bind: 1.1.1
dev: true
/he@1.2.0:
resolution: {integrity: sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw==}
@ -2309,6 +2333,7 @@ packages:
/http-cache-semantics@4.1.1:
resolution: {integrity: sha512-er295DKPVsV82j5kw1Gjt+ADA/XYHsajl82cGNQG2eyoPkvgUhX+nDIyelzhIWbbsXP39EHcI6l5tYs2FYqYXQ==}
dev: true
/http-proxy-agent@5.0.0:
resolution: {integrity: sha512-n2hY8YdoRE1i7r6M0w9DIw5GgZN0G25P8zLCRQ8rjXtTU3vsNFBI/vWK/UIeE6g5MUUz6avwAPXmL6Fy9D/90w==}
@ -2327,6 +2352,7 @@ packages:
dependencies:
quick-lru: 5.1.1
resolve-alpn: 1.2.1
dev: true
/https-proxy-agent@5.0.1:
resolution: {integrity: sha512-dFcAjpTQFgoLMzC2VwU+C/CbS7uRL0lWmxDITmqm7C+7F0Odmj6s9l6alZc6AELXhrnggM2CeWSXHGOdX2YtwA==}
@ -2541,6 +2567,7 @@ packages:
/json-buffer@3.0.1:
resolution: {integrity: sha512-4bV5BfR2mqfQTJm+V5tPPdf+ZpuhiIvTuAB5g8kcrXOZpTT/QwwVRWBywX1ozr6lEuPdbHxwaJlm9G6mI2sfSQ==}
dev: true
/json-parse-even-better-errors@2.3.1:
resolution: {integrity: sha512-xyFwyhro/JEof6Ghe2iz2NcXoj2sloNsWr/XsERDK/oiPCfaNhl5ONfp+jQdAZRQQ0IJWNzH9zIZF7li91kh2w==}
@ -2561,6 +2588,7 @@ packages:
/json-stringify-safe@5.0.1:
resolution: {integrity: sha512-ZClg6AaYvamvYEE82d3Iyd3vSSIjQ+odgjaTzRuO3s7toCdFKczob2i0zCh7JE8kWn17yvAWhUVxvqGwUalsRA==}
requiresBuild: true
dev: true
optional: true
/json5@1.0.2:
@ -2580,6 +2608,7 @@ packages:
resolution: {integrity: sha512-m6F1R3z8jjlf2imQHS2Qez5sjKWQzbuuhuJ/FKYFRZvPE3PuHcSMVZzfsLhGVOkfd20obL5SWEBew5ShlquNxg==}
optionalDependencies:
graceful-fs: 4.2.11
dev: true
/jsonfile@6.1.0:
resolution: {integrity: sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==}
@ -2593,6 +2622,7 @@ packages:
resolution: {integrity: sha512-5MHbFaKn8cNSmVW7BYnijeAVlE4cYA/SVkifVgrh7yotnfhKmjuXpDKjrABLnT0SfHWV21P8ow07OGfRrNDg8g==}
dependencies:
json-buffer: 3.0.1
dev: true
/kind-of@6.0.3:
resolution: {integrity: sha512-dcS1ul+9tmeD95T+x28/ehLgd9mENa3LsvDTtzm3vyBEO7RPptvAD+t44WVXaUjTBRcrpFeFlC8WCruUR456hw==}
@ -2663,12 +2693,14 @@ packages:
/lowercase-keys@2.0.0:
resolution: {integrity: sha512-tqNXrS78oMOE73NMxK4EMLQsQowWf8jKooH9g7xPavRT706R6bkQJ6DY2Te7QukaZsulxa30wQ7bk0pm4XiHmA==}
engines: {node: '>=8'}
dev: true
/lru-cache@6.0.0:
resolution: {integrity: sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==}
engines: {node: '>=10'}
dependencies:
yallist: 4.0.0
dev: true
/matcher@3.0.0:
resolution: {integrity: sha512-OkeDaAZ/bQCxeFAozM55PKcKU0yJMPGifLwV4Qgjitu+5MoAfSQN4lsLJeXZ1b8w0x+/Emda6MZgXS1jvsapng==}
@ -2676,6 +2708,7 @@ packages:
requiresBuild: true
dependencies:
escape-string-regexp: 4.0.0
dev: true
optional: true
/merge-stream@2.0.0:
@ -2716,10 +2749,12 @@ packages:
/mimic-response@1.0.1:
resolution: {integrity: sha512-j5EctnkH7amfV/q5Hgmoal1g2QHFJRraOtmx0JpIqkxhBhI/lJSl1nMpQ45hVarwNETOoWEimndZ4QK0RHxuxQ==}
engines: {node: '>=4'}
dev: true
/mimic-response@3.1.0:
resolution: {integrity: sha512-z0yWI+4FDrrweS8Zmt4Ej5HdJmky15+L2e6Wgn3+iK5fWzb6T3fhNFq2+MeTRb064c6Wr4N/wv0DzQTjNzHNGQ==}
engines: {node: '>=10'}
dev: true
/mini-css-extract-plugin@2.7.6(webpack@5.76.0):
resolution: {integrity: sha512-Qk7HcgaPkGG6eD77mLvZS1nmxlao3j+9PkrT9Uc7HAE1id3F41+DdBRYRYkbyfNRGzm8/YWtzhw7nVPmwhqTQw==}
@ -2781,6 +2816,7 @@ packages:
/ms@2.1.2:
resolution: {integrity: sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==}
dev: true
/nanoid@3.3.6:
resolution: {integrity: sha512-BGcqMMJuToF7i1rt+2PWSNVnWIkGCU78jBG3RxO/bZlnZPK2Cmi2QaffxGO/2RvWi9sL+FAiRiXMgsyxQ1DIDA==}
@ -2821,6 +2857,7 @@ packages:
/normalize-url@6.1.0:
resolution: {integrity: sha512-DlL+XwOy3NxAQ8xuC0okPgK46iuVNAK01YN7RueYBqqFeGsBjV9XmCAzAdgt+667bCl5kPh9EqKKDwnaPG1I7A==}
engines: {node: '>=10'}
dev: true
/nth-check@2.1.1:
resolution: {integrity: sha512-lqjrjmaOoAnWfMmBPL+XNnynZh2+swxiX3WUE0s4yEHI6m+AwrK2UZOimIRl3X/4QctVqS8AiZjFqyOGrMXb/w==}
@ -2837,12 +2874,14 @@ packages:
resolution: {integrity: sha512-NuAESUOUMrlIXOfHKzD6bpPu3tYt3xvjNdRIQ+FeT0lNb4K8WR70CaDxhuNguS2XG+GjkyMwOzsN5ZktImfhLA==}
engines: {node: '>= 0.4'}
requiresBuild: true
dev: true
optional: true
/once@1.4.0:
resolution: {integrity: sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==}
dependencies:
wrappy: 1.0.2
dev: true
/opener@1.5.2:
resolution: {integrity: sha512-ur5UIdyw5Y7yEj9wLzhqXiy6GZ3Mwx0yGI+5sMn2r0N0v3cKJvUmFH5yPP+WXh9e0xfyzyJX95D8l088DNFj7A==}
@ -2864,6 +2903,7 @@ packages:
/p-cancelable@2.1.1:
resolution: {integrity: sha512-BZOr3nRQHOntUjTrH8+Lh54smKHoHyur8We1V8DSMVrl5A2malOOwuJRnKRDjSnkoeBh4at6BwEnb5I7Jl31wg==}
engines: {node: '>=8'}
dev: true
/p-limit@2.3.0:
resolution: {integrity: sha512-//88mFWSJx8lxCzwdAABTJL2MyWB12+eIY7MDL2SqLmAkeKU9qxRvWuSyTjm3FUmpBEMuFfckAIqEaVGUDxb6w==}
@ -2948,6 +2988,7 @@ packages:
/pend@1.2.0:
resolution: {integrity: sha512-F3asv42UuXchdzt+xXqfW1OGlVBe+mxa2mqI0pg5yAHZPvFmY3Y6drSf/GQ1A86WgWEN9Kzh/WrgKa6iGcHXLg==}
dev: true
/picocolors@1.0.0:
resolution: {integrity: sha512-1fygroTLlHu66zi26VoTDv8yRgm0Fccecssto+MhsZ0D/DGW2sm8E8AjW7NU5VVTRt5GxbeZ5qBuJr+HyLYkjQ==}
@ -3072,12 +3113,14 @@ packages:
/progress@2.0.3:
resolution: {integrity: sha512-7PiHtLll5LdnKIMw100I+8xJXR5gW2QwWYkT6iJva0bXitZKa/XMrSbdmg3r2Xnaidz9Qumd0VPaMrZlF9V9sA==}
engines: {node: '>=0.4.0'}
dev: true
/pump@3.0.0:
resolution: {integrity: sha512-LwZy+p3SFs1Pytd/jYct4wpv49HiYCqd9Rlc5ZVdk0V+8Yzv6jR5Blk3TRmPL1ft69TxP0IMZGJ+WPFU2BFhww==}
dependencies:
end-of-stream: 1.4.4
once: 1.4.0
dev: true
/punycode@2.1.1:
resolution: {integrity: sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==}
@ -3091,6 +3134,7 @@ packages:
/quick-lru@5.1.1:
resolution: {integrity: sha512-WuyALRjWPDGtt/wzJiadO5AXY+8hZ80hVpe6MyivgraREW751X3SbhRvG3eLKOYN+8VEvqLcf3wdnt44Z4S4SA==}
engines: {node: '>=10'}
dev: true
/randombytes@2.1.0:
resolution: {integrity: sha512-vYl3iOX+4CKUWuxGi9Ukhie6fsqXqS9FE2Zaic4tNFD2N2QQaXOMFbuKK4QmDHC0JO6B1Zp41J0LpT0oR68amQ==}
@ -3156,6 +3200,7 @@ packages:
/resolve-alpn@1.2.1:
resolution: {integrity: sha512-0a1F4l73/ZFZOakJnQ3FvkJ2+gSTQWz/r2KE5OdDY0TxPm5h4GkqkWWfM47T7HsbnOtcJVEF4epCVy6u7Q3K+g==}
dev: true
/resolve-cwd@3.0.0:
resolution: {integrity: sha512-OrZaX2Mb+rJCpH/6CpSqt9xFVpN++x01XnN2ie9g6P5/3xelLAkXWVADpdz1IHD/KFfEXyE6V0U01OQ3UO2rEg==}
@ -3187,6 +3232,7 @@ packages:
resolution: {integrity: sha512-4gl03wn3hj1HP3yzgdI7d3lCkF95F21Pz4BPGvKHinyQzALR5CapwC8yIi0Rh58DEMQ/SguC03wFj2k0M/mHhw==}
dependencies:
lowercase-keys: 2.0.0
dev: true
/reusify@1.0.4:
resolution: {integrity: sha512-U9nH88a3fc/ekCF1l0/UP1IosiuIjyTh7hBvXVMHYgVcfGvt897Xguj2UOLDeI5BG2m7/uwyaLVT6fbtCwTyzw==}
@ -3218,6 +3264,7 @@ packages:
json-stringify-safe: 5.0.1
semver-compare: 1.0.0
sprintf-js: 1.1.2
dev: true
optional: true
/run-parallel@1.2.0:
@ -3301,11 +3348,13 @@ packages:
/semver-compare@1.0.0:
resolution: {integrity: sha512-YM3/ITh2MJ5MtzaM429anh+x2jiLVjqILF4m4oyQB18W7Ggea7BfqdH/wGMK7dDiMghv/6WG7znWMwUDzJiXow==}
requiresBuild: true
dev: true
optional: true
/semver@6.3.1:
resolution: {integrity: sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==}
hasBin: true
dev: true
/semver@7.3.8:
resolution: {integrity: sha512-NB1ctGL5rlHrPJtFDVIVzTyQylMLu9N9VICA6HSFJo8MCGVTMW6gfpicwKmmK/dAjTOrqu5l63JJOpDSrAis3A==}
@ -3321,6 +3370,7 @@ packages:
hasBin: true
dependencies:
lru-cache: 6.0.0
dev: true
/serialize-error@7.0.1:
resolution: {integrity: sha512-8I8TjW5KMOKsZQTvoxjuSIa7foAwPWGOts+6o7sgjz41/qMD9VQHEDxi6PBvK2l0MXUmqZyNpUK+T2tQaaElvw==}
@ -3328,6 +3378,7 @@ packages:
requiresBuild: true
dependencies:
type-fest: 0.13.1
dev: true
optional: true
/serialize-javascript@6.0.0:
@ -3418,6 +3469,7 @@ packages:
/sprintf-js@1.1.2:
resolution: {integrity: sha512-VE0SOVEHCk7Qc8ulkWw3ntAzXuqf7S2lvwQaDLRnUeIEaKNQJzV6BwmLKhOqT61aGhfUMrXeaBk+oDGCzvhcug==}
requiresBuild: true
dev: true
optional: true
/stat-mode@1.0.0:
@ -3453,6 +3505,7 @@ packages:
debug: 4.3.4
transitivePeerDependencies:
- supports-color
dev: true
/supports-color@7.2.0:
resolution: {integrity: sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==}
@ -3607,6 +3660,7 @@ packages:
resolution: {integrity: sha512-34R7HTnG0XIJcBSn5XhDd7nNFPRcXYRZrBB2O2jdKqYODldSzBAqzsWoZYYvduky73toYS/ESqxPvkDf/F0XMg==}
engines: {node: '>=10'}
requiresBuild: true
dev: true
optional: true
/type-fest@0.20.2:
@ -3623,6 +3677,7 @@ packages:
/universalify@0.1.2:
resolution: {integrity: sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg==}
engines: {node: '>= 4.0.0'}
dev: true
/universalify@2.0.0:
resolution: {integrity: sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ==}
@ -3825,6 +3880,7 @@ packages:
/wrappy@1.0.2:
resolution: {integrity: sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==}
dev: true
/ws@7.5.8:
resolution: {integrity: sha512-ri1Id1WinAX5Jqn9HejiGb8crfRio0Qgu8+MtL36rlTA6RLsMdWt1Az/19A2Qij6uSHUMphEFaTKa4WG+UNHNw==}
@ -3852,6 +3908,7 @@ packages:
/yallist@4.0.0:
resolution: {integrity: sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==}
dev: true
/yargs-parser@21.1.1:
resolution: {integrity: sha512-tVpsJW7DdjecAiFpbIB1e3qxIQsE6NoPc5/eTdrbbIC4h0LVsWhnoa3g+m2HclBIujHzsxZ4VJVA+GUuc2/LBw==}
@ -3876,3 +3933,4 @@ packages:
dependencies:
buffer-crc32: 0.2.13
fd-slicer: 1.1.0
dev: true

View file

@ -1,7 +1,6 @@
import {exportLayout, JSONToLayout, resetLayout, resizeTopbar, resizeTabs} from "../layout/util";
import {setStorageVal} from "../protyle/util/compatibility";
/// #if !BROWSER
import {getCurrentWindow} from "@electron/remote";
import {ipcRenderer, webFrame} from "electron";
import * as fs from "fs";
import * as path from "path";
@ -153,34 +152,29 @@ export const onGetConfig = (isStart: boolean, app: App) => {
addGA();
};
export const initWindow = (app: App) => {
const winOnMaxRestore = async () => {
/// #if !BROWSER
const winOnFocus = () => {
if (getSelection().rangeCount > 0) {
const range = getSelection().getRangeAt(0);
const startNode = range.startContainer.childNodes[range.startOffset] as HTMLElement;
if (startNode && startNode.nodeType !== 3 && (startNode.tagName === "TEXTAREA" || startNode.tagName === "INPUT")) {
startNode.focus();
} else {
focusByRange(getSelection().getRangeAt(0));
}
}
exportLayout({
reload: false,
onlyData: false,
errorExit: false
});
window.siyuan.altIsPressed = false;
window.siyuan.ctrlIsPressed = false;
window.siyuan.shiftIsPressed = false;
document.body.classList.remove("body--blur");
};
const maxBtnElement = document.getElementById("maxWindow");
const restoreBtnElement = document.getElementById("restoreWindow");
const isFullScreen = await ipcRenderer.invoke(Constants.SIYUAN_GET, {
cmd: "isFullScreen",
});
const isMaximized = await ipcRenderer.invoke(Constants.SIYUAN_GET, {
cmd: "isMaximized",
});
if (isMaximized || isFullScreen) {
restoreBtnElement.style.display = "flex";
maxBtnElement.style.display = "none";
} else {
restoreBtnElement.style.display = "none";
maxBtnElement.style.display = "flex";
}
/// #endif
};
const winOnBlur = () => {
document.body.classList.add("body--blur");
};
const winOnClose = (currentWindow: Electron.BrowserWindow, close = false) => {
export const initWindow = async (app: App) => {
/// #if !BROWSER
const winOnClose = (close = false) => {
exportLayout({
reload: false,
cb() {
@ -191,12 +185,7 @@ export const initWindow = (app: App) => {
languages: window.siyuan.languages["_trayMenu"],
});
} else {
if (currentWindow.isFullScreen()) {
currentWindow.once("leave-full-screen", () => currentWindow.hide());
currentWindow.setFullScreen(false);
} else {
currentWindow.hide();
}
ipcRenderer.send(Constants.SIYUAN_CMD, "closeButtonBehavior");
}
} else {
exitSiYuan();
@ -207,38 +196,55 @@ export const initWindow = (app: App) => {
});
};
const winOnMaxRestore = () => {
const currentWindow = getCurrentWindow();
const maxBtnElement = document.getElementById("maxWindow");
const restoreBtnElement = document.getElementById("restoreWindow");
if (currentWindow.isMaximized() || currentWindow.isFullScreen()) {
restoreBtnElement.style.display = "flex";
maxBtnElement.style.display = "none";
} else {
restoreBtnElement.style.display = "none";
maxBtnElement.style.display = "flex";
ipcRenderer.send(Constants.SIYUAN_EVENT, "onEvent")
ipcRenderer.on(Constants.SIYUAN_EVENT, (event, cmd) => {
if (cmd === "focus") {
if (getSelection().rangeCount > 0) {
const range = getSelection().getRangeAt(0);
const startNode = range.startContainer.childNodes[range.startOffset] as HTMLElement;
if (startNode && startNode.nodeType !== 3 && (startNode.tagName === "TEXTAREA" || startNode.tagName === "INPUT")) {
startNode.focus();
} else {
focusByRange(getSelection().getRangeAt(0));
}
}
exportLayout({
reload: false,
onlyData: false,
errorExit: false
});
window.siyuan.altIsPressed = false;
window.siyuan.ctrlIsPressed = false;
window.siyuan.shiftIsPressed = false;
document.body.classList.remove("body--blur");
} else if (cmd === "blur") {
document.body.classList.add("body--blur");
} else if (cmd === "enter-full-screen") {
if ("darwin" === window.siyuan.config.system.os) {
if (isWindow()) {
setTabPosition();
} else {
document.getElementById("toolbar").style.paddingLeft = "0";
}
} else {
winOnMaxRestore()
}
} else if (cmd === "leave-full-screen") {
if ("darwin" === window.siyuan.config.system.os) {
if (isWindow()) {
setTabPosition();
} else {
document.getElementById("toolbar").setAttribute("style", "");
}
} else {
winOnMaxRestore();
}
} else if (cmd === "maximize") {
winOnMaxRestore();
} else if (cmd === "unmaximize") {
winOnMaxRestore();
}
};
const winOnEnterFullscreen = () => {
if (isWindow()) {
setTabPosition();
} else {
document.getElementById("toolbar").style.paddingLeft = "0";
}
};
const winOnLeaveFullscreen = () => {
if (isWindow()) {
setTabPosition();
} else {
document.getElementById("toolbar").setAttribute("style", "");
}
};
const currentWindow = getCurrentWindow();
currentWindow.on("focus", winOnFocus);
currentWindow.on("blur", winOnBlur);
});
if (!isWindow()) {
ipcRenderer.on(Constants.SIYUAN_OPEN_URL, (event, url) => {
if (url.startsWith("siyuan://plugins/")) {
@ -304,7 +310,7 @@ export const initWindow = (app: App) => {
if (isWindow()) {
closeWindow(app);
} else {
winOnClose(currentWindow, close);
winOnClose(close);
}
});
ipcRenderer.on(Constants.SIYUAN_SEND_WINDOWS, (e, ipcData: IWebSocketData) => {
@ -403,20 +409,6 @@ ${response.data.replace("%pages", "<span class=totalPages></span>").replace("%pa
ipcRenderer.send(Constants.SIYUAN_CMD, {cmd: "hide", webContentsId: ipcData.webContentsId});
});
window.addEventListener("beforeunload", () => {
currentWindow.off("focus", winOnFocus);
currentWindow.off("blur", winOnBlur);
if ("darwin" === window.siyuan.config.system.os) {
currentWindow.off("enter-full-screen", winOnEnterFullscreen);
currentWindow.off("leave-full-screen", winOnLeaveFullscreen);
} else {
currentWindow.off("enter-full-screen", winOnMaxRestore);
currentWindow.off("leave-full-screen", winOnMaxRestore);
currentWindow.off("maximize", winOnMaxRestore);
currentWindow.off("unmaximize", winOnMaxRestore);
}
}, false);
if (isWindow()) {
document.body.insertAdjacentHTML("beforeend", `<div class="toolbar__window">
<div class="toolbar__item ariaLabel" aria-label="${window.siyuan.languages.pin}" id="pinWindow">
@ -429,34 +421,18 @@ ${response.data.replace("%pages", "<span class=totalPages></span>").replace("%pa
pinElement.classList.toggle("toolbar__item--active");
if (pinElement.classList.contains("toolbar__item--active")) {
pinElement.setAttribute("aria-label", window.siyuan.languages.unpin);
currentWindow.setAlwaysOnTop(true, "pop-up-menu");
ipcRenderer.send(Constants.SIYUAN_CMD, "setAlwaysOnTopTrue");
} else {
pinElement.setAttribute("aria-label", window.siyuan.languages.pin);
currentWindow.setAlwaysOnTop(false);
ipcRenderer.send(Constants.SIYUAN_CMD, "setAlwaysOnTopFalse");
}
});
}
if ("darwin" === window.siyuan.config.system.os) {
document.getElementById("drag")?.addEventListener("dblclick", () => {
if (currentWindow.isMaximized()) {
currentWindow.unmaximize();
} else {
currentWindow.maximize();
}
});
const toolbarElement = document.getElementById("toolbar");
currentWindow.on("enter-full-screen", winOnEnterFullscreen);
currentWindow.on("leave-full-screen", winOnLeaveFullscreen);
if (currentWindow.isFullScreen() && !isWindow()) {
toolbarElement.style.paddingLeft = "0";
}
return;
}
if ("darwin" !== window.siyuan.config.system.os) {
document.body.classList.add("body--win32");
document.body.classList.add("body--win32");
// 添加窗口控件
const controlsHTML = `<div class="toolbar__item ariaLabel toolbar__item--win" aria-label="${window.siyuan.languages.min}" id="minWindow">
// 添加窗口控件
const controlsHTML = `<div class="toolbar__item ariaLabel toolbar__item--win" aria-label="${window.siyuan.languages.min}" id="minWindow">
<svg>
<use xlink:href="#iconMin"></use>
</svg>
@ -476,45 +452,46 @@ ${response.data.replace("%pages", "<span class=totalPages></span>").replace("%pa
<use xlink:href="#iconClose"></use>
</svg>
</div>`;
if (isWindow()) {
document.querySelector(".toolbar__window").insertAdjacentHTML("beforeend", controlsHTML);
} else {
document.getElementById("windowControls").innerHTML = controlsHTML;
}
const maxBtnElement = document.getElementById("maxWindow");
const restoreBtnElement = document.getElementById("restoreWindow");
restoreBtnElement.addEventListener("click", () => {
if (currentWindow.isFullScreen()) {
currentWindow.setFullScreen(false);
} else {
currentWindow.unmaximize();
}
});
maxBtnElement.addEventListener("click", () => {
currentWindow.maximize();
});
winOnMaxRestore();
currentWindow.on("maximize", winOnMaxRestore);
currentWindow.on("unmaximize", winOnMaxRestore);
currentWindow.on("enter-full-screen", winOnMaxRestore);
currentWindow.on("leave-full-screen", winOnMaxRestore);
const minBtnElement = document.getElementById("minWindow");
const closeBtnElement = document.getElementById("closeWindow");
minBtnElement.addEventListener("click", () => {
if (minBtnElement.classList.contains("window-controls__item--disabled")) {
return;
}
currentWindow.minimize();
});
closeBtnElement.addEventListener("click", () => {
if (isWindow()) {
closeWindow(app);
document.querySelector(".toolbar__window").insertAdjacentHTML("beforeend", controlsHTML);
} else {
winOnClose(currentWindow);
document.getElementById("windowControls").innerHTML = controlsHTML;
}
});
const maxBtnElement = document.getElementById("maxWindow");
const restoreBtnElement = document.getElementById("restoreWindow");
restoreBtnElement.addEventListener("click", () => {
ipcRenderer.send(Constants.SIYUAN_CMD, "restore");
});
maxBtnElement.addEventListener("click", () => {
ipcRenderer.send(Constants.SIYUAN_CMD, "maximize");
});
winOnMaxRestore();
const minBtnElement = document.getElementById("minWindow");
const closeBtnElement = document.getElementById("closeWindow");
minBtnElement.addEventListener("click", () => {
if (minBtnElement.classList.contains("window-controls__item--disabled")) {
return;
}
ipcRenderer.send(Constants.SIYUAN_CMD, "minimize");
});
closeBtnElement.addEventListener("click", () => {
if (isWindow()) {
closeWindow(app);
} else {
winOnClose();
}
});
} else {
const toolbarElement = document.getElementById("toolbar");
const isFullScreen = await ipcRenderer.invoke(Constants.SIYUAN_GET, {
cmd: "isFullScreen",
});
if (isFullScreen && !isWindow()) {
toolbarElement.style.paddingLeft = "0";
}
}
/// #else
if (!isWindow()) {
document.querySelector(".toolbar").classList.add("toolbar--browser");

View file

@ -187,7 +187,7 @@ export const exportConfig = {
});
/// #else
const filePaths = await ipcRenderer.invoke(Constants.SIYUAN_GET,{
cmd: "showOpenDialogSync",
cmd: "showOpenDialog",
title: window.siyuan.languages.export + " " + "Data",
properties: ["createDirectory", "openDirectory"],
});

View file

@ -26,6 +26,7 @@ export abstract class Constants {
// 渲染进程调主进程
public static readonly SIYUAN_CMD: string = "siyuan-cmd";
public static readonly SIYUAN_GET: string = "siyuan-get";
public static readonly SIYUAN_EVENT: string = "siyuan-event";
public static readonly SIYUAN_CONFIG_TRAY: string = "siyuan-config-tray";
public static readonly SIYUAN_QUIT: string = "siyuan-quit";

View file

@ -1,6 +1,5 @@
import {MenuItem} from "./Menu";
/// #if !BROWSER
import {getCurrentWindow} from "@electron/remote";
import {ipcRenderer} from "electron";
/// #endif
import {openHistory} from "../history/history";
@ -407,7 +406,7 @@ export const workspaceMenu = (app: App, rect: DOMRect) => {
label: window.siyuan.languages.debug,
icon: "iconBug",
click: () => {
getCurrentWindow().webContents.openDevTools({mode: "bottom"});
ipcRenderer.send(Constants.SIYUAN_CMD, "openDevTools");
}
}).element);
/// #endif

View file

@ -46,8 +46,7 @@ import {
import {transaction, updateTransaction} from "./transaction";
import {hideElements} from "../ui/hideElements";
/// #if !BROWSER
import {shell} from "electron";
import {getCurrentWindow} from "@electron/remote";
import {ipcRenderer, shell} from "electron";
/// #endif
import {getEnableHTML, removeEmbed} from "./removeEmbed";
import {keydown} from "./keydown";
@ -1502,7 +1501,7 @@ export class WYSIWYG {
}
if (event.inputType === "historyUndo") {
/// #if !BROWSER
getCurrentWindow().webContents.redo();
ipcRenderer.send(Constants.SIYUAN_CMD, "redo");
/// #endif
window.siyuan.menus.menu.remove();
return;

View file

@ -437,7 +437,6 @@
const exitApp = () => {
try {
const {ipcRenderer} = require('electron')
const {getCurrentWindow} = require('@electron/remote')
ipcRenderer.send('siyuan-quit', window.location.port)
} catch (e) {
if ((window.webkit && window.webkit.messageHandlers) || window.JSAndroid) {