feat(electron): add Electron desktop wrapper

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
congsh
2026-04-19 22:54:27 +08:00
parent 10574845f6
commit 4c7152ff50
4 changed files with 95 additions and 0 deletions
+1
View File
@@ -0,0 +1 @@
ELECTRON_MIRROR=https://npmmirror.com/mirrors/electron/
+47
View File
@@ -0,0 +1,47 @@
const { app, BrowserWindow } = require('electron')
const path = require('path')
const ENV_URLS = {
dev: 'http://192.168.1.14:7033',
uat: 'http://nas.wjl-work.top:7034',
}
function getWindowUrl() {
const envArg = process.argv.find(a => a.startsWith('--env='))
if (envArg) {
const env = envArg.split('=')[1]
return ENV_URLS[env] || ENV_URLS.dev
}
return ENV_URLS.dev
}
function createWindow() {
const win = new BrowserWindow({
width: 1280,
height: 800,
minWidth: 960,
minHeight: 600,
title: 'Game Group',
autoHideMenuBar: true,
webPreferences: {
preload: path.join(__dirname, 'preload.js'),
contextIsolation: true,
webSecurity: false,
},
})
const url = getWindowUrl()
win.loadURL(url)
// 页面标题同步
win.on('page-title-updated', (event, title) => {
event.preventDefault()
win.setTitle(`Game Group - ${title}`)
})
}
app.whenReady().then(createWindow)
app.on('window-all-closed', () => {
app.quit()
})
+41
View File
@@ -0,0 +1,41 @@
{
"name": "gamegroup-electron",
"version": "0.3.2",
"description": "Game Group V2 桌面客户端",
"main": "main.js",
"scripts": {
"start": "electron .",
"start:dev": "electron . --env=dev",
"start:uat": "electron . --env=uat",
"build": "electron-builder --win",
"build:portable": "electron-builder --win portable"
},
"dependencies": {
"electron-store": "^8.2"
},
"devDependencies": {
"electron": "^35.0",
"electron-builder": "^26.0"
},
"build": {
"appId": "com.gamegroup.v2",
"productName": "GameGroup",
"directories": {
"output": "dist"
},
"win": {
"target": [
{
"target": "portable",
"arch": ["x64"]
}
],
"icon": "build/icon.ico"
},
"files": [
"main.js",
"preload.js",
"build/**/*"
]
}
}
+6
View File
@@ -0,0 +1,6 @@
// preload.js - 目前为空,预留用于未来需要暴露给渲染进程的 API
const { contextBridge } = require('electron')
contextBridge.exposeInMainWorld('electronAPI', {
platform: process.platform,
})