Skip to content
This repository was archived by the owner on Jun 24, 2025. It is now read-only.

Commit cbcc219

Browse files
committed
fix(desktop): use plugin to clean up languages
1 parent 58e2bc2 commit cbcc219

File tree

3 files changed

+27
-55
lines changed

3 files changed

+27
-55
lines changed

apps/desktop/electron-forge/forge.config.cjs

Lines changed: 8 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const path = require("path");
22
const fs = require("fs-extra");
33
const { LOCALES } = require("@triliumnext/commons");
4+
const setLanguages = require('electron-packager-languages');
45

56
const ELECTRON_FORGE_DIR = __dirname;
67

@@ -29,6 +30,10 @@ const macosSignConfiguration = process.env.APPLE_ID ? {
2930
}
3031
} : undefined;
3132

33+
const localesToKeep = LOCALES
34+
.filter(locale => !locale.contentOnly)
35+
.map(locale => locale.electronLocale);
36+
3237
module.exports = {
3338
outDir: "out",
3439
// Documentation of `packagerConfig` options: https://electron.github.io/packager/main/interfaces/Options.html
@@ -45,6 +50,9 @@ module.exports = {
4550
...(process.platform === "darwin" ? [] : extraResourcesForPlatform)
4651
],
4752
prune: false,
53+
afterCopy: [
54+
setLanguages(localesToKeep)
55+
],
4856
afterComplete: [
4957
(buildPath, _electronVersion, platform, _arch, callback) => {
5058
// Only move resources on non-macOS platforms
@@ -142,53 +150,6 @@ module.exports = {
142150
}
143151
],
144152
hooks: {
145-
// Remove unused locales from the packaged app to save some space.
146-
postPackage(_, packageResult) {
147-
const localesToKeep = LOCALES
148-
.filter(locale => !locale.contentOnly)
149-
.map(locale => locale.electronLocale.replace("_", "-"));
150-
const keptLocales = new Set();
151-
const removedLocales = [];
152-
153-
for (const outputPath of packageResult.outputPaths) {
154-
const localesDir = path.join(outputPath, 'locales');
155-
156-
if (!fs.existsSync(localesDir)) {
157-
console.log('No locales directory found. Skipping cleanup.');
158-
return;
159-
}
160-
161-
const files = fs.readdirSync(localesDir);
162-
163-
for (const file of files) {
164-
let localeName = path.basename(file, ".pak");
165-
if (localeName === "en-US" && process.platform === "win32") {
166-
// If the locale is "en-US" on Windows, we treat it as "en".
167-
// This is because the Windows version of Electron uses "en-US.pak" instead of "en.pak".
168-
localeName = "en";
169-
}
170-
171-
if (localesToKeep.includes(localeName)) {
172-
keptLocales.add(localeName);
173-
continue;
174-
}
175-
176-
const filePath = path.join(localesDir, file);
177-
fs.unlinkSync(filePath);
178-
removedLocales.push(file);
179-
}
180-
}
181-
182-
console.log(`Removed unused locale files: ${removedLocales.join(", ")}`);
183-
184-
// Ensure all locales that should be kept are actually present.
185-
for (const locale of localesToKeep) {
186-
if (!keptLocales.has(locale)) {
187-
console.error(`Locale ${locale} was not found in the packaged app.`);
188-
process.exit(1);
189-
}
190-
}
191-
},
192153
// Gather all the artifacts produced by the makers and copy them to a common upload directory.
193154
postMake(_, makeResults) {
194155
const outputDir = path.join(__dirname, "..", "upload");

apps/desktop/package.json

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,10 @@
1010
"electron-debug": "4.1.0",
1111
"electron-dl": "4.0.0",
1212
"electron-squirrel-startup": "1.0.1",
13-
"jquery.fancytree": "2.38.5",
14-
"jquery-hotkeys": "0.2.2"
13+
"jquery-hotkeys": "0.2.2",
14+
"jquery.fancytree": "2.38.5"
1515
},
1616
"devDependencies": {
17-
"@types/electron-squirrel-startup": "1.0.2",
18-
"@triliumnext/server": "workspace:*",
19-
"copy-webpack-plugin": "13.0.0",
20-
"electron": "36.4.0",
2117
"@electron-forge/cli": "7.8.1",
2218
"@electron-forge/maker-deb": "7.8.1",
2319
"@electron-forge/maker-dmg": "7.8.1",
@@ -26,6 +22,11 @@
2622
"@electron-forge/maker-squirrel": "7.8.1",
2723
"@electron-forge/maker-zip": "7.8.1",
2824
"@electron-forge/plugin-auto-unpack-natives": "7.8.1",
25+
"@triliumnext/server": "workspace:*",
26+
"@types/electron-squirrel-startup": "1.0.2",
27+
"copy-webpack-plugin": "13.0.0",
28+
"electron": "36.4.0",
29+
"electron-packager-languages": "0.6.0",
2930
"prebuild-install": "^7.1.1"
3031
},
3132
"config": {
@@ -75,7 +76,7 @@
7576
"cjs"
7677
],
7778
"thirdParty": true,
78-
"declaration": false,
79+
"declaration": false,
7980
"esbuildOptions": {
8081
"splitting": false,
8182
"loader": {

pnpm-lock.yaml

Lines changed: 11 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)