From 03bf14f10aac5e1460b4fadb9ae88b6e3b288b42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BD=D0=B8=D1=97=D0=BB=20=D0=93=D1=80=D0=B8?= =?UTF-8?q?=D0=B3=D0=BE=D1=80=27=D1=94=D0=B2?= Date: Wed, 26 Mar 2025 22:23:17 +0200 Subject: [PATCH 1/4] Add missing TypeScript package and update readme Unfortunately we have to keep a second copy for now. The lockfile specifies the same version as used in the root package to avoid issues. This may be replaced with Node.js type stripping in the future. README.md is updated to include the correct command for testing the Electron wrapper. --- README.md | 2 +- electron/package.json | 3 ++- electron/yarn.lock | 5 +++++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index eea0bef3..0af12b06 100644 --- a/README.md +++ b/README.md @@ -69,7 +69,7 @@ and does not intend to provide compatibility for older clients. - Run `yarn` in the root folder and in `electron/`. - Run `yarn gulp` in the root folder to build and serve files. Ignore the browser tab that opens. -- Open a new terminal and run `yarn startDev` in `electron/` to open an Electron window. +- Open a new terminal and run `yarn start` in `electron/` to open an Electron window. - Tip: If you open the Electron window too early, you can reload it when focused on DevTools. ### Release diff --git a/electron/package.json b/electron/package.json index b19c7d38..f93c08c2 100644 --- a/electron/package.json +++ b/electron/package.json @@ -10,6 +10,7 @@ }, "dependencies": {}, "devDependencies": { - "electron": "^31.3.0" + "electron": "^31.3.0", + "typescript": "^5.4.5" } } diff --git a/electron/yarn.lock b/electron/yarn.lock index ada2f8aa..874c6379 100644 --- a/electron/yarn.lock +++ b/electron/yarn.lock @@ -495,6 +495,11 @@ type-fest@^0.13.1: resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-0.13.1.tgz#0172cb5bce80b0bd542ea348db50c7e21834d934" integrity sha512-34R7HTnG0XIJcBSn5XhDd7nNFPRcXYRZrBB2O2jdKqYODldSzBAqzsWoZYYvduky73toYS/ESqxPvkDf/F0XMg== +typescript@5.4.5: + version "5.4.5" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.4.5.tgz#42ccef2c571fdbd0f6718b1d1f5e6e5ef006f611" + integrity sha512-vcI4UpRgg81oIRUFwR0WSIHKt11nJ7SAVlYNIu+QpqeyXP+gpQJy/Z4+F0aGxSE4MqwjyXvW/TzgkLAx2AGHwQ== + undici-types@~5.26.4: version "5.26.5" resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-5.26.5.tgz#bcd539893d00b56e964fd2657a4866b221a65617" From ae1cd71d3b4dde123d10dabde8f2db8042d9d8db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BD=D0=B8=D1=97=D0=BB=20=D0=93=D1=80=D0=B8?= =?UTF-8?q?=D0=B3=D0=BE=D1=80=27=D1=94=D0=B2?= Date: Wed, 26 Mar 2025 22:46:14 +0200 Subject: [PATCH 2/4] Fix file writes to non-existent directories When the game attempts to create the settings file but its directory does not exist yet, an early error occurs. In reality, there is no way for the directory to be created without user intervention. This change makes sure the directory is created before any attempt to write a file is done. Errors related to directory creation and/or file writes are still reported as usual. --- electron/src/fsjob.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/electron/src/fsjob.ts b/electron/src/fsjob.ts index 6672ad8d..0e85ea69 100644 --- a/electron/src/fsjob.ts +++ b/electron/src/fsjob.ts @@ -49,6 +49,10 @@ export class FsJobHandler { } private async write(file: string, contents: string): Promise { + // The target directory might not exist, ensure it does + const parentDir = path.dirname(file); + await fs.mkdir(parentDir, { recursive: true }); + // Backups not implemented yet. await fs.writeFile(file, contents, { encoding: "utf-8", From 2997cf8daf5dc2883e4a6c2cb1ae4f15e9d377b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BD=D0=B8=D1=97=D0=BB=20=D0=93=D1=80=D0=B8?= =?UTF-8?q?=D0=B3=D0=BE=D1=80=27=D1=94=D0=B2?= Date: Thu, 27 Mar 2025 23:02:45 +0200 Subject: [PATCH 3/4] Handle window.open calls with external browser Re-use the same openExternalUrl logic meant for frame navigation to handle window.open calls as well. Possibly a partial solution, as the ability to open new windows might be useful for mods. --- electron/src/index.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/electron/src/index.ts b/electron/src/index.ts index 5962a2db..e4d67a8f 100644 --- a/electron/src/index.ts +++ b/electron/src/index.ts @@ -65,6 +65,12 @@ function createWindow() { ev.preventDefault(); openExternalUrl(url); }); + + // Also redirect window.open + win.webContents.setWindowOpenHandler(({ url }) => { + openExternalUrl(url); + return { action: "deny" }; + }); } function openExternalUrl(urlString: string) { From 8e87398c3c98d1827d5967431794aa53b1cd7243 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BD=D0=B8=D1=97=D0=BB=20=D0=93=D1=80=D0=B8?= =?UTF-8?q?=D0=B3=D0=BE=D1=80=27=D1=94=D0=B2?= Date: Sat, 29 Mar 2025 20:11:07 +0200 Subject: [PATCH 4/4] Update TypeScript packages Yarn seems to complain due to my hand-edited package.json, but TypeScript packages are out of sync if I let it update the electron one. To avoid these issues, update both packages. --- electron/package.json | 2 +- electron/yarn.lock | 8 ++++---- package.json | 2 +- yarn.lock | 8 ++++---- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/electron/package.json b/electron/package.json index f93c08c2..c47d3cbd 100644 --- a/electron/package.json +++ b/electron/package.json @@ -11,6 +11,6 @@ "dependencies": {}, "devDependencies": { "electron": "^31.3.0", - "typescript": "^5.4.5" + "typescript": "^5.8.2" } } diff --git a/electron/yarn.lock b/electron/yarn.lock index 874c6379..a82b7b14 100644 --- a/electron/yarn.lock +++ b/electron/yarn.lock @@ -495,10 +495,10 @@ type-fest@^0.13.1: resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-0.13.1.tgz#0172cb5bce80b0bd542ea348db50c7e21834d934" integrity sha512-34R7HTnG0XIJcBSn5XhDd7nNFPRcXYRZrBB2O2jdKqYODldSzBAqzsWoZYYvduky73toYS/ESqxPvkDf/F0XMg== -typescript@5.4.5: - version "5.4.5" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.4.5.tgz#42ccef2c571fdbd0f6718b1d1f5e6e5ef006f611" - integrity sha512-vcI4UpRgg81oIRUFwR0WSIHKt11nJ7SAVlYNIu+QpqeyXP+gpQJy/Z4+F0aGxSE4MqwjyXvW/TzgkLAx2AGHwQ== +typescript@^5.8.2: + version "5.8.2" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.8.2.tgz#8170b3702f74b79db2e5a96207c15e65807999e4" + integrity sha512-aJn6wq13/afZp/jT9QZmwEjDqqvSGp1VT5GVg+f/t6/oVyrgXM6BY1h9BRh/O5p3PlUPAe+WuiEZOmb/49RqoQ== undici-types@~5.26.4: version "5.26.5" diff --git a/package.json b/package.json index 01eaca86..27e85253 100644 --- a/package.json +++ b/package.json @@ -83,7 +83,7 @@ "strip-json-comments": "^3.0.1", "terser-webpack-plugin": "^5.3.6", "ts-loader": "^9.4.2", - "typescript": "^5.4.5", + "typescript": "^5.8.2", "typescript-eslint": "^7.7.1", "webpack": "^5.75.0", "webpack-deadcode-plugin": "^0.1.17", diff --git a/yarn.lock b/yarn.lock index 89b1f334..3f2dd6ee 100644 --- a/yarn.lock +++ b/yarn.lock @@ -9799,10 +9799,10 @@ typescript@^4.6.2: resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.9.3.tgz#3aea307c1746b8c384435d8ac36b8a2e580d85db" integrity sha512-CIfGzTelbKNEnLpLdGFgdyKhG23CKdKgQPOBc+OUNrkJ2vr+KSzsSV5kq5iWhEQbok+quxgGzrAtGWCyU7tHnA== -typescript@^5.4.5: - version "5.4.5" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.4.5.tgz#42ccef2c571fdbd0f6718b1d1f5e6e5ef006f611" - integrity sha512-vcI4UpRgg81oIRUFwR0WSIHKt11nJ7SAVlYNIu+QpqeyXP+gpQJy/Z4+F0aGxSE4MqwjyXvW/TzgkLAx2AGHwQ== +typescript@^5.8.2: + version "5.8.2" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.8.2.tgz#8170b3702f74b79db2e5a96207c15e65807999e4" + integrity sha512-aJn6wq13/afZp/jT9QZmwEjDqqvSGp1VT5GVg+f/t6/oVyrgXM6BY1h9BRh/O5p3PlUPAe+WuiEZOmb/49RqoQ== ua-parser-js@1.0.2: version "1.0.2"