feat(electron): add Electron desktop wrapper
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1 @@
|
||||
ELECTRON_MIRROR=https://npmmirror.com/mirrors/electron/
|
||||
@@ -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()
|
||||
})
|
||||
@@ -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/**/*"
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
// preload.js - 目前为空,预留用于未来需要暴露给渲染进程的 API
|
||||
const { contextBridge } = require('electron')
|
||||
|
||||
contextBridge.exposeInMainWorld('electronAPI', {
|
||||
platform: process.platform,
|
||||
})
|
||||
Reference in New Issue
Block a user