Skip to content

Commit 69c86dc

Browse files
committed
(macOS) Removed unused locales in order to reduce UI app size
ivpn/desktop-app-shadow#165
1 parent fcac621 commit 69c86dc

File tree

7 files changed

+76
-42
lines changed

7 files changed

+76
-42
lines changed

.github/workflows/ci.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ name: CI
22

33
on:
44
pull_request:
5-
branches: [ master, beta, development, feature/s160-update-binaries-to-latest-versions, feature/UI-app-migration-on-Vite ]
5+
branches: [ master, beta, development, test ]
66
push:
7-
branches: [ master, beta, development, feature/s160-update-binaries-to-latest-versions, feature/UI-app-migration-on-Vite ]
7+
branches: [ master, beta, development, test ]
88
jobs:
99
win:
1010
runs-on: windows-latest

.github/workflows/codeql-analysis.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ name: "CodeQL"
1313

1414
on:
1515
push:
16-
branches: [ master, beta, development ]
16+
branches: [ master, beta, development, test ]
1717
pull_request:
1818
# The branches below must be a subset of the branches above
19-
branches: [ master, beta, development ]
19+
branches: [ master, beta, development, test ]
2020
schedule:
2121
- cron: '18 19 * * 6'
2222

.github/workflows/gosec.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ name: "Security Scan (gosec)"
22

33
on:
44
pull_request:
5-
branches: [ master, beta, development ]
5+
branches: [ master, beta, development, test ]
66
push:
7-
branches: [ master, beta, development ]
7+
branches: [ master, beta, development, test ]
88

99
permissions: read-all
1010

ui/buildHooks/afterPack.js

+57-16
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,58 @@
1+
var fs = require ('fs');
2+
const path = require('path');
3+
14
exports.default = async function (context) {
2-
console.log (`afterPack hook triggered (${__filename})`);
3-
console.log (" - removing all locales except en-US");
4-
var fs = require ('fs');
5-
var localeDir = context.appOutDir+'/locales/';
6-
7-
fs.readdir (localeDir, function (err, files) {
8-
if (! (files && files.length)) return;
9-
for (var i = 0, len = files.length; i < len; i++) {
10-
var match = files[i].match(/en-US\.pak/);
11-
if (match === null) {
12-
fs.unlinkSync (localeDir+files [i]);
13-
}
14-
}
15-
});
16-
}
17-
5+
console.log (`AfterPack hook triggered ('${__filename}')`);
6+
7+
// In order to reduce the size of the app, we remove all unused locales
8+
try {
9+
if (context?.packager?.platform?.buildConfigurationKey === 'mac') {
10+
let localeDir = context.appOutDir+'/IVPN.app/Contents/Frameworks/Electron Framework.framework/Resources/';
11+
if (fs.existsSync(localeDir))
12+
removeLocalesMac(localeDir);
13+
} else {
14+
let localeDir = context.appOutDir+'/locales/';
15+
if (fs.existsSync(localeDir))
16+
removeLocales(localeDir);
17+
}
18+
} catch (e) {
19+
console.error("Error removing locales in afterPack hook:", e);
20+
}
21+
}
22+
23+
function removeLocales(localesFolderPath) {
24+
console.log (` - removing all locales except en-US (from '${localesFolderPath}')`);
25+
let removedCnt = 0;
26+
let files = fs.readdirSync(localesFolderPath);
27+
if (files && files.length) {
28+
for (var i = 0, len = files.length; i < len; i++) {
29+
var match = files[i].match(/en-US\.pak/);
30+
if (match === null) {
31+
fs.unlinkSync(path.join(localesFolderPath, files[i]));
32+
removedCnt+=1;
33+
}
34+
}
35+
}
36+
console.log (` removed ${removedCnt} locales`);
37+
}
38+
39+
function removeLocalesMac(resourcesFolderPath) {
40+
console.log (` - removing all locales except en/en-US (from '${resourcesFolderPath}')`);
41+
let removedCnt = 0;
42+
let files = fs.readdirSync(resourcesFolderPath);
43+
if (files && files.length) {
44+
for (var i = 0, len = files.length; i < len; i++) {
45+
const lprojDir = files[i];
46+
if (lprojDir === 'en.lproj' || lprojDir === 'en-US.lproj' || lprojDir === 'en_US.lproj')
47+
continue;
48+
const lprojDirPath = path.join(resourcesFolderPath, files[i]);
49+
const localePakPath = path.join(lprojDirPath,"locale.pak");
50+
if (fs.lstatSync(lprojDirPath).isDirectory() && path.extname(lprojDirPath) === '.lproj' && fs.existsSync(localePakPath)) {
51+
fs.unlinkSync(localePakPath);
52+
fs.rmdirSync(lprojDirPath);
53+
removedCnt+=1;
54+
}
55+
}
56+
}
57+
console.log (` removed ${removedCnt} locales`);
58+
}

ui/electron-builder.config.js

+3-10
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ module.exports = {
1414
],
1515

1616
afterPack: "buildHooks/afterPack.js",
17-
17+
1818
mac: {
1919
target: "dir",
2020
extendInfo: {
@@ -23,17 +23,10 @@ module.exports = {
2323
},
2424
},
2525
win: {
26-
target: "dir",
27-
//extraResources: [
28-
// {
29-
// from: "public/tray/windows",
30-
// to: "tray/windows",
31-
// filter: ["**/*"],
32-
// },
33-
//],
26+
target: "dir",
3427
},
3528
linux: {
36-
target: ["dir"],
29+
target: "dir",
3730
category: "Network",
3831
},
3932
snap: {

ui/package-lock.json

+8-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ui/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@
3636
},
3737
"devDependencies": {
3838
"@electron-toolkit/eslint-config": "1.0.2",
39-
"@rushstack/eslint-patch": "1.6.1",
39+
"@rushstack/eslint-patch": "1.7.0",
4040
"@vitejs/plugin-vue": "5.0.3",
4141
"@vue/eslint-config-prettier": "8.0.0",
4242
"electron": "25.9.8",
4343
"electron-builder": "24.9.1",
4444
"electron-vite": "^2.0.0",
4545
"eslint": "8.56.0",
4646
"eslint-plugin-vue": "9.20.1",
47-
"prettier": "3.2.2",
47+
"prettier": "3.2.3",
4848
"sass": "1.69.7",
4949
"vite": "5.0.11",
5050
"vue": "3.4.14",

0 commit comments

Comments
 (0)