fix(editor): 新文档回到顶部 + 超链接用系统浏览器打开 + 链接气泡仅选中时弹出
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
// main 进程入口:创建窗口 + 初始化库 + 注册 IPC + 迁移检测
|
||||
import { app, BrowserWindow, ipcMain, protocol, net, dialog } from 'electron';
|
||||
import { app, BrowserWindow, ipcMain, protocol, net, dialog, shell } from 'electron';
|
||||
import nodePath from 'node:path';
|
||||
import { fileURLToPath, pathToFileURL } from 'node:url';
|
||||
import { promises as fs } from 'node:fs';
|
||||
@@ -31,6 +31,19 @@ function createWindow() {
|
||||
});
|
||||
if (!win) win = w;
|
||||
w.on('ready-to-show', () => w.show());
|
||||
// 安全:外部链接一律交给系统默认浏览器,不在应用窗口内导航(避免丢失编辑器状态)
|
||||
w.webContents.setWindowOpenHandler(({ url }) => {
|
||||
if (/^https?:\/\//i.test(url)) void shell.openExternal(url);
|
||||
return { action: 'deny' };
|
||||
});
|
||||
w.webContents.on('will-navigate', (e, url) => {
|
||||
const current = w.webContents.getURL();
|
||||
// 仅拦截跳转到其它 http(s) 站点的导航;应用自身 (vaultasset/file/app) 不拦
|
||||
if (/^https?:\/\//i.test(url) && url !== current) {
|
||||
e.preventDefault();
|
||||
void shell.openExternal(url);
|
||||
}
|
||||
});
|
||||
// 转发渲染进程控制台消息到主进程终端(便于开发调试)
|
||||
w.webContents.on('console-message', (e, level, message, line, sourceId) => {
|
||||
const lv = ['log', 'info', 'warn', 'error'][level] || 'log';
|
||||
|
||||
Reference in New Issue
Block a user