feat: 新增页面
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
import { app, BrowserWindow, ipcMain, shell } from "electron";
|
||||
import { app, BrowserWindow, ipcMain } from "electron";
|
||||
import path from "node:path";
|
||||
import started from "electron-squirrel-startup";
|
||||
import { TabManager } from '@modules/tab-manager'
|
||||
import { logger } from '@modules/logger'
|
||||
import "@modules/window-size";
|
||||
|
||||
@@ -11,12 +10,10 @@ if (started) {
|
||||
|
||||
class AppMain {
|
||||
private mainWindow: BrowserWindow | null = null
|
||||
private tabs: TabManager | null = null
|
||||
private readonly isDev = !!MAIN_WINDOW_VITE_DEV_SERVER_URL
|
||||
|
||||
init() {
|
||||
this.registerLifecycle()
|
||||
this.registerCommonIPC()
|
||||
this.registerAppIPC()
|
||||
this.registerLogIPC()
|
||||
}
|
||||
@@ -45,7 +42,6 @@ class AppMain {
|
||||
this.loadEntry(win, options?.route)
|
||||
if (this.isDev) win.webContents.openDevTools()
|
||||
this.mainWindow = win
|
||||
this.initTabsIfNeeded(options)
|
||||
return win
|
||||
}
|
||||
|
||||
@@ -65,17 +61,6 @@ class AppMain {
|
||||
});
|
||||
}
|
||||
|
||||
private initTabsIfNeeded(options?: { frameless?: boolean; route?: string }) {
|
||||
if (!this.mainWindow) return
|
||||
const route = options?.route || ''
|
||||
const shouldInit = !!options?.frameless || route.startsWith('/browser')
|
||||
if (!shouldInit) return
|
||||
this.tabs = new TabManager(this.mainWindow)
|
||||
this.registerTabIPC()
|
||||
this.tabs.enable?.()
|
||||
this.tabs.create('about:blank')
|
||||
}
|
||||
|
||||
private registerLifecycle() {
|
||||
app.on("ready", () => {
|
||||
this.createWindow({ frameless: false, route: '/login' })
|
||||
@@ -88,23 +73,6 @@ class AppMain {
|
||||
})
|
||||
}
|
||||
|
||||
private registerCommonIPC() {
|
||||
ipcMain.handle('open-baidu', () => {
|
||||
this.mainWindow?.loadURL("https://www.baidu.com")
|
||||
})
|
||||
ipcMain.handle("external-open", (_event, url: string) => {
|
||||
try {
|
||||
const allowed = /^https:\/\/(www\.)?(baidu\.com|\w+[\.-]?\w+\.[a-z]{2,})(\/.*)?$/i;
|
||||
if (typeof url === "string" && allowed.test(url)) {
|
||||
return shell.openExternal(url);
|
||||
}
|
||||
throw new Error("URL not allowed");
|
||||
} catch (e) {
|
||||
return Promise.reject(e);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private registerAppIPC() {
|
||||
ipcMain.handle('app:set-frameless', async (event, route?: string) => {
|
||||
const old = BrowserWindow.fromWebContents(event.sender)
|
||||
@@ -114,19 +82,6 @@ class AppMain {
|
||||
})
|
||||
}
|
||||
|
||||
private registerTabIPC() {
|
||||
if (!this.tabs) return
|
||||
const tabs = this.tabs
|
||||
ipcMain.handle('tab:create', (_e, url?: string) => tabs.create(url))
|
||||
ipcMain.handle('tab:list', () => tabs.list())
|
||||
ipcMain.handle('tab:navigate', (_e, payload: { tabId: string; url: string }) => tabs.navigate(payload.tabId, payload.url))
|
||||
ipcMain.handle('tab:reload', (_e, tabId: string) => tabs.reload(tabId))
|
||||
ipcMain.handle('tab:back', (_e, tabId: string) => tabs.goBack(tabId))
|
||||
ipcMain.handle('tab:forward', (_e, tabId: string) => tabs.goForward(tabId))
|
||||
ipcMain.handle('tab:switch', (_e, tabId: string) => tabs.switch(tabId))
|
||||
ipcMain.handle('tab:close', (_e, tabId: string) => tabs.close(tabId))
|
||||
}
|
||||
|
||||
private registerLogIPC() {
|
||||
ipcMain.handle('log-to-main', (_e, logLevel: string, message: string) => {
|
||||
switch(logLevel) {
|
||||
|
||||
Reference in New Issue
Block a user