feat: 添加公告功能,支持查看公告和在系统浏览器中打开链接

This commit is contained in:
2025-08-31 23:11:24 +08:00
parent fe35e37371
commit c5fd0c1253
5 changed files with 108 additions and 6 deletions

View File

@@ -1,4 +1,4 @@
import { app, BrowserWindow, ipcMain, dialog } from 'electron'
import { app, BrowserWindow, ipcMain, dialog, shell } from 'electron'
import * as path from 'path'
import * as fs from 'fs'
import { spawn } from 'child_process'
@@ -74,7 +74,6 @@ function createWindow() {
})
mainWindow.setMenuBarVisibility(false)
const devServer = process.env.VITE_DEV_SERVER_URL
if (devServer) {
mainWindow.loadURL(devServer)
@@ -121,6 +120,17 @@ ipcMain.handle('select-file', async (event, filters = []) => {
return result.canceled ? null : result.filePaths[0]
})
// 在系统默认浏览器中打开URL
ipcMain.handle('open-url', async (event, url: string) => {
try {
await shell.openExternal(url)
return { success: true }
} catch (error) {
console.error('打开链接失败:', error)
return { success: false, error: error.message }
}
})
// 环境检查
ipcMain.handle('check-environment', async () => {
const appRoot = getAppRoot()

View File

@@ -9,6 +9,7 @@ contextBridge.exposeInMainWorld('electronAPI', {
openDevTools: () => ipcRenderer.invoke('open-dev-tools'),
selectFolder: () => ipcRenderer.invoke('select-folder'),
selectFile: (filters?: any[]) => ipcRenderer.invoke('select-file', filters),
openUrl: (url: string) => ipcRenderer.invoke('open-url', url),
// 初始化相关API
checkEnvironment: () => ipcRenderer.invoke('check-environment'),