Skip to content

Commit 1925136

Browse files
Merge pull request #519 from OpenWebGAL/dev
4.5.17
2 parents bdb80e9 + 62dd497 commit 1925136

File tree

91 files changed

+4642
-1759
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+4642
-1759
lines changed

.gitattributes

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# Auto detect text files and perform LF normalization
2-
* text=auto
2+
* text=auto eol=lf

.github/workflows/build-terre.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
- name: Install Node.js
2222
uses: actions/setup-node@v4
2323
with:
24-
node-version-file: package.json
24+
node-version: 22
2525
cache: 'yarn'
2626
- name: Build
2727
env:
@@ -43,7 +43,7 @@ jobs:
4343
- name: Install Node.js
4444
uses: actions/setup-node@v4
4545
with:
46-
node-version-file: package.json
46+
node-version: 22
4747
cache: 'yarn'
4848
- name: Build
4949
env:
@@ -65,7 +65,7 @@ jobs:
6565
- name: Install Node.js
6666
uses: actions/setup-node@v4
6767
with:
68-
node-version-file: package.json
68+
node-version: 22
6969
cache: 'yarn'
7070
- name: Build
7171
env:
@@ -87,7 +87,7 @@ jobs:
8787
- name: Install Node.js
8888
uses: actions/setup-node@v4
8989
with:
90-
node-version-file: package.json
90+
node-version: 22
9191
cache: 'yarn'
9292
- name: Build
9393
shell: bash
@@ -108,7 +108,7 @@ jobs:
108108
- name: Install Node.js
109109
uses: actions/setup-node@v4
110110
with:
111-
node-version-file: package.json
111+
node-version: 22
112112
cache: 'yarn'
113113
- name: Build
114114
shell: bash
@@ -132,7 +132,7 @@ jobs:
132132
- name: Install Node.js
133133
uses: actions/setup-node@v4
134134
with:
135-
node-version-file: package.json
135+
node-version: 22
136136
cache: 'yarn'
137137
- name: Set up Java
138138
uses: actions/setup-java@v4

.github/workflows/release.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
- name: Install Node.js
1717
uses: actions/setup-node@v4
1818
with:
19-
node-version-file: package.json
19+
node-version: 22
2020
cache: 'yarn'
2121
- name: Build
2222
env:
@@ -38,7 +38,7 @@ jobs:
3838
- name: Install Node.js
3939
uses: actions/setup-node@v4
4040
with:
41-
node-version-file: package.json
41+
node-version: 22
4242
cache: 'yarn'
4343
- name: Build
4444
env:
@@ -60,7 +60,7 @@ jobs:
6060
- name: Install Node.js
6161
uses: actions/setup-node@v4
6262
with:
63-
node-version-file: package.json
63+
node-version: 22
6464
cache: 'yarn'
6565
- name: Build
6666
env:
@@ -82,7 +82,7 @@ jobs:
8282
- name: Install Node.js
8383
uses: actions/setup-node@v4
8484
with:
85-
node-version-file: package.json
85+
node-version: 22
8686
cache: 'yarn'
8787
- name: Build
8888
shell: bash
@@ -103,7 +103,7 @@ jobs:
103103
- name: Install Node.js
104104
uses: actions/setup-node@v4
105105
with:
106-
node-version-file: package.json
106+
node-version: 22
107107
cache: 'yarn'
108108
- name: Build
109109
shell: bash
@@ -127,7 +127,7 @@ jobs:
127127
- name: Install Node.js
128128
uses: actions/setup-node@v4
129129
with:
130-
node-version-file: package.json
130+
node-version: 22
131131
cache: 'yarn'
132132
- name: Set up Java
133133
uses: actions/setup-java@v4

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "webgal-terre",
3-
"version": "4.5.16",
3+
"version": "4.5.17",
44
"private": true,
55
"scripts": {
66
"dev": "concurrently \"yarn dev:terre\" \"yarn dev:origine\" \"yarn dev:start-dev-server\"",
@@ -38,4 +38,4 @@
3838
"@types/react": "^18.0.0",
3939
"@types/react-dom": "^18.0.0"
4040
}
41-
}
41+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export {};
2+
3+
declare global {
4+
interface Window {
5+
electronFuncs?: {
6+
steam?: {
7+
initialize: (appId: string) => boolean | Promise<boolean>;
8+
unlockAchievement: (achievementId: string) => boolean | Promise<boolean>;
9+
};
10+
};
11+
}
12+
}

