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
  • Loading branch information
greenhat616 committed Sep 20, 2024
1 parent 28982cf commit 7f1878c
Show file tree
Hide file tree
Showing 6 changed files with 154 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-Archive -Path $outfile -DestinationPath './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: 2 additions & 1 deletion scripts/portable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import packageJson from "../package.json";
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 @@ -43,7 +44,7 @@ async function resolvePortable() {

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
25 changes: 23 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,32 @@ 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);
tauriConf.bundle.windows.webviewInstallMode.path = path.join(
"./",
path.basename(webviewPath),
);
}

if (isNSIS) {
tauriConf.bundle.targets = ["nsis"];
Expand Down
27 changes: 25 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,37 @@ 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);
tauriConf.bundle.windows.webviewInstallMode.path = path.join(
"./",
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 7f1878c

Please sign in to comment.