Skip to content

Commit fcac621

Browse files
committed
(UI) Migration to new Electron building tool electron-vite
ivpn/desktop-app-shadow#165
1 parent a90370b commit fcac621

34 files changed

+5039
-33646
lines changed

.github/workflows/ci.yml

+5-5
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 ]
5+
branches: [ master, beta, development, feature/s160-update-binaries-to-latest-versions, feature/UI-app-migration-on-Vite ]
66
push:
7-
branches: [ master, beta, development, feature/s160-update-binaries-to-latest-versions ]
7+
branches: [ master, beta, development, feature/s160-update-binaries-to-latest-versions, feature/UI-app-migration-on-Vite ]
88
jobs:
99
win:
1010
runs-on: windows-latest
@@ -31,7 +31,7 @@ jobs:
3131
- name: Setup node
3232
uses: actions/setup-node@v4
3333
with:
34-
node-version: 16.x #lts/*
34+
node-version: 18.x #lts/*
3535
cache: npm
3636
cache-dependency-path: ui/package-lock.json
3737

@@ -60,7 +60,7 @@ jobs:
6060
- name: Setup node
6161
uses: actions/setup-node@v4
6262
with:
63-
node-version: 16.x #lts/*
63+
node-version: 18.x #lts/*
6464
cache: npm
6565
cache-dependency-path: ui/package-lock.json
6666

@@ -104,7 +104,7 @@ jobs:
104104
- name: Setup node
105105
uses: actions/setup-node@v4
106106
with:
107-
node-version: 16.x #lts/*
107+
node-version: 18.x #lts/*
108108
cache: npm
109109
cache-dependency-path: ui/package-lock.json
110110

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ daemon/References/common/kem-helper/_out_linux/
1212
daemon/References/common/kem-helper/_out_macos/
1313
daemon/References/common/kem-helper/_out_windows/
1414
daemon/References/Windows/v2ray/v2ray.exe
15+
ui/out/

readme.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ These instructions enable you to get the project up and running on your local ma
5151
<a name="requirements_windows"></a>
5252
#### Windows
5353

54-
[npm](https://www.npmjs.com/get-npm); [Node.js (16)](https://nodejs.org/); [nsis3](https://nsis.sourceforge.io/Download); Build Tools for Visual Studio 2019 ('Windows 10 SDK 10.0.19041.0', 'Windows 11 SDK 10.0.22000.0', 'MSVC v142 C++ x64 build tools', 'C++ ATL for latest v142 build tools'); gcc compiler e.g. [TDM GCC](https://jmeubank.github.io/tdm-gcc/download/); [Go 1.21+](https://golang.org/); Git
54+
[npm](https://www.npmjs.com/get-npm); [Node.js (18)](https://nodejs.org/); [nsis3](https://nsis.sourceforge.io/Download); Build Tools for Visual Studio 2019 ('Windows 10 SDK 10.0.19041.0', 'Windows 11 SDK 10.0.22000.0', 'MSVC v142 C++ x64 build tools', 'C++ ATL for latest v142 build tools'); gcc compiler e.g. [TDM GCC](https://jmeubank.github.io/tdm-gcc/download/); [Go 1.21+](https://golang.org/); Git
5555

5656
<a name="requirements_macos"></a>
5757
#### macOS

snap/snapcraft.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ parts:
305305
- libnspr4
306306
- libnss3
307307
override-build: |
308-
rm -fr dist_electron
308+
rm -fr dist
309309
./References/Linux/build.sh -v $SNAPCRAFT_PROJECT_VERSION
310310
mkdir -p $SNAPCRAFT_PART_INSTALL/opt/ivpn/ui
311-
cp -R dist_electron/bin $SNAPCRAFT_PART_INSTALL/opt/ivpn/ui
311+
cp -R dist/bin $SNAPCRAFT_PART_INSTALL/opt/ivpn/ui

ui/.eslintignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules
2+
dist
3+
out
4+
.gitignore

ui/.eslintrc.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/* eslint-env node */
2+
require("@rushstack/eslint-patch/modern-module-resolution");
3+
4+
module.exports = {
5+
extends: [
6+
"eslint:recommended",
7+
"plugin:vue/vue3-recommended",
8+
"@electron-toolkit",
9+
//"@vue/eslint-config-prettier",
10+
],
11+
rules: {
12+
"vue/require-default-prop": "off",
13+
"vue/multi-word-component-names": "off",
14+
},
15+
};

ui/.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pnpm-debug.log*
2121
*.sw?
2222

2323
#Electron-builder output
24-
/dist_electron
24+
/dist
2525
/References/Linux/_out_bin/*
2626
/References/Linux/_tmp/*
2727

ui/.prettierignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
out
2+
dist
3+
pnpm-lock.yaml
4+
LICENSE.md
5+
tsconfig.json
6+
tsconfig.*.json

ui/.vscode/launch.json

+35-35
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,39 @@
11
{
2-
"version": "0.2.0",
3-
"configurations": [
4-
{
5-
"name": "Electron: Main",
6-
"type": "node",
7-
"request": "launch",
8-
"protocol": "inspector",
9-
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron",
10-
"windows": {
11-
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron.cmd"
12-
},
13-
"preLaunchTask": "electron-debug",
14-
"args": ["--remote-debugging-port=9223", "./dist_electron"],
15-
"outFiles": ["${workspaceFolder}/dist_electron/**/*.js"],
16-
"env": {
17-
"IS_DEBUG": "true"
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"name": "Debug Main Process",
6+
"type": "node",
7+
"request": "launch",
8+
"cwd": "${workspaceRoot}",
9+
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron-vite",
10+
"windows": {
11+
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron-vite.cmd"
1812
},
19-
},
20-
{
21-
"name": "Electron: Renderer",
22-
"type": "chrome",
23-
"request": "attach",
24-
"port": 9223,
25-
"urlFilter": "http://localhost:*",
26-
"timeout": 30000,
27-
"webRoot": "${workspaceFolder}/src",
28-
"sourceMapPathOverrides": {
29-
"webpack:///./src/*": "${webRoot}/*"
30-
},
13+
"runtimeArgs": ["--sourcemap"],
14+
"env": {
15+
"REMOTE_DEBUGGING_PORT": "9222"
16+
}
17+
},
18+
{
19+
"name": "Debug Renderer Process",
20+
"port": 9222,
21+
"request": "attach",
22+
"type": "chrome",
23+
"webRoot": "${workspaceFolder}/src/renderer",
24+
"timeout": 60000,
25+
"presentation": {
26+
"hidden": true
3127
}
32-
],
33-
"compounds": [
34-
{
35-
"name": "Electron: All",
36-
"configurations": ["Electron: Main", "Electron: Renderer"]
28+
}
29+
],
30+
"compounds": [
31+
{
32+
"name": "Debug All",
33+
"configurations": ["Debug Main Process", "Debug Renderer Process"],
34+
"presentation": {
35+
"order": 1
3736
}
38-
]
39-
}
37+
}
38+
]
39+
}

