Skip to content

Commit

Permalink
feat: support fixed webview variants
Browse files Browse the repository at this point in the history
feat: support fixed webview variants

feat: support fixed webview variants

feat: support fixed webview variants
  • Loading branch information
greenhat616 committed Sep 20, 2024
1 parent 28982cf commit 9822f78
Show file tree
Hide file tree
Showing 7 changed files with 168 additions and 33 deletions.
108 changes: 80 additions & 28 deletions .github/workflows/deps-build-windows-nsis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ on:
type: boolean
default: false

fixed-webview:
description: "Fixed WebView"
required: true
type: boolean
default: false

nightly:
description: "Nightly prepare"
required: true
Expand Down Expand Up @@ -38,6 +44,12 @@ on:
type: boolean
default: false

fixed-webview:
description: "Fixed WebView"
required: true
type: boolean
default: false

nightly:
description: "Nightly prepare"
required: true
Expand Down Expand Up @@ -108,67 +120,107 @@ jobs:
}
}
- name: Download fixed WebView
if: ${{ inputs.fixed-webview == true }}
run: |
$condition = '${{ inputs.arch }}'
switch ($condition) {
'x86_64' {
$arch= 'x64'
}
'i686' {
$arch = 'x86'
}
'aarch64' {
$arch = 'arm64'
}
}
$version = '127.0.2651.105'
$uri = "https://github.com/westinyang/WebView2RuntimeArchive/releases/download/$version/Microsoft.WebView2.FixedVersionRuntime.$version.$arch.cab"
$outfile = "Microsoft.WebView2.FixedVersionRuntime.$version.$arch.cab"
echo "Downloading $uri to $outfile"
invoke-webrequest -uri $uri -outfile $outfile
echo "Download finished, attempting to extract"
expand.exe $outfile -F:* ./backend/tauri
echo "Extraction finished"
- name: Prepare (Windows NSIS and Portable)
if: ${{ inputs.fixed-webview == false }}
run: ${{ inputs.nightly == true && 'pnpm prepare:nightly --nsis' || 'pnpm prepare:release --nsis' }}

- name: Prepare (Windows NSIS and Portable) with fixed WebView
if: ${{ inputs.fixed-webview == true }}
run: ${{ inputs.nightly == true && 'pnpm prepare:nightly --nsis --fixed-webview' || 'pnpm prepare:release --nsis --fixed-webview' }}

