From 9c73f7d784fe28e591f342e321fbd94d916e5ad2 Mon Sep 17 00:00:00 2001 From: LU XIANGRUI <1078666705@qq.com> Date: Fri, 4 Dec 2026 10:52:08 +0900 Subject: [PATCH] feat(updates): choose the update channel (Stable / Nightly) (#7684) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(updates): choose the update channel (Stable / Nightly) - Settings › System Settings › Updates gets an Update channel select next to Update source - Its default follows the running build; nightly is on GitHub only, stable keeps the CNB mirror - OPENIDEA_UPDATE_ENDPOINT still overrides both channels * fix(updates): shorten the update channel hint so Check Now stays in view - At 520px wide and 680px high the long hint pushed Check Now out of the Settings dialog - The Updates e2e also checks that Update channel sits between the automatic check and Update source --------- Co-authored-by: LU XIANGRUI <26499420+wildcatDownstairs@users.noreply.github.com> --- Cargo.lock | 1 + crates/ide-core/src/settings.rs | 3 + crates/ide-core/src/updates.rs | 46 ++++++ e2e/updates.spec.ts | 10 +- src-tauri/Cargo.toml | 2 + src-tauri/src/commands/window.rs | 153 +++++++++++++----- src-tauri/src/updates.rs | 9 +- src/bindings.ts | 2 + .../settings/__tests__/behavior.test.ts | 50 ++++++ src/features/settings/model/behaviorSchema.ts | 9 ++ src/features/settings/pages/updates.ts | 12 +- src/platform/clientSettings.ts | 1 + src/platform/locales/text/en.json | 4 + src/platform/locales/text/ru.json | 4 + src/platform/locales/text/tr.json | 4 + src/platform/locales/text/zh-TW.json | 4 + src/platform/locales/text/zh.json | 4 + 17 files changed, 271 insertions(+), 47 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 309629e00b..15d054c1d8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6827,6 +6827,7 @@ dependencies = [ "percent-encoding", "reqwest", "security-framework", + "semver", "serde", "serde_json", "specta", diff --git a/crates/ide-core/src/settings.rs b/crates/ide-core/src/settings.rs index e7b3fa08e6..2f12cde6f5 100644 --- a/crates/ide-core/src/settings.rs +++ b/crates/ide-core/src/settings.rs @@ -1100,6 +1100,8 @@ pub struct GeneralSettings { pub project_name: String, /// Where updates come from: `auto` (the CNB mirror for the Chinese UI, else GitHub) | `github` | `cnb`. pub update_source: String, + /// `stable` | `nightly`; defaults to the running build's channel. + pub update_channel: String, pub auto_check_updates: bool, /// System Settings › Updates: open the What's New page after the app starts a new version. pub show_whats_new_after_update: bool, @@ -1122,6 +1124,7 @@ impl Default for GeneralSettings { power_save_mode: false, project_name: String::new(), update_source: "auto".into(), + update_channel: crate::updates::UpdateChannel::of_version(env!("CARGO_PKG_VERSION")).as_str().into(), auto_check_updates: true, show_whats_new_after_update: true, last_run_version: String::new(), diff --git a/crates/ide-core/src/updates.rs b/crates/ide-core/src/updates.rs index ae1679f393..d6d876d464 100644 --- a/crates/ide-core/src/updates.rs +++ b/crates/ide-core/src/updates.rs @@ -30,6 +30,38 @@ impl UpdateSource { } } +/// System Settings › Updates › Update channel: which release line updates come from. +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub enum UpdateChannel { + /// `releases/latest`, never a prerelease, mirrored on CNB. + Stable, + /// The rolling `nightly` release (nightly.yml), on GitHub only. + Nightly, +} + +impl UpdateChannel { + /// The channel a build of `version` updates from unless the setting says otherwise. + pub fn of_version(version: &str) -> Self { + if version.contains("-nightly.") { Self::Nightly } else { Self::Stable } + } + + /// The `general.updateChannel` setting; anything else follows this build. + pub fn resolve(preference: &str) -> Self { + match preference { + "stable" => Self::Stable, + "nightly" => Self::Nightly, + _ => Self::of_version(env!("CARGO_PKG_VERSION")), + } + } + + pub fn as_str(self) -> &'static str { + match self { + Self::Stable => "stable", + Self::Nightly => "nightly", + } + } +} + #[derive(Clone, Debug, Serialize, Deserialize, Type)] #[serde(rename_all = "camelCase")] pub struct UpdateInfo { @@ -109,6 +141,20 @@ mod tests { } } + #[test] + fn channel_follows_the_build_unless_chosen() { + assert_eq!(UpdateChannel::of_version("0.1.57"), UpdateChannel::Stable); + assert_eq!(UpdateChannel::of_version("0.1.58-nightly.20261203"), UpdateChannel::Nightly); + assert_eq!(UpdateChannel::of_version("0.1.58-nightly.20261203.2"), UpdateChannel::Nightly); + assert_eq!(UpdateChannel::of_version("0.2.0-beta.1"), UpdateChannel::Stable); + assert_eq!(UpdateChannel::resolve("stable"), UpdateChannel::Stable); + assert_eq!(UpdateChannel::resolve("nightly"), UpdateChannel::Nightly); + let build = UpdateChannel::of_version(env!("CARGO_PKG_VERSION")); + for other in ["", "auto", "Nightly", "eap"] { + assert_eq!(UpdateChannel::resolve(other), build); + } + } + #[test] fn checks_at_startup_and_every_four_hours_even_after_failure() { let mut policy = UpdatePolicy::default(); diff --git a/e2e/updates.spec.ts b/e2e/updates.spec.ts index 4e165bc27a..eef82472d6 100644 --- a/e2e/updates.spec.ts +++ b/e2e/updates.spec.ts @@ -63,19 +63,21 @@ test("Updates shows check status and keeps manual checks available when automati await expect(dialog.getByText("0.1.39", { exact: true })).toBeVisible(); await expect(dialog.getByText("Never", { exact: true })).toBeVisible(); const automatic = dialog.getByRole("checkbox", { name: "Check for updates automatically" }); + const channel = dialog.getByRole("button", { name: "Update channel", exact: true }); const source = dialog.getByRole("button", { name: "Update source", exact: true }); const check = dialog.getByRole("button", { name: "Check Now", exact: true }); const checked = dialog.getByText("Never", { exact: true }); const whatsNew = dialog.getByRole("checkbox", { name: "Show What's New after an update", exact: true }); for (const width of [1120, 580, 520]) { await page.setViewportSize({ width, height: 680 }); - const [automaticBox, sourceBox, checkBox, statusBox, whatsNewBox] = await Promise.all( - [automatic, source, check, checked, whatsNew].map((item) => item.boundingBox()), + const [automaticBox, channelBox, sourceBox, checkBox, statusBox, whatsNewBox] = await Promise.all( + [automatic, channel, source, check, checked, whatsNew].map((item) => item.boundingBox()), ); - if (!automaticBox || !sourceBox || !checkBox || !statusBox || !whatsNewBox) + if (!automaticBox || !channelBox || !sourceBox || !checkBox || !statusBox || !whatsNewBox) throw new Error("Missing Updates controls"); expect(checkBox.y).toBeGreaterThan(sourceBox.y + sourceBox.height); - expect(sourceBox.y).toBeGreaterThan(automaticBox.y + automaticBox.height); + expect(sourceBox.y).toBeGreaterThan(channelBox.y + channelBox.height); + expect(channelBox.y).toBeGreaterThan(automaticBox.y + automaticBox.height); expect(whatsNewBox.y).toBeGreaterThan(checkBox.y + checkBox.height); expect(statusBox.x).toBeGreaterThan(checkBox.x + checkBox.width); expect(Math.abs(statusBox.y + statusBox.height / 2 - checkBox.y - checkBox.height / 2)).toBeLessThan(1.5); diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 62aef345e6..a7be96c943 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -70,6 +70,8 @@ ide-docker = { path = "../crates/ide-docker" } ide-android = { path = "../crates/ide-android" } [dev-dependencies] +# The updater's version order (tauri-plugin-updater compares with semver). +semver = "1" tempfile.workspace = true [[test]] diff --git a/src-tauri/src/commands/window.rs b/src-tauri/src/commands/window.rs index dd97844e00..7abaff7c30 100644 --- a/src-tauri/src/commands/window.rs +++ b/src-tauri/src/commands/window.rs @@ -612,7 +612,7 @@ pub fn app_build_info(app: AppHandle) -> BuildInfo { } use ide_core::updates::UpdateInfo; -pub use ide_core::updates::{UpdateCheck, UpdateSource, UpdateStatus}; +pub use ide_core::updates::{UpdateChannel, UpdateCheck, UpdateSource, UpdateStatus}; pub(crate) fn update_endpoint_env() -> Option { std::env::var("OPENIDEA_UPDATE_ENDPOINT").ok().filter(|s| !s.trim().is_empty()) @@ -638,24 +638,51 @@ fn config_endpoints(app: &AppHandle) -> Vec { .unwrap_or_default() } -/// Nightly builds (`x.y.z-nightly.…`, nightly.yml) update from the nightly channel's manifest -/// only: the CNB mirror carries stable releases. -fn is_nightly(version: &str) -> bool { - version.contains("-nightly.") -} +/// The Stable channel's GitHub manifest, `plugins.updater.endpoints` of a stable build. +const STABLE_ENDPOINT: &str = "https://github.com/l0ng-ai/openidea/releases/latest/download/latest.json"; +/// The Nightly channel's manifest, which `scripts/nightly-prepare.ts` writes into a nightly build. +const NIGHTLY_ENDPOINT: &str = "https://github.com/l0ng-ai/openidea/releases/download/nightly/latest.json"; -/// The endpoints tried in order: `source` first, the other source when it fails or has -/// no manifest. Bundles are signed, so either source's manifest and downloads verify. -/// No official endpoint (a build without updates) means no mirror either, and a nightly -/// build of `version` has no mirror. -fn source_endpoints(official: Vec, source: UpdateSource, version: &str) -> Vec { - if official.is_empty() || is_nightly(version) { +/// The endpoints tried in order. The build's configured endpoint serves its own channel and +/// the other channel's manifest is the official one. Stable tries `source` first and the other +/// source when it fails or has no manifest; Nightly is on GitHub only, as the CNB mirror carries +/// stable releases. Bundles of both channels are signed with one key, so any of them verifies. +/// No configured endpoint (a build without updates) means no endpoint at all. +fn source_endpoints(official: Vec, channel: UpdateChannel, source: UpdateSource, version: &str) -> Vec { + if official.is_empty() { return official; } + let github = if channel == UpdateChannel::of_version(version) { + official + } else { + vec![ + match channel { + UpdateChannel::Stable => STABLE_ENDPOINT, + UpdateChannel::Nightly => NIGHTLY_ENDPOINT, + } + .to_string(), + ] + }; let mirror = vec![CNB_ENDPOINT.to_string()]; - match source { - UpdateSource::Github => [official, mirror].concat(), - UpdateSource::Cnb => [mirror, official].concat(), + match (channel, source) { + (UpdateChannel::Nightly, _) => github, + (UpdateChannel::Stable, UpdateSource::Github) => [github, mirror].concat(), + (UpdateChannel::Stable, UpdateSource::Cnb) => [mirror, github].concat(), + } +} + +/// `OPENIDEA_UPDATE_ENDPOINT` when set, which overrides both channels; else the endpoints of +/// the configured channel and `source`. +fn update_endpoints(app: &AppHandle, source: UpdateSource) -> Vec { + use tauri::Manager; + match update_endpoint_env() { + Some(url) => vec![url], + None => source_endpoints( + config_endpoints(app), + crate::updates::configured_channel(&app.state::()), + source, + env!("CARGO_PKG_VERSION"), + ), } } @@ -676,11 +703,7 @@ pub(crate) fn updater(app: &AppHandle, source: UpdateSource) -> IdeResult