ui/.vscode/settings.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@
1010

1111
"editor.formatOnSave": false,
1212
"editor.codeActionsOnSave": {
13-
"source.fixAll.eslint": true
13+
"source.fixAll.eslint": "explicit"
1414
}
1515
}

ui/.vscode/tasks.json

-27
This file was deleted.

ui/References/Linux/build.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ CheckLastResult()
5252
ARCH="$( node -e 'console.log(process.arch)' )"
5353
SCRIPT_DIR="$( cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
5454
OUT_DIR="$SCRIPT_DIR/_out_bin"
55-
APP_UNPACKED_DIR="$SCRIPT_DIR/../../dist_electron/linux-unpacked"
56-
APP_UNPACKED_DIR_ARCH="$SCRIPT_DIR/../../dist_electron/linux-${ARCH}-unpacked"
57-
APP_BIN_DIR="$SCRIPT_DIR/../../dist_electron/bin"
55+
APP_UNPACKED_DIR="$SCRIPT_DIR/../../dist/linux-unpacked"
56+
APP_UNPACKED_DIR_ARCH="$SCRIPT_DIR/../../dist/linux-${ARCH}-unpacked"
57+
APP_BIN_DIR="$SCRIPT_DIR/../../dist/bin"
5858
IVPN_DESKTOP_UI2_SOURCES="$SCRIPT_DIR/../../"
5959

6060
# ---------------------------------------------------------

ui/References/Linux/compile-ui.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

3-
# Building electron app (result can be found here: dist_electron/ivpn-ui-XXX.AppImage)
3+
# Building electron app (result can be found here: dist/ivpn-ui-XXX.AppImage)
44
# Configuring app version in file 'package.json'
55

66
cd "$(dirname "$0")"

ui/References/Windows/build.bat

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ goto :success
111111
goto :eof
112112

113113
:copy_files
114-
set UI_BINARIES_FOLDER=%SCRIPTDIR%..\..\dist_electron\win-unpacked
114+
set UI_BINARIES_FOLDER=%SCRIPTDIR%..\..\dist\win-unpacked
115115