packages/WebGAL-electron/main.js

Lines changed: 112 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,83 @@
1-
const { app, BrowserWindow, globalShortcut, Menu } = require('electron');
1+
const { app, BrowserWindow, globalShortcut, Menu, ipcMain } = require('electron');
22
const log = require('electron-log');
33
const path = require('path');
4+
const Steamworks = require('steamworks.js');
5+
6+
let steamClient;
7+
let steamCallbackInterval;
8+
9+
const parseAppId = (appId) => {
10+
if (typeof appId === 'number') {
11+
return appId;
12+
}
13+
const numeric = Number(appId);
14+
return Number.isNaN(numeric) ? appId : numeric;
15+
};
16+
17+
const stopSteamCallbacks = () => {
18+
if (steamCallbackInterval) {
19+
clearInterval(steamCallbackInterval);
20+
steamCallbackInterval = undefined;
21+
}
22+
};
23+
24+
ipcMain.handle('steam-initialize', async (_event, appId) => {
25+
if (steamClient) {
26+
return true;
27+
}
28+
29+
try {
30+
const parsedAppId = parseAppId(appId);
31+
steamClient = Steamworks.init(parsedAppId);
32+
33+
if (typeof steamClient?.runCallbacks === 'function' && !steamCallbackInterval) {
34+
steamCallbackInterval = setInterval(() => {
35+
try {
36+
steamClient.runCallbacks();
37+
} catch (error) {
38+
log.error('Steamworks runCallbacks failed', error);
39+
}
40+
}, 1000 / 60);
41+
42+
if (typeof steamCallbackInterval?.unref === 'function') {
43+
steamCallbackInterval.unref();
44+
}
45+
}
46+
47+
log.info('Steamworks initialized');
48+
return true;
49+
} catch (error) {
50+
log.error('Failed to initialize Steamworks', error);
51+
steamClient = undefined;
52+
stopSteamCallbacks();
53+
return false;
54+
}
55+
});
56+
57+
ipcMain.handle('steam-unlock-achievement', async (_event, achievementId) => {
58+
if (!steamClient) {
59+
log.warn(`Cannot unlock achievement ${achievementId}: Steamworks not initialized`);
60+
return false;
61+
}
62+
63+
try {
64+
const result = steamClient.achievement?.activate
65+
? steamClient.achievement.activate(achievementId)
66+
: false;
67+
68+
if (!result) {
69+
log.warn(`Steamworks failed to activate achievement ${achievementId}`);
70+
}
71+
72+
return Boolean(result);
73+
} catch (error) {
74+
log.error(`Error unlocking Steam achievement ${achievementId}`, error);
75+
return false;
76+
}
77+
});
78+
79+
app.commandLine.appendSwitch("--in-process-gpu"); // 修复 steam overlay
80+
app.commandLine.appendSwitch("--autoplay-policy", "no-user-gesture-required"); // 允许自动播放
481