- name: Build UI
run: |
pnpm -F ui build
# TODO: optimize strategy
- name: Tauri build x86_64
uses: tauri-apps/tauri-action@v0
if: ${{ inputs.arch == 'x86_64' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAURI_SIGNING_PRIVATE_KEY: ${{ secrets.TAURI_PRIVATE_KEY }}
TAURI_SIGNING_PRIVATE_KEY_PASSWORD: ${{ secrets.TAURI_KEY_PASSWORD }}
NIGHTLY: ${{ inputs.nightly == true && 'true' || 'false' }}
with:
tagName: ${{ inputs.tag }}
releaseName: "Clash Nyanpasu Dev"
releaseBody: "More new features are now supported."
releaseDraft: false
prerelease: true
tauriScript: pnpm tauri
args: ${{ inputs.nightly == true && '-f nightly -c ./backend/tauri/tauri.nightly.conf.json' || '-f default-meta' }}
run: |
pnpm tauri build ${{ inputs.nightly == true && '-f nightly -c ./backend/tauri/tauri.nightly.conf.json' || '-f default-meta' }}
- name: Tauri build i686
uses: tauri-apps/tauri-action@v0
if: ${{ inputs.arch == 'i686' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAURI_SIGNING_PRIVATE_KEY: ${{ secrets.TAURI_PRIVATE_KEY }}
TAURI_SIGNING_PRIVATE_KEY_PASSWORD: ${{ secrets.TAURI_KEY_PASSWORD }}
NIGHTLY: ${{ inputs.nightly == true && 'true' || 'false' }}
with:
tagName: ${{ inputs.tag }}
releaseName: "Clash Nyanpasu Dev"
releaseBody: "More new features are now supported."
releaseDraft: false
prerelease: true
tauriScript: pnpm tauri
args: ${{ inputs.nightly == true && '-f nightly -c ./backend/tauri/tauri.nightly.conf.json --target i686-pc-windows-msvc' || '-f default-meta --target i686-pc-windows-msvc' }}
run: |
pnpm tauri build ${{ inputs.nightly == true && '-f nightly -c ./backend/tauri/tauri.nightly.conf.json --target i686-pc-windows-msvc' || '-f default-meta --target i686-pc-windows-msvc' }}
- name: Tauri build arm64
uses: tauri-apps/tauri-action@v0
if: ${{ inputs.arch == 'aarch64' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAURI_SIGNING_PRIVATE_KEY: ${{ secrets.TAURI_PRIVATE_KEY }}
TAURI_SIGNING_PRIVATE_KEY_PASSWORD: ${{ secrets.TAURI_KEY_PASSWORD }}
NIGHTLY: ${{ inputs.nightly == true && 'true' || 'false' }}
with:
tagName: ${{ inputs.tag }}
releaseName: "Clash Nyanpasu Dev"
releaseBody: "More new features are now supported."
releaseDraft: false
prerelease: true
tauriScript: pnpm tauri
args: ${{ inputs.nightly == true && '-f nightly -c ./backend/tauri/tauri.nightly.conf.json --target aarch64-pc-windows-msvc' || '-f default-meta --target aarch64-pc-windows-msvc' }}
run: |
pnpm tauri build ${{ inputs.nightly == true && '-f nightly -c ./backend/tauri/tauri.nightly.conf.json --target aarch64-pc-windows-msvc' || '-f default-meta --target aarch64-pc-windows-msvc' }}
- name: Rename fixed webview bundle name
if: ${{ inputs.fixed-webview == true }}
run: |
$files = Get-ChildItem -Path "./backend/target" -Recurse -Include "*.exe", "*.zip", "*.zip.sig" | Where-Object { $_.FullName -like "*\bundle\*" }
$condition = '${{ inputs.arch }}'
switch ($condition) {
'x86_64' {
$arch= 'x64'
}
'i686' {
$arch = 'x86'
}
'aarch64' {
$arch = 'arm64'
}
}
foreach ($file in $files) {
echo "Renaming $file.FullName"
$newname = $file.FullName -replace $arch, "fixed-webview-$arch"
Rename-Item -Path $file.FullName -NewName $newname
}
- name: Upload to release
run: |
$files = Get-ChildItem -Path "./backend/target" -Recurse -Include "*.exe", "*.zip", "*.zip.sig" | Where-Object { $_.FullName -like "*\bundle\*" }
foreach ($file in $files) {
echo "Uploading $file.FullName"
gh release upload ${{ inputs.tag }} "$file.FullName" --clobber
}
- name: Portable Bundle
if: ${{ inputs.portable == true }}
run: |
pnpm portable
pnpm portable ${{ inputs.fixed-webview == true && '--fixed-webview' || '' }}
env:
RUST_ARCH: ${{ inputs.arch }}
TAG_NAME: ${{ inputs.tag }}
Expand Down
20 changes: 20 additions & 0 deletions backend/tauri/overrides/fixed-webview2.conf.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"$schema": "../../../node_modules/@tauri-apps/cli/config.schema.json",
"bundle": {
"windows": {
"webviewInstallMode": {
"type": "fixedRuntime",
"path": "SHOULD_BE_REPLACED_WITH_THE_PATH_TO_THE_FIXED_WEBVIEW"
}
}
},
"plugins": {
"updater": {
"endpoints": [
"https://mirror.ghproxy.com/https://github.com/LibNyanpasu/clash-nyanpasu/releases/download/updater/update-fixedwebview-proxy.json",
"https://gh-proxy.com/https://github.com/LibNyanpasu/clash-nyanpasu/releases/download/updater/update-fixedwebview-proxy.json",
"https://github.com/LibNyanpasu/clash-nyanpasu/releases/download/updater/update-fixedwebview.json"
]
}
}
}
3 changes: 3 additions & 0 deletions backend/tauri/src/core/tray/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ pub mod proxies;
pub use self::icon::on_scale_factor_changed;
use self::proxies::SystemTrayMenuProxiesExt;

#[cfg(target_os = "linux")]
use std::sync::atomic::AtomicU16;

struct TrayState<R: Runtime> {
menu: Mutex<Menu<R>>,
}
Expand Down
18 changes: 17 additions & 1 deletion scripts/portable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import AdmZip from "adm-zip";
import fs from "fs-extra";
import { context, getOctokit } from "@actions/github";
import packageJson from "../package.json";
import { TAURI_APP_DIR } from "./utils/env";
import { colorize, consola } from "./utils/logger";

const RUST_ARCH = process.env.RUST_ARCH || "x86_64";
const fixedWebview = process.argv.includes("--fixed-webview");

/// Script for ci
/// 打包绿色版/便携版 (only Windows)
Expand Down Expand Up @@ -39,11 +41,25 @@ async function resolvePortable() {
zip.addLocalFile(path.join(buildDir, "nyanpasu-service.exe"));
zip.addLocalFile(path.join(buildDir, "clash-rs.exe"));
zip.addLocalFolder(path.join(buildDir, "resources"), "resources");

if (fixedWebview) {
const webviewPath = (await fs.readdir(TAURI_APP_DIR)).find((file) =>
file.includes("WebView2"),
);
if (!webviewPath) {
throw new Error("WebView2 runtime not found");
}
zip.addLocalFolder(
path.join(TAURI_APP_DIR, webviewPath),
path.basename(webviewPath),
);
}

zip.addLocalFolder(configDir, ".config");

const { version } = packageJson;

const zipFile = `Clash.Nyanpasu_${version}_${RUST_ARCH}_portable.zip`;
const zipFile = `Clash.Nyanpasu_${version}_${RUST_ARCH}${fixedWebview ? "_fixedWebview2" : ""}_portable.zip`;
zip.writeZip(zipFile);

consola.success("create portable zip successfully");
Expand Down
23 changes: 21 additions & 2 deletions scripts/prepare-nightly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import { execSync } from "child_process";
import path from "node:path";
import fs from "fs-extra";
import { merge } from "lodash-es";
import { cwd, TAURI_APP_DIR } from "./utils/env";
import {
cwd,
TAURI_APP_DIR,
TAURI_FIXED_WEBVIEW2_CONFIG_OVERRIDE_PATH,
} from "./utils/env";
import { consola } from "./utils/logger";

const TAURI_DEV_APP_CONF_PATH = path.join(
Expand All @@ -24,15 +28,30 @@ const NYANPASU_PACKAGE_JSON_PATH = path.join(

const isNSIS = process.argv.includes("--nsis"); // only build nsis
const isMSI = process.argv.includes("--msi"); // only build msi
const fixedWebview = process.argv.includes("--fixed-webview");

async function main() {
consola.debug("Read config...");
const tauriAppConf = await fs.readJSON(TAURI_APP_CONF);
const tauriAppOverrides = await fs.readJSON(TAURI_DEV_APP_OVERRIDES_PATH);
const tauriConf = merge(tauriAppConf, tauriAppOverrides);
let tauriConf = merge(tauriAppConf, tauriAppOverrides);
const packageJson = await fs.readJSON(NYANPASU_PACKAGE_JSON_PATH);
const rootPackageJson = await fs.readJSON(ROOT_PACKAGE_JSON_PATH);
// const wxsFile = await fs.readFile(WXS_PATH, "utf-8");
if (fixedWebview) {
const fixedWebview2Config = await fs.readJSON(
TAURI_FIXED_WEBVIEW2_CONFIG_OVERRIDE_PATH,
);
const webviewPath = (await fs.readdir(TAURI_APP_DIR)).find((file) =>
file.includes("WebView2"),
);
if (!webviewPath) {
throw new Error("WebView2 runtime not found");
}
tauriConf = merge(tauriConf, fixedWebview2Config);
delete tauriConf.bundle.windows.webviewInstallMode.silent;
tauriConf.bundle.windows.webviewInstallMode.path = `./${path.basename(webviewPath)}`;
}

if (isNSIS) {
tauriConf.bundle.targets = ["nsis"];
Expand Down
25 changes: 23 additions & 2 deletions scripts/prepare-release.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import path from "node:path";
import fs from "fs-extra";
import { cwd, TAURI_APP_DIR } from "./utils/env";
import { merge } from "lodash-es";
import {
cwd,
TAURI_APP_DIR,
TAURI_FIXED_WEBVIEW2_CONFIG_OVERRIDE_PATH,
} from "./utils/env";
import { consola } from "./utils/logger";

const TAURI_APP_CONF = path.join(TAURI_APP_DIR, "tauri.conf.json");
Expand All @@ -14,19 +19,35 @@ const PACKAGE_JSON_PATH = path.join(cwd, "package.json");
// const WXS_PATH = path.join(TAURI_APP_DIR, "templates", "nightly.wxs");

const isNSIS = process.argv.includes("--nsis"); // only build nsis
const fixedWebview = process.argv.includes("--fixed-webview");

async function main() {
consola.debug("Read config...");
const tauriAppConf = await fs.readJSON(TAURI_APP_CONF);
// const tauriAppOverrides = await fs.readJSON(TAURI_DEV_APP_OVERRIDES_PATH);
// const tauriConf = merge(tauriAppConf, tauriAppOverrides);
const tauriConf = tauriAppConf;
let tauriConf = tauriAppConf;
// const wxsFile = await fs.readFile(WXS_PATH, "utf-8");

// if (isNSIS) {
// tauriConf.tauri.bundle.targets = ["nsis", "updater"];
// }

if (fixedWebview) {
const fixedWebview2Config = await fs.readJSON(
TAURI_FIXED_WEBVIEW2_CONFIG_OVERRIDE_PATH,
);
const webviewPath = (await fs.readdir(TAURI_APP_DIR)).find((file) =>
file.includes("WebView2"),
);
if (!webviewPath) {
throw new Error("WebView2 runtime not found");
}
tauriConf = merge(tauriConf, fixedWebview2Config);
delete tauriConf.bundle.windows.webviewInstallMode.silent;
tauriConf.bundle.windows.webviewInstallMode.path = `./${path.basename(webviewPath)}`;
}

consola.debug("Write tauri version to tauri.conf.json");
await fs.writeJSON(TAURI_APP_CONF, tauriConf, { spaces: 2 });
consola.debug("tauri.conf.json updated");
Expand Down
4 changes: 4 additions & 0 deletions scripts/utils/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import path from "path";

export const cwd = process.cwd();
export const TAURI_APP_DIR = path.join(cwd, "backend/tauri");
export const TAURI_FIXED_WEBVIEW2_CONFIG_OVERRIDE_PATH = path.join(
TAURI_APP_DIR,
"overrides/fixed-webview2.conf.json",
);
export const MANIFEST_DIR = path.join(cwd, "manifest");
export const GITHUB_PROXY = "https://mirror.ghproxy.com/";
export const GITHUB_TOKEN = process.env.GITHUB_TOKEN;
Expand Down

0 comments on commit 9822f78

Please sign in to comment.