Skip to content

Commit

Permalink
(macOS) Removed unused locales in order to reduce UI app size
Browse files Browse the repository at this point in the history
  • Loading branch information
stenya committed Jan 17, 2024
1 parent fcac621 commit 69c86dc
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 42 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: CI

on:
pull_request:
branches: [ master, beta, development, feature/s160-update-binaries-to-latest-versions, feature/UI-app-migration-on-Vite ]
branches: [ master, beta, development, test ]
push:
branches: [ master, beta, development, feature/s160-update-binaries-to-latest-versions, feature/UI-app-migration-on-Vite ]
branches: [ master, beta, development, test ]
jobs:
win:
runs-on: windows-latest
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ name: "CodeQL"

on:
push:
branches: [ master, beta, development ]
branches: [ master, beta, development, test ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ master, beta, development ]
branches: [ master, beta, development, test ]
schedule:
- cron: '18 19 * * 6'

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/gosec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: "Security Scan (gosec)"

on:
pull_request:
branches: [ master, beta, development ]
branches: [ master, beta, development, test ]
push:
branches: [ master, beta, development ]
branches: [ master, beta, development, test ]

permissions: read-all

Expand Down
73 changes: 57 additions & 16 deletions ui/buildHooks/afterPack.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,58 @@
var fs = require ('fs');
const path = require('path');

exports.default = async function (context) {
console.log (`afterPack hook triggered (${__filename})`);
console.log (" - removing all locales except en-US");
var fs = require ('fs');
var localeDir = context.appOutDir+'/locales/';

fs.readdir (localeDir, function (err, files) {
if (! (files && files.length)) return;
for (var i = 0, len = files.length; i < len; i++) {
var match = files[i].match(/en-US\.pak/);
if (match === null) {
fs.unlinkSync (localeDir+files [i]);
}
}
});
}

console.log (`AfterPack hook triggered ('${__filename}')`);

// In order to reduce the size of the app, we remove all unused locales
try {
if (context?.packager?.platform?.buildConfigurationKey === 'mac') {
let localeDir = context.appOutDir+'/IVPN.app/Contents/Frameworks/Electron Framework.framework/Resources/';
if (fs.existsSync(localeDir))
removeLocalesMac(localeDir);
} else {
let localeDir = context.appOutDir+'/locales/';
if (fs.existsSync(localeDir))
removeLocales(localeDir);
}
} catch (e) {
console.error("Error removing locales in afterPack hook:", e);
}
}

function removeLocales(localesFolderPath) {
console.log (` - removing all locales except en-US (from '${localesFolderPath}')`);
let removedCnt = 0;
let files = fs.readdirSync(localesFolderPath);
if (files && files.length) {
for (var i = 0, len = files.length; i < len; i++) {
var match = files[i].match(/en-US\.pak/);
if (match === null) {
fs.unlinkSync(path.join(localesFolderPath, files[i]));
removedCnt+=1;
}
}
}
console.log (` removed ${removedCnt} locales`);
}

function removeLocalesMac(resourcesFolderPath) {
console.log (` - removing all locales except en/en-US (from '${resourcesFolderPath}')`);
let removedCnt = 0;
let files = fs.readdirSync(resourcesFolderPath);
if (files && files.length) {
for (var i = 0, len = files.length; i < len; i++) {
const lprojDir = files[i];
if (lprojDir === 'en.lproj' || lprojDir === 'en-US.lproj' || lprojDir === 'en_US.lproj')
continue;
const lprojDirPath = path.join(resourcesFolderPath, files[i]);
const localePakPath = path.join(lprojDirPath,"locale.pak");
if (fs.lstatSync(lprojDirPath).isDirectory() && path.extname(lprojDirPath) === '.lproj' && fs.existsSync(localePakPath)) {
fs.unlinkSync(localePakPath);
fs.rmdirSync(lprojDirPath);
removedCnt+=1;
}
}
}
console.log (` removed ${removedCnt} locales`);
}
13 changes: 3 additions & 10 deletions ui/electron-builder.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module.exports = {
],

afterPack: "buildHooks/afterPack.js",

mac: {
target: "dir",
extendInfo: {
Expand All @@ -23,17 +23,10 @@ module.exports = {
},
},
win: {
target: "dir",
//extraResources: [
// {
// from: "public/tray/windows",
// to: "tray/windows",
// filter: ["**/*"],
// },
//],
target: "dir",
},
linux: {
target: ["dir"],
target: "dir",
category: "Network",
},
snap: {
Expand Down
16 changes: 8 additions & 8 deletions ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@
},
"devDependencies": {
"@electron-toolkit/eslint-config": "1.0.2",
"@rushstack/eslint-patch": "1.6.1",
"@rushstack/eslint-patch": "1.7.0",
"@vitejs/plugin-vue": "5.0.3",
"@vue/eslint-config-prettier": "8.0.0",
"electron": "25.9.8",
"electron-builder": "24.9.1",
"electron-vite": "^2.0.0",
"eslint": "8.56.0",
"eslint-plugin-vue": "9.20.1",
"prettier": "3.2.2",
"prettier": "3.2.3",
"sass": "1.69.7",
"vite": "5.0.11",
"vue": "3.4.14",
Expand Down

0 comments on commit 69c86dc

Please sign in to comment.