582
/**
683
* 关闭默认菜单栏
@@ -12,6 +89,13 @@ Menu.setApplicationMenu(null);
1289
*/
1390
app.whenReady().then(() => {
1491
createWindow()
92+
93+
try {
94+
Steamworks.electronEnableSteamOverlay();
95+
} catch (error) {
96+
log.warn('Steam overlay could not be enabled', error);
97+
}
98+
1599
// 适配 Mac OS
16100
app.on('activate', () => {
17101
if (BrowserWindow.getAllWindows().length === 0) createWindow()
@@ -27,6 +111,11 @@ const createWindow = () => {
27111
height: 900,
28112
icon: path.join(__dirname, '../../icon.ico'),
29113
useContentSize: true,
114+
webPreferences: {
115+
preload: path.join(__dirname, 'preload.js'),
116+
contextIsolation: true,
117+
nodeIntegration: false,
118+
},
30119
})
31120

32121
win.loadFile('./public/index.html').then(r => {
@@ -57,18 +146,33 @@ const createWindow = () => {
57146

58147
logMessage(message);
59148
});
60-
149+
61150
/**
62-
* 侦听BrowserWindow关闭事件
63-
*/
64-
win.on("close", () => {
65-
app.quit();
66-
});
151+
* 侦听BrowserWindow关闭事件
152+
*/
153+
win.on("close", () => {
154+
app.quit();
155+
});
67156
}
68157

158+
app.on('before-quit', () => {
159+
globalShortcut.unregisterAll();
160+
stopSteamCallbacks();
161+
162+
if (steamClient && typeof steamClient.shutdown === 'function') {
163+
try {
164+
steamClient.shutdown();
165+
} catch (error) {
166+
log.error('Steamworks shutdown failed', error);
167+
}
168+
}
169+
170+
steamClient = undefined;
171+
});
172+
69173
/**
70174
* 在关闭所有窗口时退出应用
71175
*/
72176
app.on('window-all-closed', () => {
73177
if (process.platform !== 'darwin') app.quit()
74-
})
178+
})

packages/WebGAL-electron/package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,19 @@
3636
]
3737
},
3838
"mac": {
39-
"icon": "public/icon.ico"
39+
"icon": "public/icon.ico",
40+
"x64ArchFiles": "*"
4041
},
4142
"electronDownload": {
4243
"mirror": "https://npmmirror.com/mirrors/electron/"
4344
}
4445
},
4546
"dependencies": {
46-
"electron-log": "^5.1.5"
47+
"electron-log": "^5.1.5",
48+
"steamworks.js": "^0.4.0"
4749
},
4850
"repository": {
4951
"type": "git",
5052
"url": "https://github.com/OpenWebGAL/WebGAL_Terre.git"
5153
}
52-
}
54+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const { contextBridge, ipcRenderer } = require('electron');
2+
3+
contextBridge.exposeInMainWorld('electronFuncs', {
4+
steam: {
5+
initialize: (appId) => ipcRenderer.invoke('steam-initialize', appId),
6+
unlockAchievement: (achievementId) => ipcRenderer.invoke('steam-unlock-achievement', achievementId),
7+
},
8+
});
8.18 KB
Binary file not shown.

packages/WebGAL-electron/yarn.lock

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,9 +1158,9 @@ jake@^10.8.5:
11581158
minimatch "^3.1.2"
11591159

11601160
js-yaml@^4.1.0:
1161-
version "4.1.0"
1162-
resolved "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz"
1163-
integrity sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==
1161+
version "4.1.1"
1162+
resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-4.1.1.tgz#854c292467705b699476e1a2decc0c8a3458806b"
1163+
integrity sha512-qQKT4zQxXl8lLwBtHMWwaTcGfFOZviOJet3Oy/xmGk2gZH677CJM9EvtfdSkgWcATZhj/55JZ0rmy3myCT5lsA==
11641164
dependencies:
11651165
argparse "^2.0.1"
11661166

@@ -1587,6 +1587,13 @@ stat-mode@^1.0.0:
15871587
resolved "https://registry.npmjs.org/stat-mode/-/stat-mode-1.0.0.tgz"
15881588
integrity sha512-jH9EhtKIjuXZ2cWxmXS8ZP80XyC3iasQxMDV8jzhNJpfDb7VbQLVW4Wvsxz9QZvzV+G4YoSfBUVKDOyxLzi/sg==
15891589

1590+
steamworks.js@^0.4.0:
1591+
version "0.4.0"
1592+
resolved "https://registry.yarnpkg.com/steamworks.js/-/steamworks.js-0.4.0.tgz#b906998d3b9359519d3304b4f064aac39f229b47"
1593+
integrity sha512-O5TTRs7ucCRql4IA/kYUIQYeghTsXqf3rAm81sC22RDId264LQYqQjuaMEUSqL60I5LdULiGu0W2/A+ZDcKBKA==
1594+
dependencies:
1595+
"@types/node" "*"
1596+
15901597
"string-width-cjs@npm:string-width@^4.2.0":
15911598
version "4.2.3"
15921599
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"

0 commit comments

Comments
 (0)