mirror of
https://github.com/MrPatben8/konduktor.git
synced 2026-11-27 18:22:53 +01:00
Implemented self-updating
This commit is contained in:
1 parent
422297d890
commit
0eac972173
12 files changed
+975
-39
No files matched your search
@@ -0,0 +1,69 @@
|
||||
"""Write the Tauri updater's latest.json for one release.
|
||||
|
||||
The app's update dialog finds the release itself (newest app tag on GitHub)
|
||||
and points the updater at THAT release's latest.json, so each release carries
|
||||
its own manifest describing its own assets. Run by build.yml's release job:
|
||||
|
||||
python3 .github/scripts/updater_manifest.py artifacts \\
|
||||
--version 0.6.0 --tag v0.6.0-b42 --repo owner/konduktor
|
||||
|
||||
Expects, anywhere under the folder, the macOS `*.app.tar.gz` and the Windows
|
||||
`*-setup.exe`, each with its `.sig` (written by `tauri build` when
|
||||
`bundle.createUpdaterArtifacts` is on). Fails if any is missing: a release
|
||||
whose manifest lacks a platform would be refused by the updater as a whole.
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import json
|
||||
import sys
|
||||
from datetime import datetime, timezone
|
||||
from pathlib import Path
|
||||
from urllib.parse import quote
|
||||
|
||||
# Tauri's platform keys -> the asset suffix that platform installs from.
|
||||
PLATFORMS = {
|
||||
"darwin-aarch64": ".app.tar.gz",
|
||||
"windows-x86_64": "-setup.exe",
|
||||
}
|
||||
|
||||
|
||||
def find_one(root: Path, suffix: str) -> Path:
|
||||
found = [p for p in root.rglob(f"*{suffix}") if p.is_file()]
|
||||
if len(found) != 1:
|
||||
sys.exit(f"expected exactly one *{suffix} under {root}, found {len(found)}")
|
||||
return found[0]
|
||||
|
||||
|
||||
def build(root: Path, version: str, tag: str, repo: str) -> dict:
|
||||
platforms = {}
|
||||
for key, suffix in PLATFORMS.items():
|
||||
asset = find_one(root, suffix)
|
||||
sig = asset.with_name(asset.name + ".sig")
|
||||
if not sig.is_file():
|
||||
sys.exit(f"missing signature {sig}")
|
||||
platforms[key] = {
|
||||
"signature": sig.read_text(encoding="utf-8").strip(),
|
||||
"url": f"https://github.com/{repo}/releases/download/{quote(tag)}/{quote(asset.name)}",
|
||||
}
|
||||
return {
|
||||
"version": version,
|
||||
"pub_date": datetime.now(timezone.utc).replace(microsecond=0).isoformat().replace("+00:00", "Z"),
|
||||
"platforms": platforms,
|
||||
}
|
||||
|
||||
|
||||
def main() -> None:
|
||||
ap = argparse.ArgumentParser(description=__doc__.splitlines()[0])
|
||||
ap.add_argument("artifacts", type=Path)
|
||||
ap.add_argument("--version", required=True)
|
||||
ap.add_argument("--tag", required=True)
|
||||
ap.add_argument("--repo", required=True)
|
||||
args = ap.parse_args()
|
||||
manifest = build(args.artifacts, args.version, args.tag, args.repo)
|
||||
out = args.artifacts / "latest.json"
|
||||
out.write_text(json.dumps(manifest, indent=2) + "\n", encoding="utf-8")
|
||||
print(f"wrote {out}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -86,20 +86,31 @@ jobs:
|
||||
working-directory: frontend
|
||||
run: npm ci
|
||||
|
||||
# createUpdaterArtifacts also signs the in-app update packages
|
||||
# (Konduktor.app.tar.gz / the NSIS setup.exe) with the updater key, whose
|
||||
# public half is plugins.updater.pubkey in tauri.conf.json. Losing the
|
||||
# private key means installed copies can never update themselves again.
|
||||
- name: Build Tauri app
|
||||
working-directory: frontend
|
||||
env:
|
||||
TAURI_SIGNING_PRIVATE_KEY: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY }}
|
||||
TAURI_SIGNING_PRIVATE_KEY_PASSWORD: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY_PASSWORD }}
|
||||
run: npx tauri build
|
||||
|
||||
# Stage the single installer per OS into a flat folder. Uploading one
|
||||
# directory (not multiple bundle subpaths) keeps the artifact root at
|
||||
# ./installer, so the zip holds the bare file — no nested dmg/ or nsis/
|
||||
# folder. We ship the DMG on macOS and the NSIS -setup.exe on Windows
|
||||
# (the .msi is intentionally left out).
|
||||
# (the .msi is intentionally left out), plus what the in-app updater
|
||||
# installs: the .app.tar.gz on macOS (the setup.exe on Windows) and the
|
||||
# .sig files the release job folds into latest.json.
|
||||
- name: Stage installer (macOS)
|
||||
if: runner.os == 'macOS'
|
||||
run: |
|
||||
mkdir -p installer
|
||||
cp frontend/src-tauri/target/release/bundle/dmg/*.dmg installer/
|
||||
cp frontend/src-tauri/target/release/bundle/macos/*.app.tar.gz installer/
|
||||
cp frontend/src-tauri/target/release/bundle/macos/*.app.tar.gz.sig installer/
|
||||
|
||||
- name: Stage installer (Windows)
|
||||
if: runner.os == 'Windows'
|
||||
@@ -107,6 +118,7 @@ jobs:
|
||||
run: |
|
||||
New-Item -ItemType Directory -Force installer | Out-Null
|
||||
Copy-Item frontend/src-tauri/target/release/bundle/nsis/*-setup.exe installer/
|
||||
Copy-Item frontend/src-tauri/target/release/bundle/nsis/*-setup.exe.sig installer/
|
||||
|
||||
- name: Upload installer
|
||||
uses: actions/upload-artifact@v4
|
||||
@@ -226,6 +238,16 @@ jobs:
|
||||
print("Using the PR's patch notes." if found else "No patch notes section; using generated notes.")
|
||||
EOF
|
||||
|
||||
# The in-app updater's manifest for THIS release (the app's update
|
||||
# dialog finds the release, then reads releases/download/<tag>/latest.json).
|
||||
# The .sig files are folded into it and not uploaded themselves.
|
||||
- name: Updater manifest
|
||||
run: |
|
||||
python3 .github/scripts/updater_manifest.py artifacts \
|
||||
--version "${{ steps.version.outputs.version }}" \
|
||||
--tag "v${{ steps.version.outputs.version }}-b${{ github.run_number }}" \
|
||||
--repo "${{ github.repository }}"
|
||||
|
||||
- name: Publish release
|
||||
uses: softprops/action-gh-release@v2
|
||||
with:
|
||||
@@ -235,4 +257,8 @@ jobs:
|
||||
body_path: ${{ steps.notes.outputs.found == 'true' && 'release-notes.md' || '' }}
|
||||
generate_release_notes: ${{ steps.notes.outputs.found != 'true' }}
|
||||
fail_on_unmatched_files: true
|
||||
files: artifacts/**/*
|
||||
files: |
|
||||
artifacts/**/*.dmg
|
||||
artifacts/**/*-setup.exe
|
||||
artifacts/**/*.app.tar.gz
|
||||
artifacts/latest.json
|
||||
+8
-3
@@ -88,9 +88,14 @@ cd ..
|
||||
|
||||
# 2) Build the app (its beforeBuildCommand runs the Vite build)
|
||||
cd frontend
|
||||
npx tauri build
|
||||
npx tauri build --config src-tauri/tauri.unsigned.conf.json
|
||||
```
|
||||
|
||||
The `--config` override skips the in-app updater packages, which are signed
|
||||
with the release key that only CI holds (`TAURI_SIGNING_PRIVATE_KEY`). With
|
||||
that key set in the environment, plain `npx tauri build` makes them too.
|
||||
`build.ps1` picks the right one by itself.
|
||||
|
||||
`build_sidecar.ps1` uses `backend\.venv\Scripts\python.exe` when it exists (else
|
||||
whatever `python` resolves to), so the venv doesn't need to be activated. It
|
||||
replaces the whole staged folder, so no file from an older build survives.
|
||||
@@ -117,8 +122,8 @@ folder (`tauri.windows.conf.json` → `bundle.resources`), where `lib.rs` spawns
|
||||
## Rebuilding after changes
|
||||
|
||||
If you changed **backend** Python, run `.\build.ps1` (or `build_sidecar.ps1`,
|
||||
then `npx tauri build`). Frontend-only changes just need
|
||||
`.\build.ps1 -SkipSidecar` (or `npx tauri build`).
|
||||
then `npx tauri build` as above). Frontend-only changes just need
|
||||
`.\build.ps1 -SkipSidecar`.
|
||||
|
||||
## Not part of this build: the stem engine
|
||||
|
||||
|
||||
@@ -1035,10 +1035,28 @@ Two independent apps that talk over HTTP:
|
||||
stem engine publishes `engine-v*` releases in the same repo — and,
|
||||
if its tag's **semver part** is newer than `__APP_VERSION__` — build-number
|
||||
`-b<N>` bumps don't count — shows an update dialog with the release's
|
||||
"What's Changed" bullets; Download opens the release page in the system
|
||||
browser via `@tauri-apps/plugin-shell` `open` — falls back to `window.open`
|
||||
outside Tauri; "Skip this version" persists `skippedUpdateVersion` to
|
||||
userprefs via `/api/prefs`; all failures are silent).
|
||||
"What's Changed" bullets; "Skip this version" persists
|
||||
`skippedUpdateVersion` to userprefs via `/api/prefs`; check failures are
|
||||
silent. **In the desktop app, Update installs it** (decided 2026-10-16,
|
||||
[the discussion](.claude/discussions/discuss-self-update-2026-10-16.md)):
|
||||
`update_download` (lib.rs, tauri-plugin-updater) reads THAT release's
|
||||
`latest.json`, downloads with progress in the dialog, verifies the
|
||||
signature and STAGES the package in app-cache; `update_restart` then
|
||||
quits through the ordinary quit request, so QuitGuard asks about unsaved
|
||||
edits. The package is installed in `exit_now`, only AFTER the sidecar is
|
||||
killed — on macOS the running backend lazily loads native libraries from
|
||||
inside the bundle being replaced, on Windows its `.exe` is locked (the
|
||||
shell waits until it can open it for writing) — then the app relaunches.
|
||||
Cancel in QuitGuard keeps it staged (`konduktor://update-deferred`) and the
|
||||
next ordinary quit installs it without relaunching. On macOS a bundle run
|
||||
from the DMG, translocated, or in a folder the user cannot write is
|
||||
refused BEFORE downloading (the updater's own admin-password fallback
|
||||
runs on the main thread, which the quit path may hold). Any failure shows
|
||||
its reason + "Open release page" (the old Download, still the button in a
|
||||
plain browser); an install that failed at exit is written to
|
||||
`failed.json` and reported by the next launch (`update_take_failure`).
|
||||
The updater's crate is built WITHOUT its `zip` feature — only for v1-style
|
||||
zipped Windows installers, and every zip 4.x is yanked.
|
||||
- **Stem playback** (decided 2026-09-30): a stem FILE always loads its four
|
||||
stems (`trackStemsFor` / `trackStemUrl` in `api.ts`) and the deck plays
|
||||
their SUM, as Traktor's stem deck does — the mix stream is never decoded,
|
||||
@@ -1771,7 +1789,16 @@ that number and nothing else — everything derives from it:
|
||||
- **CI release** — `.github/workflows/build.yml` reads it with
|
||||
`jq .version frontend/package.json` and tags each push
|
||||
`v<version>-b<run_number>` (release name `Konduktor v<version>-b<run_number>`).
|
||||
The `-b<N>` suffix keeps every push's tag/release unique.
|
||||
The `-b<N>` suffix keeps every push's tag/release unique. Each release also
|
||||
carries the in-app updater's `latest.json` (`.github/scripts/updater_manifest.py`:
|
||||
`version` = package.json's, `darwin-aarch64` → `Konduktor.app.tar.gz`,
|
||||
`windows-x86_64` → the NSIS `-setup.exe`, each with its signature inlined).
|
||||
`bundle.createUpdaterArtifacts` signs those with the updater key: the
|
||||
repo secrets `TAURI_SIGNING_PRIVATE_KEY` / `_PASSWORD`, public half in
|
||||
`tauri.conf.json` `plugins.updater.pubkey`. **Losing the private key means
|
||||
installed copies can never update themselves again** — it is backed up
|
||||
outside the repo. A local build without it passes
|
||||
`--config src-tauri/tauri.unsigned.conf.json` (`build.ps1` does so itself).
|
||||
- **NOT a source**: `src-tauri/Cargo.toml` `version` is inert Rust crate metadata
|
||||
(Tauri uses the config's `../package.json`); don't treat it as the app version.
|
||||
|
||||
|
||||
@@ -40,6 +40,12 @@ try {
|
||||
& (Join-Path $Root "backend\build_sidecar.ps1")
|
||||
}
|
||||
|
||||
# Updater packages are signed with the release key (CI's secret). Without
|
||||
# it, build the installers alone rather than fail at the signing step.
|
||||
if (-not $env:TAURI_SIGNING_PRIVATE_KEY) {
|
||||
$TauriArgs = @("--config", "src-tauri/tauri.unsigned.conf.json") + $TauriArgs
|
||||
}
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "==> 2/2 Building the app (tauri build $TauriArgs)"
|
||||
Set-Location (Join-Path $Root "frontend")
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "frontend",
|
||||
"private": true,
|
||||
"version": "0.2.9",
|
||||
"version": "0.3.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
|
||||
Generated
+412
-8
@@ -86,6 +86,7 @@ dependencies = [
|
||||
"tauri-build",
|
||||
"tauri-plugin-log",
|
||||
"tauri-plugin-shell",
|
||||
"tauri-plugin-updater",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
@@ -465,6 +466,16 @@ dependencies = [
|
||||
"version_check",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "core-foundation"
|
||||
version = "0.9.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f"
|
||||
dependencies = [
|
||||
"core-foundation-sys",
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "core-foundation"
|
||||
version = "0.10.1"
|
||||
@@ -488,7 +499,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "064badf302c3194842cf2c5d61f56cc88e54a759313879cdf03abdd27d0c3b97"
|
||||
dependencies = [
|
||||
"bitflags 2.13.0",
|
||||
"core-foundation",
|
||||
"core-foundation 0.10.1",
|
||||
"core-graphics-types",
|
||||
"foreign-types",
|
||||
"libc",
|
||||
@@ -501,7 +512,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3d44a101f213f6c4cdc1853d4b78aef6db6bdfa3468798cc1d9912f4735013eb"
|
||||
dependencies = [
|
||||
"bitflags 2.13.0",
|
||||
"core-foundation",
|
||||
"core-foundation 0.10.1",
|
||||
"libc",
|
||||
]
|
||||
|
||||
@@ -905,6 +916,16 @@ dependencies = [
|
||||
"rustc_version",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "filetime"
|
||||
version = "0.2.29"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5c287a33c7f0a620c38e641e7f60827713987b3c0f26e8ddc9462cc69cf75759"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "find-msvc-tools"
|
||||
version = "0.1.9"
|
||||
@@ -1439,6 +1460,21 @@ dependencies = [
|
||||
"want",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hyper-rustls"
|
||||
version = "0.27.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dfa8e654703247911e29c23fbeaa261834bd9bb74efba2f9acddc37bfb127f53"
|
||||
dependencies = [
|
||||
"http",
|
||||
"hyper",
|
||||
"hyper-util",
|
||||
"rustls",
|
||||
"tokio",
|
||||
"tokio-rustls",
|
||||
"tower-service",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hyper-util"
|
||||
version = "0.1.20"
|
||||
@@ -1457,9 +1493,11 @@ dependencies = [
|
||||
"percent-encoding",
|
||||
"pin-project-lite",
|
||||
"socket2",
|
||||
"system-configuration",
|
||||
"tokio",
|
||||
"tower-service",
|
||||
"tracing",
|
||||
"windows-registry",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1707,6 +1745,36 @@ dependencies = [
|
||||
"windows-sys 0.45.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "jni"
|
||||
version = "0.22.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5efd9a482cf3a427f00d6b35f14332adc7902ce91efb778580e180ff90fa3498"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"combine",
|
||||
"jni-macros",
|
||||
"jni-sys 0.4.1",
|
||||
"log",
|
||||
"simd_cesu8",
|
||||
"thiserror 2.0.18",
|
||||
"walkdir",
|
||||
"windows-link 0.2.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "jni-macros"
|
||||
version = "0.22.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a00109accc170f0bdb141fed3e393c565b6f5e072365c3bd58f5b062591560a3"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"rustc_version",
|
||||
"simd_cesu8",
|
||||
"syn 2.0.118",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "jni-sys"
|
||||
version = "0.3.1"
|
||||
@@ -1837,6 +1905,12 @@ dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "linux-raw-sys"
|
||||
version = "0.12.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "32a66949e030da00e8c7d4434b251670a91556f4144941d37452769c25d58a53"
|
||||
|
||||
[[package]]
|
||||
name = "litemap"
|
||||
version = "0.8.2"
|
||||
@@ -1893,6 +1967,12 @@ version = "0.3.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a"
|
||||
|
||||
[[package]]
|
||||
name = "minisign-verify"
|
||||
version = "0.2.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "22f9645cb765ea72b8111f36c522475d2daa0d22c957a9826437e97534bc4e9e"
|
||||
|
||||
[[package]]
|
||||
name = "miniz_oxide"
|
||||
version = "0.8.9"
|
||||
@@ -2134,6 +2214,7 @@ checksum = "e3e0adef53c21f888deb4fa59fc59f7eb17404926ee8a6f59f5df0fd7f9f3272"
|
||||
dependencies = [
|
||||
"bitflags 2.13.0",
|
||||
"block2",
|
||||
"libc",
|
||||
"objc2",
|
||||
"objc2-core-foundation",
|
||||
]
|
||||
@@ -2149,6 +2230,18 @@ dependencies = [
|
||||
"objc2-core-foundation",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "objc2-osa-kit"
|
||||
version = "0.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f112d1746737b0da274ef79a23aac283376f335f4095a083a267a082f21db0c0"
|
||||
dependencies = [
|
||||
"bitflags 2.13.0",
|
||||
"objc2",
|
||||
"objc2-app-kit",
|
||||
"objc2-foundation",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "objc2-quartz-core"
|
||||
version = "0.3.2"
|
||||
@@ -2223,6 +2316,12 @@ dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "openssl-probe"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7c87def4c32ab89d880effc9e097653c8da5d6ef28e6b539d313baaacfbafcbe"
|
||||
|
||||
[[package]]
|
||||
name = "option-ext"
|
||||
version = "0.2.0"
|
||||
@@ -2239,6 +2338,20 @@ dependencies = [
|
||||
"windows-sys 0.61.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "osakit"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "732c71caeaa72c065bb69d7ea08717bd3f4863a4f451402fc9513e29dbd5261b"
|
||||
dependencies = [
|
||||
"objc2",
|
||||
"objc2-foundation",
|
||||
"objc2-osa-kit",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"thiserror 2.0.18",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pango"
|
||||
version = "0.18.3"
|
||||
@@ -2673,15 +2786,20 @@ dependencies = [
|
||||
"http-body",
|
||||
"http-body-util",
|
||||
"hyper",
|
||||
"hyper-rustls",
|
||||
"hyper-util",
|
||||
"js-sys",
|
||||
"log",
|
||||
"percent-encoding",
|
||||
"pin-project-lite",
|
||||
"rustls",
|
||||
"rustls-pki-types",
|
||||
"rustls-platform-verifier",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"sync_wrapper",
|
||||
"tokio",
|
||||
"tokio-rustls",
|
||||
"tokio-util",
|
||||
"tower",
|
||||
"tower-http",
|
||||
@@ -2693,6 +2811,20 @@ dependencies = [
|
||||
"web-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ring"
|
||||
version = "0.17.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a4689e6c2294d81e88dc6261c768b63bc4fcdb852be6d1352498b114f61383b7"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"cfg-if",
|
||||
"getrandom 0.2.17",
|
||||
"libc",
|
||||
"untrusted",
|
||||
"windows-sys 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rkyv"
|
||||
version = "0.7.46"
|
||||
@@ -2754,6 +2886,92 @@ dependencies = [
|
||||
"semver",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustix"
|
||||
version = "1.1.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "891efababe418670775f199f0d233d84843c227a0949a883ce15b37c78d6629d"
|
||||
dependencies = [
|
||||
"bitflags 2.13.0",
|
||||
"errno",
|
||||
"libc",
|
||||
"linux-raw-sys",
|
||||
"windows-sys 0.61.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustls"
|
||||
version = "0.23.46"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "48e13bd8c0e9365c43cfa5c9e8f9ad49d3c8444926c9aac819e0e4dc503c8fdf"
|
||||
dependencies = [
|
||||
"once_cell",
|
||||
"ring",
|
||||
"rustls-pki-types",
|
||||
"rustls-webpki",
|
||||
"subtle",
|
||||
"zeroize",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustls-native-certs"
|
||||
version = "0.8.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4a073f5dc7469f984c52ad2752b63b0807745133b6de880b7b64c1ac4c48aec4"
|
||||
dependencies = [
|
||||
"openssl-probe",
|
||||
"rustls-pki-types",
|
||||
"schannel",
|
||||
"security-framework",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustls-pki-types"
|
||||
version = "1.15.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2f4925028c7eb5d1fcdaf196971378ed9d2c1c4efc7dc5d011256f76c99c0a96"
|
||||
dependencies = [
|
||||
"zeroize",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustls-platform-verifier"
|
||||
version = "0.7.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1167586491e2b18b8bfbb293e8180ec17c201c4f076d7cb3070ca964e7598f98"
|
||||
dependencies = [
|
||||
"core-foundation 0.10.1",
|
||||
"core-foundation-sys",
|
||||
"jni 0.22.4",
|
||||
"log",
|
||||
"once_cell",
|
||||
"rustls",
|
||||
"rustls-native-certs",
|
||||
"rustls-platform-verifier-android",
|
||||
"rustls-webpki",
|
||||
"security-framework",
|
||||
"security-framework-sys",
|
||||
"webpki-root-certs",
|
||||
"windows-sys 0.61.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustls-platform-verifier-android"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "eec689c0bc40ff2458a5977b6619cb718087084a18e02a131c599b62d05e1a5f"
|
||||
|
||||
[[package]]
|
||||
name = "rustls-webpki"
|
||||
version = "0.103.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f3c3cf1d8b1e7d4927e2d154c3fcb02979afb9939629c62cd9048d4f07b60ac2"
|
||||
dependencies = [
|
||||
"ring",
|
||||
"rustls-pki-types",
|
||||
"untrusted",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustversion"
|
||||
version = "1.0.22"
|
||||
@@ -2769,6 +2987,15 @@ dependencies = [
|
||||
"winapi-util",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "schannel"
|
||||
version = "0.1.29"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "91c1b7e4904c873ef0710c1f407dde2e6287de2bebc1bbbf7d430bb7cbffd939"
|
||||
dependencies = [
|
||||
"windows-sys 0.61.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "schemars"
|
||||
version = "0.8.22"
|
||||
@@ -2832,6 +3059,29 @@ version = "4.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1c107b6f4780854c8b126e228ea8869f4d7b71260f962fefb57b996b8959ba6b"
|
||||
|
||||
[[package]]
|
||||
name = "security-framework"
|
||||
version = "3.7.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b7f4bc775c73d9a02cde8bf7b2ec4c9d12743edf609006c7facc23998404cd1d"
|
||||
dependencies = [
|
||||
"bitflags 2.13.0",
|
||||
"core-foundation 0.10.1",
|
||||
"core-foundation-sys",
|
||||
"libc",
|
||||
"security-framework-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "security-framework-sys"
|
||||
version = "2.17.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6ce2691df843ecc5d231c0b14ece2acc3efb62c0a398c7e1d875f3983ce020e3"
|
||||
dependencies = [
|
||||
"core-foundation-sys",
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "selectors"
|
||||
version = "0.36.1"
|
||||
@@ -3084,6 +3334,16 @@ version = "0.3.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "703d5c7ef118737c72f1af64ad2f6f8c5e1921f818cdcb97b8fe6fc69bf66214"
|
||||
|
||||
[[package]]
|
||||
name = "simd_cesu8"
|
||||
version = "1.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "11031e251abf8611c80f460e19dbdeb54a66db918e49c65a7065b46ac7aec520"
|
||||
dependencies = [
|
||||
"rustc_version",
|
||||
"simdutf8",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "simdutf8"
|
||||
version = "0.1.5"
|
||||
@@ -3202,6 +3462,12 @@ version = "0.11.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
|
||||
|
||||
[[package]]
|
||||
name = "subtle"
|
||||
version = "2.6.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292"
|
||||
|
||||
[[package]]
|
||||
name = "swift-rs"
|
||||
version = "1.0.7"
|
||||
@@ -3255,6 +3521,27 @@ dependencies = [
|
||||
"syn 2.0.118",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "system-configuration"
|
||||
version = "0.7.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a13f3d0daba03132c0aa9767f98351b3488edc2c100cda2d2ec2b04f3d8d3c8b"
|
||||
dependencies = [
|
||||
"bitflags 2.13.0",
|
||||
"core-foundation 0.9.4",
|
||||
"system-configuration-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "system-configuration-sys"
|
||||
version = "0.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4"
|
||||
dependencies = [
|
||||
"core-foundation-sys",
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "system-deps"
|
||||
version = "6.2.2"
|
||||
@@ -3276,7 +3563,7 @@ checksum = "d1c93047acf68669466a34690ac58cca7010bd1b201e1ec86f1fd0a75d3dd4a9"
|
||||
dependencies = [
|
||||
"bitflags 2.13.0",
|
||||
"block2",
|
||||
"core-foundation",
|
||||
"core-foundation 0.10.1",
|
||||
"core-graphics",
|
||||
"crossbeam-channel",
|
||||
"dbus",
|
||||
@@ -3286,7 +3573,7 @@ dependencies = [
|
||||
"gdkwayland-sys",
|
||||
"gdkx11-sys",
|
||||
"gtk",
|
||||
"jni",
|
||||
"jni 0.21.1",
|
||||
"libc",
|
||||
"log",
|
||||
"ndk",
|
||||
@@ -3325,6 +3612,17 @@ version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369"
|
||||
|
||||
[[package]]
|
||||
name = "tar"
|
||||
version = "0.4.46"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3f6221d9a6003c78398e3b239969f352578258df48c8eb051caadae0015bc840"
|
||||
dependencies = [
|
||||
"filetime",
|
||||
"libc",
|
||||
"xattr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "target-lexicon"
|
||||
version = "0.12.16"
|
||||
@@ -3348,7 +3646,7 @@ dependencies = [
|
||||
"gtk",
|
||||
"heck 0.5.0",
|
||||
"http",
|
||||
"jni",
|
||||
"jni 0.21.1",
|
||||
"libc",
|
||||
"log",
|
||||
"mime",
|
||||
@@ -3503,6 +3801,38 @@ dependencies = [
|
||||
"tokio",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tauri-plugin-updater"
|
||||
version = "2.12.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7a5cad8ed5948d988e1018ecd31e27cacedbf72ce3fb972940c3e4bf51639e4b"
|
||||
dependencies = [
|
||||
"base64 0.22.1",
|
||||
"dirs",
|
||||
"flate2",
|
||||
"futures-util",
|
||||
"http",
|
||||
"infer",
|
||||
"log",
|
||||
"minisign-verify",
|
||||
"osakit",
|
||||
"percent-encoding",
|
||||
"reqwest",
|
||||
"rustls",
|
||||
"semver",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"tar",
|
||||
"tauri",
|
||||
"tauri-plugin",
|
||||
"tempfile",
|
||||
"thiserror 2.0.18",
|
||||
"time",
|
||||
"tokio",
|
||||
"url",
|
||||
"windows-sys 0.60.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tauri-runtime"
|
||||
version = "2.11.3"
|
||||
@@ -3513,7 +3843,7 @@ dependencies = [
|
||||
"dpi",
|
||||
"gtk",
|
||||
"http",
|
||||
"jni",
|
||||
"jni 0.21.1",
|
||||
"objc2",
|
||||
"objc2-ui-kit",
|
||||
"objc2-web-kit",
|
||||
@@ -3536,7 +3866,7 @@ checksum = "4e6fac707727b7a2f48e4ded90976324267371073edbb415ffb73bb0458d203f"
|
||||
dependencies = [
|
||||
"gtk",
|
||||
"http",
|
||||
"jni",
|
||||
"jni 0.21.1",
|
||||
"log",
|
||||
"objc2",
|
||||
"objc2-app-kit",
|
||||
@@ -3603,6 +3933,19 @@ dependencies = [
|
||||
"toml 1.1.2+spec-1.1.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tempfile"
|
||||
version = "3.27.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "32497e9a4c7b38532efcdebeef879707aa9f794296a4f0244f6f69e9bc8574bd"
|
||||
dependencies = [
|
||||
"fastrand",
|
||||
"getrandom 0.4.3",
|
||||
"once_cell",
|
||||
"rustix",
|
||||
"windows-sys 0.61.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tendril"
|
||||
version = "0.5.0"
|
||||
@@ -3724,6 +4067,16 @@ dependencies = [
|
||||
"windows-sys 0.61.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tokio-rustls"
|
||||
version = "0.26.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c9cc2678c2cdd569ef8215e2afd7954ada2ae20b4fdd2c5fe6139a3b02d105db"
|
||||
dependencies = [
|
||||
"rustls",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tokio-util"
|
||||
version = "0.7.18"
|
||||
@@ -4014,6 +4367,12 @@ version = "1.13.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c6f5d3c3b1bf09027a88a6bc961fc00497d651009560b5463668dc81b0fa87a8"
|
||||
|
||||
[[package]]
|
||||
name = "untrusted"
|
||||
version = "0.9.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1"
|
||||
|
||||
[[package]]
|
||||
name = "url"
|
||||
version = "2.5.8"
|
||||
@@ -4275,6 +4634,15 @@ dependencies = [
|
||||
"system-deps",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "webpki-root-certs"
|
||||
version = "1.0.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b96554aa2acc8ccdb7e1c9a58a7a68dd5d13bccc69cd124cb09406db612a1c9b"
|
||||
dependencies = [
|
||||
"rustls-pki-types",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "webview2-com"
|
||||
version = "0.38.2"
|
||||
@@ -4460,6 +4828,17 @@ dependencies = [
|
||||
"windows-link 0.1.3",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-registry"
|
||||
version = "0.6.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "02752bf7fbdcce7f2a27a742f798510f3e5ad88dbe84871e5168e2120c3d5720"
|
||||
dependencies = [
|
||||
"windows-link 0.2.1",
|
||||
"windows-result 0.4.1",
|
||||
"windows-strings 0.5.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-result"
|
||||
version = "0.3.4"
|
||||
@@ -4505,6 +4884,15 @@ dependencies = [
|
||||
"windows-targets 0.42.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-sys"
|
||||
version = "0.52.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d"
|
||||
dependencies = [
|
||||
"windows-targets 0.52.6",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-sys"
|
||||
version = "0.59.0"
|
||||
@@ -4800,7 +5188,7 @@ dependencies = [
|
||||
"gtk",
|
||||
"http",
|
||||
"javascriptcore-rs",
|
||||
"jni",
|
||||
"jni 0.21.1",
|
||||
"libc",
|
||||
"ndk",
|
||||
"objc2",
|
||||
@@ -4856,6 +5244,16 @@ dependencies = [
|
||||
"pkg-config",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "xattr"
|
||||
version = "1.6.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "32e45ad4206f6d2479085147f02bc2ef834ac85886624a23575ae137c8aa8156"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"rustix",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "yoke"
|
||||
version = "0.8.3"
|
||||
@@ -4920,6 +5318,12 @@ dependencies = [
|
||||
"synstructure",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zeroize"
|
||||
version = "1.9.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e13084392c5e4bc371903e2935a5eaeed24905a7511356b883835e18a78f6879"
|
||||
|
||||
[[package]]
|
||||
name = "zerotrie"
|
||||
version = "0.2.4"
|
||||
|
||||
@@ -28,3 +28,7 @@ tauri = { version = "2.11.3", features = [] }
|
||||
tauri-plugin-log = "2"
|
||||
tauri-plugin-shell = "2" # spawn the Python backend sidecar
|
||||
tokio = { version = "1", features = ["time"] } # timeout on the port handshake
|
||||
# One-click update (UpdateDialog.tsx). No `zip` feature: it only unpacks
|
||||
# v1-style zipped Windows installers (we ship the bare NSIS setup.exe), and
|
||||
# every zip 4.x it would need is yanked.
|
||||
tauri-plugin-updater = { version = "2.12", default-features = false, features = ["rustls-tls", "system-proxy"] }
|
||||
+236
-12
@@ -26,16 +26,30 @@
|
||||
// it — so it is killed only once the app really exits. If the webview does not
|
||||
// acknowledge within ~2 s (hung, or not loaded yet), the app quits anyway: a
|
||||
// broken page must never make the app unquittable.
|
||||
//
|
||||
// UPDATING rides on that same handshake (UpdateDialog.tsx). The page finds the
|
||||
// release (its own GitHub check); `update_download` fetches THAT release's
|
||||
// `latest.json`, downloads + verifies the package with tauri-plugin-updater and
|
||||
// STAGES it on disk; `update_restart` then asks to quit like Cmd+Q does. The
|
||||
// package is installed only in `exit_now`, after the sidecar is dead: on macOS
|
||||
// the sidecar lazily loads native libraries from inside the bundle being
|
||||
// replaced, and on Windows its .exe in the install folder is locked while it
|
||||
// runs. Cancel in the Save / Discard prompt keeps the update staged, so the
|
||||
// next ordinary quit installs it (without relaunching). A failed install is
|
||||
// written to `failed.json` for the next launch's dialog to report.
|
||||
use std::collections::VecDeque;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::atomic::{AtomicBool, AtomicU64, Ordering};
|
||||
use std::sync::Mutex;
|
||||
use std::time::Duration;
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
use serde::Serialize;
|
||||
use tauri::ipc::Channel;
|
||||
use tauri::window::Color;
|
||||
use tauri::{AppHandle, Emitter, Manager, RunEvent, WebviewUrl, WebviewWindowBuilder, WindowEvent};
|
||||
use tauri_plugin_shell::process::{CommandChild, CommandEvent};
|
||||
use tauri_plugin_shell::ShellExt;
|
||||
use tauri_plugin_updater::{Update, UpdaterExt};
|
||||
|
||||
/// Holds the running sidecar child so we can terminate it on exit.
|
||||
struct Sidecar(Mutex<Option<CommandChild>>);
|
||||
@@ -67,15 +81,105 @@ struct Quit {
|
||||
acked: AtomicBool,
|
||||
}
|
||||
|
||||
/// A downloaded, verified update waiting for the app to exit.
|
||||
struct StagedUpdate {
|
||||
update: Update,
|
||||
/// The package on disk (~150 MB: not worth holding in memory all session).
|
||||
path: PathBuf,
|
||||
/// Relaunch once installed: set by `update_restart`, cleared by Cancel.
|
||||
relaunch: bool,
|
||||
}
|
||||
|
||||
struct Staged(Mutex<Option<StagedUpdate>>);
|
||||
|
||||
/// Download progress for the update dialog.
|
||||
#[derive(Clone, Serialize)]
|
||||
struct UpdateProgress {
|
||||
downloaded: u64,
|
||||
total: Option<u64>,
|
||||
}
|
||||
|
||||
/// An install that failed at exit, reported by the next launch.
|
||||
#[derive(Serialize, serde::Deserialize)]
|
||||
struct UpdateFailure {
|
||||
version: String,
|
||||
error: String,
|
||||
}
|
||||
|
||||
const REPO: &str = "MrPatben8/konduktor";
|
||||
|
||||
/// The frozen backend's executable, in the bundled `sidecar/` folder (staged
|
||||
/// into src-tauri/binaries/ by backend/build_sidecar.*).
|
||||
fn sidecar_exe(app: &AppHandle) -> Result<PathBuf, String> {
|
||||
let exe = if cfg!(windows) { "konduktor-sidecar.exe" } else { "konduktor-sidecar" };
|
||||
let dir = app.path().resource_dir().map_err(|e| e.to_string())?;
|
||||
Ok(dir.join("sidecar").join(exe))
|
||||
}
|
||||
|
||||
fn kill_sidecar(app: &AppHandle) {
|
||||
if let Some(child) = app.state::<Sidecar>().0.lock().unwrap().take() {
|
||||
let _ = child.kill();
|
||||
}
|
||||
}
|
||||
|
||||
/// Windows only: `kill` asks the OS to end the process and returns at once,
|
||||
/// and the installer must not find the sidecar's .exe still locked. Opening a
|
||||
/// running executable for writing is refused, so poll that (up to ~5 s).
|
||||
fn wait_for_sidecar_exit(app: &AppHandle) {
|
||||
if !cfg!(windows) {
|
||||
return;
|
||||
}
|
||||
let Ok(exe) = sidecar_exe(app) else { return };
|
||||
let deadline = Instant::now() + Duration::from_secs(5);
|
||||
while Instant::now() < deadline {
|
||||
if std::fs::OpenOptions::new().write(true).open(&exe).is_ok() {
|
||||
return;
|
||||
}
|
||||
std::thread::sleep(Duration::from_millis(100));
|
||||
}
|
||||
}
|
||||
|
||||
fn update_dir(app: &AppHandle) -> Option<PathBuf> {
|
||||
app.path().app_cache_dir().ok().map(|dir| dir.join("update"))
|
||||
}
|
||||
|
||||
/// Install a staged update, if any. Runs at exit with the sidecar already dead.
|
||||
/// On Windows a successful install never returns (the updater starts the
|
||||
/// installer and exits the process); on macOS the new bundle is in place and
|
||||
/// a requested relaunch starts it.
|
||||
fn install_staged(app: &AppHandle) {
|
||||
let Some(staged) = app.state::<Staged>().0.lock().unwrap().take() else { return };
|
||||
let StagedUpdate { update, path, relaunch } = staged;
|
||||
let version = update.version.clone();
|
||||
wait_for_sidecar_exit(app);
|
||||
// Not re-verified: `download` checked the signature before staging, and
|
||||
// whoever could alter the app's cache folder could alter the app itself.
|
||||
let result = std::fs::read(&path).map_err(|e| e.to_string()).and_then(|bytes| {
|
||||
update.restart_after_install(relaunch).install(bytes).map_err(|e| e.to_string())
|
||||
});
|
||||
let _ = std::fs::remove_file(&path);
|
||||
match result {
|
||||
Ok(()) if relaunch => app.restart(),
|
||||
Ok(()) => {}
|
||||
Err(error) => {
|
||||
log::error!("update to {version} failed to install: {error}");
|
||||
if let Some(dir) = update_dir(app) {
|
||||
let failure = UpdateFailure { version, error };
|
||||
if let Ok(json) = serde_json::to_vec(&failure) {
|
||||
let _ = std::fs::write(dir.join("failed.json"), json);
|
||||
}
|
||||
}
|
||||
if relaunch {
|
||||
app.restart(); // back into the version that is still installed
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn exit_now(app: &AppHandle) {
|
||||
app.state::<Quit>().allowed.store(true, Ordering::SeqCst);
|
||||
kill_sidecar(app);
|
||||
install_staged(app);
|
||||
app.exit(0);
|
||||
}
|
||||
|
||||
@@ -121,15 +225,7 @@ fn start_backend(app: &AppHandle) {
|
||||
let gen = app.state::<Backend>().generation.fetch_add(1, Ordering::SeqCst) + 1;
|
||||
set_status(app, gen, BackendStatus::Starting);
|
||||
|
||||
// The frozen backend lives in the bundled `sidecar/` folder (staged into
|
||||
// src-tauri/binaries/ by backend/build_sidecar.*).
|
||||
let exe = if cfg!(windows) { "konduktor-sidecar.exe" } else { "konduktor-sidecar" };
|
||||
let spawned = app
|
||||
.path()
|
||||
.resource_dir()
|
||||
.map_err(|e| e.to_string())
|
||||
.and_then(|dir| {
|
||||
let program = dir.join("sidecar").join(exe);
|
||||
let spawned = sidecar_exe(app).and_then(|program| {
|
||||
app.shell()
|
||||
.command(&program)
|
||||
.spawn()
|
||||
@@ -220,10 +316,15 @@ fn quit_ack(app: AppHandle) {
|
||||
app.state::<Quit>().acked.store(true, Ordering::SeqCst);
|
||||
}
|
||||
|
||||
/// The user chose Cancel: forget the request.
|
||||
/// The user chose Cancel: forget the request. A staged update stays staged
|
||||
/// but no longer relaunches; the next ordinary quit installs it.
|
||||
#[tauri::command]
|
||||
fn quit_cancel(app: AppHandle) {
|
||||
app.state::<Quit>().acked.store(false, Ordering::SeqCst);
|
||||
if let Some(staged) = app.state::<Staged>().0.lock().unwrap().as_mut() {
|
||||
staged.relaunch = false;
|
||||
let _ = app.emit("konduktor://update-deferred", ());
|
||||
}
|
||||
}
|
||||
|
||||
/// Quit for real (nothing unsaved, or Save / Discard has finished).
|
||||
@@ -232,11 +333,130 @@ fn quit_now(app: AppHandle) {
|
||||
exit_now(&app);
|
||||
}
|
||||
|
||||
/// Refuse up front what the macOS install could not do: replace a bundle on
|
||||
/// a read-only volume (run from the DMG), a translocated copy, or a folder this
|
||||
/// user cannot write. (The updater's own fallback for the last asks for an
|
||||
/// admin password from the main thread, which the quit path may be blocking.)
|
||||
#[cfg(target_os = "macos")]
|
||||
fn check_installable() -> Result<(), String> {
|
||||
const MOVE_IT: &str = "Move Konduktor to your Applications folder, open it from there, then try again.";
|
||||
let exe = std::env::current_exe().map_err(|e| e.to_string())?;
|
||||
let bundle = tauri_plugin_updater::extract_path_from_executable(&exe).map_err(|e| e.to_string())?;
|
||||
if bundle.to_string_lossy().contains("/AppTranslocation/") {
|
||||
return Err(MOVE_IT.into());
|
||||
}
|
||||
let parent = bundle.parent().ok_or_else(|| MOVE_IT.to_string())?;
|
||||
let probe = parent.join(format!(".konduktor-update-check-{}", std::process::id()));
|
||||
match std::fs::File::create(&probe) {
|
||||
Ok(_) => {
|
||||
let _ = std::fs::remove_file(&probe);
|
||||
Ok(())
|
||||
}
|
||||
Err(_) => Err(MOVE_IT.into()),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
fn check_installable() -> Result<(), String> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Download the update published with release `tag`, verify it and stage it
|
||||
/// for installation at exit. Returns the version staged.
|
||||
#[tauri::command]
|
||||
async fn update_download(
|
||||
app: AppHandle,
|
||||
tag: String,
|
||||
on_progress: Channel<UpdateProgress>,
|
||||
) -> Result<String, String> {
|
||||
check_installable()?;
|
||||
let manifest = format!("https://github.com/{REPO}/releases/download/{tag}/latest.json");
|
||||
let url = manifest.parse().map_err(|e| format!("{manifest}: {e}"))?;
|
||||
let update = app
|
||||
.updater_builder()
|
||||
.endpoints(vec![url])
|
||||
.and_then(|b| b.build())
|
||||
.map_err(|e| e.to_string())?
|
||||
.check()
|
||||
.await
|
||||
.map_err(|e| e.to_string())?
|
||||
.ok_or_else(|| format!("{tag} is not newer than this version."))?;
|
||||
|
||||
let mut downloaded = 0u64;
|
||||
let mut last_sent = Instant::now();
|
||||
let bytes = update
|
||||
.download(
|
||||
|chunk, total| {
|
||||
downloaded += chunk as u64;
|
||||
// Chunks arrive every few KB: a few updates a second is plenty.
|
||||
if last_sent.elapsed() >= Duration::from_millis(100) {
|
||||
last_sent = Instant::now();
|
||||
let _ = on_progress.send(UpdateProgress { downloaded, total });
|
||||
}
|
||||
},
|
||||
|| {},
|
||||
)
|
||||
.await
|
||||
.map_err(|e| e.to_string())?;
|
||||
|
||||
let dir = update_dir(&app).ok_or("No cache folder to download into.")?;
|
||||
std::fs::create_dir_all(&dir).map_err(|e| e.to_string())?;
|
||||
let path = dir.join(format!("{}.pkg", update.version));
|
||||
std::fs::write(&path, &bytes).map_err(|e| e.to_string())?;
|
||||
drop(bytes);
|
||||
|
||||
let version = update.version.clone();
|
||||
let previous = app
|
||||
.state::<Staged>()
|
||||
.0
|
||||
.lock()
|
||||
.unwrap()
|
||||
.replace(StagedUpdate { update, path: path.clone(), relaunch: false });
|
||||
if let Some(old) = previous.filter(|old| old.path != path) {
|
||||
let _ = std::fs::remove_file(old.path);
|
||||
}
|
||||
Ok(version)
|
||||
}
|
||||
|
||||
/// Quit, install the staged update and relaunch. Goes through the ordinary
|
||||
/// quit request, so unsaved changes are asked about first.
|
||||
#[tauri::command]
|
||||
fn update_restart(app: AppHandle) -> Result<(), String> {
|
||||
match app.state::<Staged>().0.lock().unwrap().as_mut() {
|
||||
Some(staged) => staged.relaunch = true,
|
||||
None => return Err("No update has been downloaded.".into()),
|
||||
}
|
||||
request_quit(&app);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// The last update's install failure, if any — reported once.
|
||||
#[tauri::command]
|
||||
fn update_take_failure(app: AppHandle) -> Option<UpdateFailure> {
|
||||
let path = update_dir(&app)?.join("failed.json");
|
||||
let bytes = std::fs::read(&path).ok()?;
|
||||
let _ = std::fs::remove_file(&path);
|
||||
serde_json::from_slice(&bytes).ok()
|
||||
}
|
||||
|
||||
/// Packages left by a run that never exited normally (crash, force quit).
|
||||
fn clear_stale_updates(app: &AppHandle) {
|
||||
let Some(dir) = update_dir(app) else { return };
|
||||
let Ok(entries) = std::fs::read_dir(dir) else { return };
|
||||
for entry in entries.flatten() {
|
||||
if entry.path().extension().is_some_and(|ext| ext == "pkg") {
|
||||
let _ = std::fs::remove_file(entry.path());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||
pub fn run() {
|
||||
tauri::Builder::default()
|
||||
.plugin(tauri_plugin_shell::init())
|
||||
.plugin(tauri_plugin_updater::Builder::new().build())
|
||||
.manage(Sidecar(Mutex::new(None)))
|
||||
.manage(Staged(Mutex::new(None)))
|
||||
.manage(Backend { status: Mutex::new(BackendStatus::Starting), generation: AtomicU64::new(0) })
|
||||
.manage(Quit { allowed: AtomicBool::new(false), acked: AtomicBool::new(false) })
|
||||
.invoke_handler(tauri::generate_handler![
|
||||
@@ -244,7 +464,10 @@ pub fn run() {
|
||||
backend_restart,
|
||||
quit_ack,
|
||||
quit_cancel,
|
||||
quit_now
|
||||
quit_now,
|
||||
update_download,
|
||||
update_restart,
|
||||
update_take_failure
|
||||
])
|
||||
.on_window_event(|window, event| {
|
||||
if let WindowEvent::CloseRequested { api, .. } = event {
|
||||
@@ -264,6 +487,7 @@ pub fn run() {
|
||||
)?;
|
||||
}
|
||||
|
||||
clear_stale_updates(app.handle());
|
||||
start_backend(app.handle());
|
||||
|
||||
WebviewWindowBuilder::new(app, "main", WebviewUrl::App("index.html".into()))
|
||||
|
||||
@@ -16,9 +16,16 @@
|
||||
"csp": null
|
||||
}
|
||||
},
|
||||
"plugins": {
|
||||
"updater": {
|
||||
"pubkey": "dW50cnVzdGVkIGNvbW1lbnQ6IG1pbmlzaWduIHB1YmxpYyBrZXk6IEZBMUE5MkIyNkJFNDNENjMKUldSalBlUnJzcElhK2dpbSsyT0kzL1huSkpOOCsxaVcwN3h6TFk3V1ZHTm9uUWtJRTAwQnQrVE0K",
|
||||
"windows": { "installMode": "passive" }
|
||||
}
|
||||
},
|
||||
"bundle": {
|
||||
"active": true,
|
||||
"targets": "all",
|
||||
"createUpdaterArtifacts": true,
|
||||
"icon": [
|
||||
"icons/32x32.png",
|
||||
"icons/128x128.png",
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"$schema": "../node_modules/@tauri-apps/cli/config.schema.json",
|
||||
"bundle": { "createUpdaterArtifacts": false }
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import { createPortal } from 'react-dom'
|
||||
import { useState } from 'react'
|
||||
import { useEffect, useState } from 'react'
|
||||
import { useQuery, useQueryClient } from '@tanstack/react-query'
|
||||
import { api } from '../api'
|
||||
|
||||
@@ -12,8 +12,20 @@ import { api } from '../api'
|
||||
* Failures are silent: an update check must never nag about itself.
|
||||
* "Skip this version" persists `skippedUpdateVersion` to userprefs.json via
|
||||
* the prefs API, keyed by the semver part, so a later version re-triggers.
|
||||
*
|
||||
* In the desktop app, Update installs it (decided 2026-10-16,
|
||||
* .claude/discussions/discuss-self-update-2026-10-16.md): the shell
|
||||
* (src-tauri/src/lib.rs) downloads THIS release's `latest.json` package with
|
||||
* progress, verifies and stages it, then quits through the ordinary quit
|
||||
* request — so unsaved edits are asked about by QuitGuard — and installs at
|
||||
* exit, after the backend is dead, and relaunches. Cancel in that prompt
|
||||
* leaves it staged for the next quit. A failure says why and offers the
|
||||
* release page (what Download did before); an install that failed at exit is
|
||||
* reported by the next launch. A plain browser keeps Download.
|
||||
*/
|
||||
|
||||
const IN_TAURI = '__TAURI_INTERNALS__' in window
|
||||
|
||||
const REPO = 'MrPatben8/konduktor'
|
||||
|
||||
interface GithubRelease {
|
||||
@@ -118,10 +130,31 @@ function ChangelogLine({ text }: { text: string }) {
|
||||
)
|
||||
}
|
||||
|
||||
type Phase =
|
||||
| { kind: 'offer' }
|
||||
| { kind: 'downloading'; downloaded: number; total: number | null }
|
||||
| { kind: 'restarting' }
|
||||
| { kind: 'deferred' }
|
||||
| { kind: 'failed'; error: string }
|
||||
|
||||
interface UpdateFailure {
|
||||
version: string
|
||||
error: string
|
||||
}
|
||||
|
||||
const mb = (bytes: number) => (bytes / 1e6).toFixed(0)
|
||||
|
||||
async function lastInstallFailure(): Promise<UpdateFailure | null> {
|
||||
if (!IN_TAURI) return null
|
||||
const { invoke } = await import('@tauri-apps/api/core')
|
||||
return (await invoke<UpdateFailure | null>('update_take_failure')) ?? null
|
||||
}
|
||||
|
||||
export function UpdateCheck() {
|
||||
const qc = useQueryClient()
|
||||
const [dismissed, setDismissed] = useState(false)
|
||||
const [skipVersion, setSkipVersion] = useState(false)
|
||||
const [phase, setPhase] = useState<Phase>({ kind: 'offer' })
|
||||
|
||||
const release = useQuery({
|
||||
queryKey: ['latestRelease'],
|
||||
@@ -129,20 +162,50 @@ export function UpdateCheck() {
|
||||
staleTime: Infinity,
|
||||
retry: false,
|
||||
})
|
||||
// Read (and cleared) once: the shell writes it when an install fails at exit.
|
||||
const lastFailure = useQuery({
|
||||
queryKey: ['updateFailure'],
|
||||
queryFn: lastInstallFailure,
|
||||
staleTime: Infinity,
|
||||
retry: false,
|
||||
})
|
||||
// Shares App's ['prefs'] cache entry.
|
||||
const prefs = useQuery({ queryKey: ['prefs'], queryFn: api.getPrefs })
|
||||
|
||||
// Cancel in QuitGuard's Save / Discard prompt: the update waits for the next quit.
|
||||
useEffect(() => {
|
||||
if (phase.kind !== 'restarting') return
|
||||
let unlisten: (() => void) | undefined
|
||||
let cancelled = false
|
||||
void import('@tauri-apps/api/event').then(async ({ listen }) => {
|
||||
const off = await listen('konduktor://update-deferred', () => setPhase({ kind: 'deferred' }))
|
||||
if (cancelled) off()
|
||||
else unlisten = off
|
||||
})
|
||||
return () => {
|
||||
cancelled = true
|
||||
unlisten?.()
|
||||
}
|
||||
}, [phase.kind])
|
||||
|
||||
const latest = release.data
|
||||
const latestVer = latest ? parseVersion(latest.tag_name) : null
|
||||
const currentVer = parseVersion(__APP_VERSION__)
|
||||
const latestSemver = latestVer?.join('.')
|
||||
const updateAvailable = !!(latestVer && currentVer && isNewer(latestVer, currentVer))
|
||||
const skipped = !!latestSemver && prefs.data?.skippedUpdateVersion === latestSemver
|
||||
const failedBefore = lastFailure.data ?? null
|
||||
const releasePage = latest?.html_url ?? `https://github.com/${REPO}/releases`
|
||||
|
||||
if (dismissed) return null
|
||||
// Wait for prefs before showing so a skipped version never flashes the dialog.
|
||||
if (dismissed || !updateAvailable || !latest || !prefs.isSuccess || skipped) return null
|
||||
const offering = updateAvailable && !!latest && prefs.isSuccess && !skipped
|
||||
if (!offering && !failedBefore) return null
|
||||
|
||||
const busy = phase.kind === 'downloading' || phase.kind === 'restarting'
|
||||
|
||||
const close = () => {
|
||||
if (busy) return
|
||||
if (skipVersion && latestSemver) {
|
||||
api
|
||||
.patchPrefs({ skippedUpdateVersion: latestSemver })
|
||||
@@ -152,12 +215,47 @@ export function UpdateCheck() {
|
||||
setDismissed(true)
|
||||
}
|
||||
|
||||
const download = () => {
|
||||
openExternal(latest.html_url)
|
||||
const openReleasePage = () => {
|
||||
openExternal(releasePage)
|
||||
setDismissed(true)
|
||||
}
|
||||
|
||||
const changes = whatsChanged(latest.body)
|
||||
const update = async () => {
|
||||
if (!latest) return
|
||||
setPhase({ kind: 'downloading', downloaded: 0, total: null })
|
||||
try {
|
||||
const { invoke, Channel } = await import('@tauri-apps/api/core')
|
||||
const onProgress = new Channel<{ downloaded: number; total: number | null }>()
|
||||
onProgress.onmessage = (p) => setPhase({ kind: 'downloading', ...p })
|
||||
await invoke('update_download', { tag: latest.tag_name, onProgress })
|
||||
setPhase({ kind: 'restarting' })
|
||||
await invoke('update_restart')
|
||||
} catch (e) {
|
||||
setPhase({ kind: 'failed', error: e instanceof Error ? e.message : String(e) })
|
||||
}
|
||||
}
|
||||
|
||||
// An install that failed at the last exit, with no newer offer to make.
|
||||
const reportOnly = !offering && !!failedBefore
|
||||
const failure =
|
||||
phase.kind === 'failed'
|
||||
? phase.error
|
||||
: reportOnly || (failedBefore && phase.kind === 'offer')
|
||||
? `The update to v${failedBefore!.version} didn't install: ${failedBefore!.error}`
|
||||
: null
|
||||
|
||||
const title =
|
||||
phase.kind === 'downloading'
|
||||
? 'Downloading update…'
|
||||
: phase.kind === 'restarting'
|
||||
? 'Installing update…'
|
||||
: phase.kind === 'deferred'
|
||||
? 'Update ready'
|
||||
: phase.kind === 'failed' || reportOnly
|
||||
? "Update didn't install"
|
||||
: 'Update available'
|
||||
|
||||
const changes = latest ? whatsChanged(latest.body) : []
|
||||
|
||||
return createPortal(
|
||||
<div
|
||||
@@ -169,14 +267,44 @@ export function UpdateCheck() {
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
>
|
||||
<div className="border-b border-line px-5 py-4">
|
||||
<div className="text-[15px] font-semibold tracking-tight">Update available</div>
|
||||
<div className="text-[15px] font-semibold tracking-tight">{title}</div>
|
||||
{latest && !reportOnly && (
|
||||
<div className="text-xs text-muted">
|
||||
Konduktor <span className="text-accent">{latest.tag_name}</span> is out — you have v
|
||||
{__APP_VERSION__}.
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="min-h-0 flex-1 overflow-y-auto px-5 py-4">
|
||||
{failure && <p className="mb-3 text-sm text-pink">{failure}</p>}
|
||||
{phase.kind === 'downloading' ? (
|
||||
<div className="space-y-2">
|
||||
<div className="well h-2 overflow-hidden rounded-full">
|
||||
<div
|
||||
className="h-full rounded-full bg-accent transition-[width] duration-150"
|
||||
style={{
|
||||
width: phase.total ? `${Math.min(100, (phase.downloaded / phase.total) * 100)}%` : '0%',
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
<div className="text-xs tabular-nums text-muted">
|
||||
{mb(phase.downloaded)}
|
||||
{phase.total ? ` / ${mb(phase.total)}` : ''} MB
|
||||
</div>
|
||||
</div>
|
||||
) : phase.kind === 'restarting' ? (
|
||||
<div className="text-sm text-muted">Konduktor will quit, install the update and reopen.</div>
|
||||
) : phase.kind === 'deferred' ? (
|
||||
<div className="text-sm text-muted">
|
||||
The update will install the next time you quit Konduktor.
|
||||
</div>
|
||||
) : reportOnly ? (
|
||||
<div className="text-sm text-muted">
|
||||
You can download the installer from the release page instead.
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
<div className="mb-2 text-xs font-medium text-muted">What's changed</div>
|
||||
{changes.length ? (
|
||||
<ul className="space-y-1.5">
|
||||
@@ -192,9 +320,12 @@ export function UpdateCheck() {
|
||||
) : (
|
||||
<div className="text-sm text-faint">No release notes.</div>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-3 border-t border-line px-5 py-3">
|
||||
{phase.kind === 'offer' && !reportOnly && (
|
||||
<label className="flex cursor-pointer items-center gap-2 text-xs text-muted">
|
||||
<input
|
||||
type="checkbox"
|
||||
@@ -204,7 +335,10 @@ export function UpdateCheck() {
|
||||
/>
|
||||
Skip this version
|
||||
</label>
|
||||
)}
|
||||
<div className="flex-1" />
|
||||
{phase.kind === 'offer' && !reportOnly && (
|
||||
<>
|
||||
<button
|
||||
onClick={close}
|
||||
className="rounded-md px-3 py-1.5 text-sm text-muted hover:bg-ink-800 hover:text-text"
|
||||
@@ -212,11 +346,37 @@ export function UpdateCheck() {
|
||||
Skip
|
||||
</button>
|
||||
<button
|
||||
onClick={download}
|
||||
onClick={IN_TAURI ? () => void update() : openReleasePage}
|
||||
className="rounded-full btn-primary px-3 py-1.5 text-sm font-semibold"
|
||||
>
|
||||
Download
|
||||
{IN_TAURI ? 'Update' : 'Download'}
|
||||
</button>
|
||||
</>
|
||||
)}
|
||||
{(phase.kind === 'failed' || reportOnly) && (
|
||||
<>
|
||||
<button
|
||||
onClick={close}
|
||||
className="rounded-md px-3 py-1.5 text-sm text-muted hover:bg-ink-800 hover:text-text"
|
||||
>
|
||||
Close
|
||||
</button>
|
||||
<button
|
||||
onClick={openReleasePage}
|
||||
className="rounded-full btn-primary px-3 py-1.5 text-sm font-semibold"
|
||||
>
|
||||
Open release page
|
||||
</button>
|
||||
</>
|
||||
)}
|
||||
{phase.kind === 'deferred' && (
|
||||
<button
|
||||
onClick={() => setDismissed(true)}
|
||||
className="rounded-full btn-primary px-3 py-1.5 text-sm font-semibold"
|
||||
>
|
||||
OK
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>,
|
||||
|
||||
Reference in new issue
Block a user