mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 23:20:13 +01:00
Merge dbcec6da90 into db4fb41024
This commit is contained in:
commit
8054847de8
1 changed files with 32 additions and 5 deletions
|
|
@ -68,12 +68,39 @@ try {
|
||||||
app.exit();
|
app.exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
const windowNavigate = (currentWindow) => {
|
const windowNavigate = (currentWindow, windowType) => {
|
||||||
currentWindow.webContents.on("will-navigate", (event) => {
|
currentWindow.webContents.on("will-navigate", (event) => {
|
||||||
const url = event.url;
|
const url = event.url;
|
||||||
if (url.startsWith(localServer)) {
|
if (url.startsWith(localServer)) {
|
||||||
return;
|
const urlObj = new URL(url);
|
||||||
|
const pathname = urlObj.pathname;
|
||||||
|
let isAllowed = false;
|
||||||
|
// 所有窗口都允许认证页面
|
||||||
|
if (pathname === "/check-auth") {
|
||||||
|
isAllowed = true;
|
||||||
|
} else {
|
||||||
|
// 根据窗口类型判断允许的路径
|
||||||
|
switch (windowType) {
|
||||||
|
case "app":
|
||||||
|
// 主窗口:只允许应用入口路径
|
||||||
|
isAllowed = pathname === "/stage/build/app/";
|
||||||
|
break;
|
||||||
|
case "window":
|
||||||
|
// 新窗口:允许 window.html
|
||||||
|
isAllowed = pathname === "/stage/build/app/window.html";
|
||||||
|
break;
|
||||||
|
case "export":
|
||||||
|
// 导出预览窗口:允许导出临时文件路径
|
||||||
|
isAllowed = pathname.startsWith("/export/temp/");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isAllowed) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
// 阻止导航并在外部浏览器打开
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
shell.openExternal(url);
|
shell.openExternal(url);
|
||||||
});
|
});
|
||||||
|
|
@ -450,7 +477,7 @@ const initMainWindow = () => {
|
||||||
const menu = Menu.buildFromTemplate(template);
|
const menu = Menu.buildFromTemplate(template);
|
||||||
Menu.setApplicationMenu(menu);
|
Menu.setApplicationMenu(menu);
|
||||||
// 当前页面链接使用浏览器打开
|
// 当前页面链接使用浏览器打开
|
||||||
windowNavigate(currentWindow);
|
windowNavigate(currentWindow, "app");
|
||||||
currentWindow.on("close", (event) => {
|
currentWindow.on("close", (event) => {
|
||||||
if (currentWindow && !currentWindow.isDestroyed()) {
|
if (currentWindow && !currentWindow.isDestroyed()) {
|
||||||
currentWindow.webContents.send("siyuan-save-close", false);
|
currentWindow.webContents.send("siyuan-save-close", false);
|
||||||
|
|
@ -1052,7 +1079,7 @@ app.whenReady().then(() => {
|
||||||
printWin.center();
|
printWin.center();
|
||||||
printWin.webContents.userAgent = "SiYuan/" + appVer + " https://b3log.org/siyuan Electron " + printWin.webContents.userAgent;
|
printWin.webContents.userAgent = "SiYuan/" + appVer + " https://b3log.org/siyuan Electron " + printWin.webContents.userAgent;
|
||||||
printWin.loadURL(data);
|
printWin.loadURL(data);
|
||||||
windowNavigate(printWin);
|
windowNavigate(printWin, "export");
|
||||||
});
|
});
|
||||||
ipcMain.on("siyuan-quit", (event, port) => {
|
ipcMain.on("siyuan-quit", (event, port) => {
|
||||||
exitApp(port);
|
exitApp(port);
|
||||||
|
|
@ -1102,7 +1129,7 @@ app.whenReady().then(() => {
|
||||||
win.webContents.userAgent = "SiYuan/" + appVer + " https://b3log.org/siyuan Electron " + win.webContents.userAgent;
|
win.webContents.userAgent = "SiYuan/" + appVer + " https://b3log.org/siyuan Electron " + win.webContents.userAgent;
|
||||||
win.webContents.session.setSpellCheckerLanguages(["en-US"]);
|
win.webContents.session.setSpellCheckerLanguages(["en-US"]);
|
||||||
win.loadURL(data.url);
|
win.loadURL(data.url);
|
||||||
windowNavigate(win);
|
windowNavigate(win, "window");
|
||||||
win.on("close", (event) => {
|
win.on("close", (event) => {
|
||||||
if (win && !win.isDestroyed()) {
|
if (win && !win.isDestroyed()) {
|
||||||
win.webContents.send("siyuan-save-close");
|
win.webContents.send("siyuan-save-close");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue