Skip to content

Commit

Permalink
(UI) Migration to new Electron building tool electron-vite
Browse files Browse the repository at this point in the history
  • Loading branch information
stenya committed Jan 16, 2024
1 parent a90370b commit fcac621
Show file tree
Hide file tree
Showing 34 changed files with 5,039 additions and 33,646 deletions.
10 changes: 5 additions & 5 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 ]
branches: [ master, beta, development, feature/s160-update-binaries-to-latest-versions, feature/UI-app-migration-on-Vite ]
push:
branches: [ master, beta, development, feature/s160-update-binaries-to-latest-versions ]
branches: [ master, beta, development, feature/s160-update-binaries-to-latest-versions, feature/UI-app-migration-on-Vite ]
jobs:
win:
runs-on: windows-latest
Expand All @@ -31,7 +31,7 @@ jobs:
- name: Setup node
uses: actions/setup-node@v4
with:
node-version: 16.x #lts/*
node-version: 18.x #lts/*
cache: npm
cache-dependency-path: ui/package-lock.json

Expand Down Expand Up @@ -60,7 +60,7 @@ jobs:
- name: Setup node
uses: actions/setup-node@v4
with:
node-version: 16.x #lts/*
node-version: 18.x #lts/*
cache: npm
cache-dependency-path: ui/package-lock.json

Expand Down Expand Up @@ -104,7 +104,7 @@ jobs:
- name: Setup node
uses: actions/setup-node@v4
with:
node-version: 16.x #lts/*
node-version: 18.x #lts/*
cache: npm
cache-dependency-path: ui/package-lock.json

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ daemon/References/common/kem-helper/_out_linux/
daemon/References/common/kem-helper/_out_macos/
daemon/References/common/kem-helper/_out_windows/
daemon/References/Windows/v2ray/v2ray.exe
ui/out/
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ These instructions enable you to get the project up and running on your local ma
<a name="requirements_windows"></a>
#### Windows

[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
[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

<a name="requirements_macos"></a>
#### macOS
Expand Down
4 changes: 2 additions & 2 deletions snap/snapcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ parts:
- libnspr4
- libnss3
override-build: |
rm -fr dist_electron
rm -fr dist
./References/Linux/build.sh -v $SNAPCRAFT_PROJECT_VERSION
mkdir -p $SNAPCRAFT_PART_INSTALL/opt/ivpn/ui
cp -R dist_electron/bin $SNAPCRAFT_PART_INSTALL/opt/ivpn/ui
cp -R dist/bin $SNAPCRAFT_PART_INSTALL/opt/ivpn/ui
4 changes: 4 additions & 0 deletions ui/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
dist
out
.gitignore
15 changes: 15 additions & 0 deletions ui/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* eslint-env node */
require("@rushstack/eslint-patch/modern-module-resolution");

module.exports = {
extends: [
"eslint:recommended",
"plugin:vue/vue3-recommended",
"@electron-toolkit",
//"@vue/eslint-config-prettier",
],
rules: {
"vue/require-default-prop": "off",
"vue/multi-word-component-names": "off",
},
};
2 changes: 1 addition & 1 deletion ui/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pnpm-debug.log*
*.sw?

#Electron-builder output
/dist_electron
/dist
/References/Linux/_out_bin/*
/References/Linux/_tmp/*

Expand Down
6 changes: 6 additions & 0 deletions ui/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
out
dist
pnpm-lock.yaml
LICENSE.md
tsconfig.json
tsconfig.*.json
70 changes: 35 additions & 35 deletions ui/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Electron: Main",
"type": "node",
"request": "launch",
"protocol": "inspector",
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron",
"windows": {
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron.cmd"
},
"preLaunchTask": "electron-debug",
"args": ["--remote-debugging-port=9223", "./dist_electron"],
"outFiles": ["${workspaceFolder}/dist_electron/**/*.js"],
"env": {
"IS_DEBUG": "true"
"version": "0.2.0",
"configurations": [
{
"name": "Debug Main Process",
"type": "node",
"request": "launch",
"cwd": "${workspaceRoot}",
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron-vite",
"windows": {
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron-vite.cmd"
},
},
{
"name": "Electron: Renderer",
"type": "chrome",
"request": "attach",
"port": 9223,
"urlFilter": "http://localhost:*",
"timeout": 30000,
"webRoot": "${workspaceFolder}/src",
"sourceMapPathOverrides": {
"webpack:///./src/*": "${webRoot}/*"
},
"runtimeArgs": ["--sourcemap"],
"env": {
"REMOTE_DEBUGGING_PORT": "9222"
}
},
{
"name": "Debug Renderer Process",
"port": 9222,
"request": "attach",
"type": "chrome",
"webRoot": "${workspaceFolder}/src/renderer",
"timeout": 60000,
"presentation": {
"hidden": true
}
],
"compounds": [
{
"name": "Electron: All",
"configurations": ["Electron: Main", "Electron: Renderer"]
}
],
"compounds": [
{
"name": "Debug All",
"configurations": ["Debug Main Process", "Debug Renderer Process"],
"presentation": {
"order": 1
}
]
}
}
]
}
2 changes: 1 addition & 1 deletion ui/.vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@

"editor.formatOnSave": false,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
"source.fixAll.eslint": "explicit"
}
}
27 changes: 0 additions & 27 deletions ui/.vscode/tasks.json

This file was deleted.

6 changes: 3 additions & 3 deletions ui/References/Linux/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ CheckLastResult()
ARCH="$( node -e 'console.log(process.arch)' )"
SCRIPT_DIR="$( cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
OUT_DIR="$SCRIPT_DIR/_out_bin"
APP_UNPACKED_DIR="$SCRIPT_DIR/../../dist_electron/linux-unpacked"
APP_UNPACKED_DIR_ARCH="$SCRIPT_DIR/../../dist_electron/linux-${ARCH}-unpacked"
APP_BIN_DIR="$SCRIPT_DIR/../../dist_electron/bin"
APP_UNPACKED_DIR="$SCRIPT_DIR/../../dist/linux-unpacked"
APP_UNPACKED_DIR_ARCH="$SCRIPT_DIR/../../dist/linux-${ARCH}-unpacked"
APP_BIN_DIR="$SCRIPT_DIR/../../dist/bin"
IVPN_DESKTOP_UI2_SOURCES="$SCRIPT_DIR/../../"

# ---------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion ui/References/Linux/compile-ui.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

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

cd "$(dirname "$0")"
Expand Down
2 changes: 1 addition & 1 deletion ui/References/Windows/build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ goto :success
goto :eof

:copy_files
set UI_BINARIES_FOLDER=%SCRIPTDIR%..\..\dist_electron\win-unpacked
set UI_BINARIES_FOLDER=%SCRIPTDIR%..\..\dist\win-unpacked

set TIMESTAMP_SERVER=http://timestamp.digicert.com
if NOT "%CERT_SHA1%" == "" (
Expand Down
4 changes: 2 additions & 2 deletions ui/References/macOS/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ _PATH_IMAGE_FOLDER="${_SCRIPT_DIR}/_image"
_PATH_UI_COMPILED_IMAGE=${_PATH_IMAGE_FOLDER}/${_FNAME_UI_COMPILED}

_FNAME_UI_ORIG="IVPN.app"
_PATH_COMPILED_UI_ORIG="${_PATH_ABS_REPO_UI}/dist_electron/${_COMPILEDFOLDER}/${_FNAME_UI_ORIG}"
_PATH_COMPILED_UI_ORIG="${_PATH_ABS_REPO_UI}/dist/${_COMPILEDFOLDER}/${_FNAME_UI_ORIG}"

# Erasing old files
rm -fr ${_PATH_IMAGE_FOLDER}
Expand All @@ -215,7 +215,7 @@ fi

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

echo "[+] Preparing DMG image: Copying 'etc' ..."
cp -R "${_PATH_ABS_REPO_DAEMON}/References/macOS/etc" "${_PATH_UI_COMPILED_IMAGE}/Contents/Resources" || CheckLastResult
Expand Down
3 changes: 0 additions & 3 deletions ui/babel.config.js

This file was deleted.

17 changes: 17 additions & 0 deletions ui/buildHooks/afterPack.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
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]);
}
}
});
}

59 changes: 59 additions & 0 deletions ui/electron-builder.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
module.exports = {
files: [
"!**/.vscode/*",
"!src/*",
"!**/buildHooks/*",
"!**/public/*",
"!**/References/*",
"!**/extraResources/*",
"!{index.html,pre_build.js}",
"!electron-builder.config.{js,ts,mjs,cjs}",
"!electron.vite.config.{js,ts,mjs,cjs}",
"!{.eslintignore,.eslintrc.cjs,.prettierignore,.prettierrc.yaml,dev-app-update.yml,CHANGELOG.md,README.md}",
"!{.env,.env.*,.npmrc,pnpm-lock.yaml}",
],

afterPack: "buildHooks/afterPack.js",

mac: {
target: "dir",
extendInfo: {
LSUIElement: 1,
SUPublicDSAKeyFile: "dsa_pub.pem",
},
},
win: {
target: "dir",
//extraResources: [
// {
// from: "public/tray/windows",
// to: "tray/windows",
// filter: ["**/*"],
// },
//],
},
linux: {
target: ["dir"],
category: "Network",
},
snap: {
confinement: "strict",
autoStart: true,
plugs: [
"default",
{
port: {
interface: "content",
content: "file",
target: "$SNAP_COMMON/opt/ivpn/mutable",
},
},
],
},
extraResources: [
{
from: "extraResources",
filter: ["**/*"],
},
],
};
53 changes: 53 additions & 0 deletions ui/electron.vite.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { defineConfig, externalizeDepsPlugin } from 'electron-vite'
import vue from '@vitejs/plugin-vue'
import { resolve } from 'path'

// https://electron-vite.org/config/
export default defineConfig({
//https://electron-vite.org/config/#built-in-config-for-main
main: {
plugins: [externalizeDepsPlugin()],
build: {
lib: {
entry: resolve('./src/background.js'),
},
},
resolve: {
alias: {
"@": resolve("src")
},
extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue']
},
},
// https://electron-vite.org/config/#built-in-config-for-preload
preload: {
plugins: [externalizeDepsPlugin()],
build: {
lib: {
entry: './src/preload.js',
},
},
resolve: {
alias: {
"@": resolve("src")
},
extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue']
},
},
// https://electron-vite.org/config/#built-in-config-for-renderer
renderer: {
plugins: [vue()],
root: '.',
build: {
rollupOptions: {
input: 'index.html'
}
},
resolve: {
alias: {
"@": resolve("src")
},
extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue']
},
}
})
Loading

0 comments on commit fcac621

Please sign in to comment.