116116
set TIMESTAMP_SERVER=http://timestamp.digicert.com
117117
if NOT "%CERT_SHA1%" == "" (

ui/References/macOS/build.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ _PATH_IMAGE_FOLDER="${_SCRIPT_DIR}/_image"
202202
_PATH_UI_COMPILED_IMAGE=${_PATH_IMAGE_FOLDER}/${_FNAME_UI_COMPILED}
203203

204204
_FNAME_UI_ORIG="IVPN.app"
205-
_PATH_COMPILED_UI_ORIG="${_PATH_ABS_REPO_UI}/dist_electron/${_COMPILEDFOLDER}/${_FNAME_UI_ORIG}"
205+
_PATH_COMPILED_UI_ORIG="${_PATH_ABS_REPO_UI}/dist/${_COMPILEDFOLDER}/${_FNAME_UI_ORIG}"
206206

207207
# Erasing old files
208208
rm -fr ${_PATH_IMAGE_FOLDER}
@@ -215,7 +215,7 @@ fi
215215

216216
echo "[+] Preparing DMG image: Copying UI binaries ..."
217217
cp -a "${_PATH_COMPILED_UI_ORIG}" ${_PATH_UI_COMPILED_IMAGE} || CheckLastResult
218-
rm ${_PATH_ABS_REPO_UI}/dist_electron/IVPN* # removing all created DMG (we do not need them)
218+
rm ${_PATH_ABS_REPO_UI}/dist/IVPN* # removing all created DMG (we do not need them)
219219

220220
echo "[+] Preparing DMG image: Copying 'etc' ..."
221221
cp -R "${_PATH_ABS_REPO_DAEMON}/References/macOS/etc" "${_PATH_UI_COMPILED_IMAGE}/Contents/Resources" || CheckLastResult

ui/babel.config.js

-3
This file was deleted.

ui/buildHooks/afterPack.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
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+

ui/electron-builder.config.js

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
module.exports = {
2+
files: [
3+
"!**/.vscode/*",
4+
"!src/*",
5+
"!**/buildHooks/*",
6+
"!**/public/*",
7+
"!**/References/*",
8+
"!**/extraResources/*",
9+
"!{index.html,pre_build.js}",
10+
"!electron-builder.config.{js,ts,mjs,cjs}",
11+
"!electron.vite.config.{js,ts,mjs,cjs}",
12+
"!{.eslintignore,.eslintrc.cjs,.prettierignore,.prettierrc.yaml,dev-app-update.yml,CHANGELOG.md,README.md}",
13+
"!{.env,.env.*,.npmrc,pnpm-lock.yaml}",
14+
],
15+
16+
afterPack: "buildHooks/afterPack.js",
17+
18+
mac: {
19+
target: "dir",
20+
extendInfo: {
21+
LSUIElement: 1,
22+
SUPublicDSAKeyFile: "dsa_pub.pem",
23+
},
24+
},
25+
win: {
26+
target: "dir",
27+
//extraResources: [
28+
// {
29+
// from: "public/tray/windows",
30+
// to: "tray/windows",
31+
// filter: ["**/*"],
32+
// },
33+
//],
34+
},
35+
linux: {
36+
target: ["dir"],
37+
category: "Network",
38+
},
39+
snap: {
40+
confinement: "strict",
41+
autoStart: true,
42+
plugs: [
43+
"default",
44+
{
45+
port: {
46+
interface: "content",
47+
content: "file",
48+
target: "$SNAP_COMMON/opt/ivpn/mutable",
49+
},
50+
},
51+
],
52+
},
53+
extraResources: [
54+
{
55+
from: "extraResources",
56+
filter: ["**/*"],
57+
},
58+
],
59+
};

ui/electron.vite.config.mjs

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { defineConfig, externalizeDepsPlugin } from 'electron-vite'
2+
import vue from '@vitejs/plugin-vue'
3+
import { resolve } from 'path'
4+
5+
// https://electron-vite.org/config/
6+
export default defineConfig({
7+
//https://electron-vite.org/config/#built-in-config-for-main
8+
main: {
9+
plugins: [externalizeDepsPlugin()],
10+
build: {
11+
lib: {
12+
entry: resolve('./src/background.js'),
13+
},
14+
},
15+
resolve: {
16+
alias: {
17+
"@": resolve("src")
18+
},
19+
extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue']
20+
},
21+
},
22+
// https://electron-vite.org/config/#built-in-config-for-preload
23+
preload: {
24+
plugins: [externalizeDepsPlugin()],
25+
build: {
26+
lib: {
27+
entry: './src/preload.js',
28+
},
29+
},
30+
resolve: {
31+
alias: {
32+
"@": resolve("src")
33+
},
34+
extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue']
35+
},
36+
},
37+
// https://electron-vite.org/config/#built-in-config-for-renderer
38+
renderer: {
39+
plugins: [vue()],
40+
root: '.',
41+
build: {
42+
rollupOptions: {
43+
input: 'index.html'
44+
}
45+
},
46+
resolve: {
47+
alias: {
48+
"@": resolve("src")
49+
},
50+
extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue']
51+
},
52+
}
53+
})

0 commit comments

Comments
 (0)