From 0f4dd63418c43d4bda009061bc2a44f6945020a6 Mon Sep 17 00:00:00 2001 From: GeekMr <140129782+WilliamWang1721@users.noreply.github.com> Date: Fri, 25 Sep 2026 18:03:37 +0800 Subject: [PATCH 01/10] feat(updater): support custom GitHub release sources --- .../2026-09-25-custom-release-source.md | 20 +++ nebula_app/i18n/en-US.json | 2 + nebula_app/i18n/zh-CN.json | 2 + nebula_app/src/gpui_shell/settings_pane.rs | 8 + .../src/gpui_shell/settings_pane/about.rs | 47 +++++- .../settings_pane/initialization.rs | 6 + .../src/gpui_shell/workspace/update_dialog.rs | 6 +- nebula_app/src/update_check.rs | 37 ++++- nebula_app/src/update_check/source.rs | 157 ++++++++++++++++++ nebula_app/src/update_download.rs | 27 +-- nebula_settings/src/lib.rs | 17 ++ nebula_settings/src/reset.rs | 1 + 12 files changed, 307 insertions(+), 23 deletions(-) create mode 100644 architecture/notes/nebula_app/update_check/2026-09-25-custom-release-source.md create mode 100644 nebula_app/src/update_check/source.rs diff --git a/architecture/notes/nebula_app/update_check/2026-09-25-custom-release-source.md b/architecture/notes/nebula_app/update_check/2026-09-25-custom-release-source.md new file mode 100644 index 000000000..9f80e717e --- /dev/null +++ b/architecture/notes/nebula_app/update_check/2026-09-25-custom-release-source.md @@ -0,0 +1,20 @@ +# Configurable GitHub Release update source + +## Decision + +Persist one optional `update_release_url`. Empty keeps the existing +`Kuddev/pebrel` updater. A custom value must be an HTTPS GitHub Releases URL; +`releases/tag/` selects that exact release, while `releases` uses GitHub's +latest-release API. + +Only discovery and the trusted release-download repository become configurable. +The existing native asset names, size limits, SHA-256 requirement, streamed +verification and platform installation handoff remain unchanged. The official +source keeps its existing 403/429 public-page fallback; custom sources return the +GitHub API error instead of adding a second fallback protocol. + +## Compatibility + +Existing settings omit the key and keep current behavior. Clearing the field +restores the official source; changing it also prevents cached assets from a +different repository from passing download validation. diff --git a/nebula_app/i18n/en-US.json b/nebula_app/i18n/en-US.json index 3a1643f1e..bee9e83bf 100644 --- a/nebula_app/i18n/en-US.json +++ b/nebula_app/i18n/en-US.json @@ -802,6 +802,8 @@ "network": "Could not download the update. Check your network and proxy settings, or use the Releases page." }, "auto_download": "Download updates in the background", + "source_label": "Custom release source", + "source_placeholder": "Blank = official · https://github.com/owner/repo/releases", "stop_download": "Stop download", "skip_version": "Skip version", "restart_install": "Restart and install", diff --git a/nebula_app/i18n/zh-CN.json b/nebula_app/i18n/zh-CN.json index 25ec97f86..9f8de96bc 100644 --- a/nebula_app/i18n/zh-CN.json +++ b/nebula_app/i18n/zh-CN.json @@ -802,6 +802,8 @@ "network": "无法下载更新。请检查网络和代理设置,或从发布页手动下载。" }, "auto_download": "在后台预下载更新", + "source_label": "自定义更新地址", + "source_placeholder": "留空 = 官方源 · https://github.com/owner/repo/releases", "stop_download": "停止下载", "skip_version": "跳过此版本", "restart_install": "重启并安装", diff --git a/nebula_app/src/gpui_shell/settings_pane.rs b/nebula_app/src/gpui_shell/settings_pane.rs index 6a7aa805e..17ca41397 100644 --- a/nebula_app/src/gpui_shell/settings_pane.rs +++ b/nebula_app/src/gpui_shell/settings_pane.rs @@ -116,6 +116,7 @@ pub struct SettingsPane { about_update: AboutUpdateState, about_update_seq: u64, about_last_checked: Option, + update_release_input: Entity, /// 首页「项目与支持」→ 赞助商:独立页面,不是外链行。切换分区时清掉。 about_sponsor_open: bool, settings_search_input: Entity, @@ -325,6 +326,13 @@ impl SettingsPane { let placeholder = localized_input_placeholder(key, language); input.update(cx, |state, cx| state.set_placeholder(placeholder, window, cx)); } + self.update_release_input.update(cx, |state, cx| { + state.set_placeholder( + language.text(crate::i18n::Message::UpdateSourcePlaceholder), + window, + cx, + ) + }); self.settings_search_input.update(cx, |state, cx| { state.set_placeholder( language.pick( diff --git a/nebula_app/src/gpui_shell/settings_pane/about.rs b/nebula_app/src/gpui_shell/settings_pane/about.rs index 1826d7653..e2b0c263b 100644 --- a/nebula_app/src/gpui_shell/settings_pane/about.rs +++ b/nebula_app/src/gpui_shell/settings_pane/about.rs @@ -67,6 +67,31 @@ impl SettingsPane { .child(value) } + fn save_update_release_source(&mut self, window: &mut Window, cx: &mut Context) { + let raw = self.update_release_input.read(cx).value(); + match crate::update_check::normalize_setting(&raw) { + Ok(value) => { + self.update_release_input + .update(cx, |input, cx| input.set_value(value.clone(), window, cx)); + if value != self.runtime.update_release_url { + self.persist(&[("update_release_url", value)], cx); + if let Some(asset) = crate::update_download::cached_asset() { + crate::update_download::cancel(&asset); + } + } + self.about_update = AboutUpdateState::Idle; + self.about_last_checked = None; + }, + Err(error) => crate::gpui_shell::toast::toast( + window, + cx, + crate::gpui_shell::toast::ToastKind::Warning, + error, + ), + } + cx.notify(); + } + pub(super) fn section_home(&mut self, window: &Window, cx: &mut Context) -> gpui::Div { let language = crate::gpui_shell::config::ui_language(cx); let theme = cx.theme(); @@ -214,6 +239,17 @@ impl SettingsPane { .on_click(cx.listener(|this, checked: &bool, _, cx| { this.persist(&[("auto_download_updates", (*checked as u8).to_string())], cx); })); + let update_source = h_flex() + .items_center() + .gap_2() + .child(div().w(px(300.0)).child(Input::new(&self.update_release_input).h(px(32.0)))) + .child( + NebulaButton::new("save-update-release-source") + .label(language.text(crate::i18n::Message::CommonSave)) + .on_click(cx.listener(|this, _, window, cx| { + this.save_update_release_source(window, cx); + })), + ); let last_checked: SharedString = self .about_last_checked .clone() @@ -242,8 +278,8 @@ impl SettingsPane { cx, )) .child(Self::about_value_row( - language.pick("更新通道", "Update channel"), - div().text_color(muted).child("Stable"), + language.text(crate::i18n::Message::UpdateSourceLabel), + update_source, cx, )) .child(Self::about_value_row( @@ -251,6 +287,11 @@ impl SettingsPane { div().text_color(muted).child(last_checked), cx, )); + let release_page = if self.runtime.update_release_url.is_empty() { + crate::update_check::RELEASES_PAGE.to_owned() + } else { + self.runtime.update_release_url.clone() + }; let actions = v_flex() .flex_1() .min_w(px(280.0)) @@ -273,7 +314,7 @@ impl SettingsPane { "about-releases", IconName::BookOpen, language.pick("更新内容", "Release notes"), - crate::update_check::RELEASES_PAGE.to_owned(), + release_page, cx, )) .child(Self::about_page_row( diff --git a/nebula_app/src/gpui_shell/settings_pane/initialization.rs b/nebula_app/src/gpui_shell/settings_pane/initialization.rs index 1ff1abe86..cf6a3fdb9 100644 --- a/nebula_app/src/gpui_shell/settings_pane/initialization.rs +++ b/nebula_app/src/gpui_shell/settings_pane/initialization.rs @@ -544,6 +544,11 @@ impl SettingsPane { let appearance_interceptor = cx.listener(Self::intercept_appearance_picker); subscriptions.push(cx.intercept_keystrokes(appearance_interceptor)); + let update_release_input = cx.new(|cx| { + InputState::new(window, cx) + .placeholder(language.text(crate::i18n::Message::UpdateSourcePlaceholder)) + .default_value(runtime.update_release_url.clone()) + }); let settings_search_input = cx.new(|cx| { InputState::new(window, cx).placeholder(language.pick( "搜索全部设置,例如「字号」「透明度」「更新」", @@ -584,6 +589,7 @@ impl SettingsPane { about_update: AboutUpdateState::Idle, about_update_seq: 0, about_last_checked: None, + update_release_input, about_sponsor_open: false, settings_search_input, search_origin_section: None, diff --git a/nebula_app/src/gpui_shell/workspace/update_dialog.rs b/nebula_app/src/gpui_shell/workspace/update_dialog.rs index 5b6a9e6f4..effefc952 100644 --- a/nebula_app/src/gpui_shell/workspace/update_dialog.rs +++ b/nebula_app/src/gpui_shell/workspace/update_dialog.rs @@ -68,7 +68,7 @@ fn start_update_download( cx: &mut App, ) { let Some(asset) = result.asset.clone() else { - cx.open_url(crate::update_check::RELEASES_PAGE); + cx.open_url(&crate::update_check::release_page()); return; }; let job = match crate::update_download::begin(&asset) { @@ -403,7 +403,7 @@ pub(crate) fn open_update_dialog( .child(body) .on_ok(move |_, window, cx| { let Some(asset) = action_result.asset.as_ref() else { - cx.open_url(crate::update_check::RELEASES_PAGE); + cx.open_url(&crate::update_check::release_page()); return true; }; match crate::update_download::status(asset) { @@ -422,7 +422,7 @@ pub(crate) fn open_update_dialog( false }, _ => { - cx.open_url(crate::update_check::RELEASES_PAGE); + cx.open_url(&crate::update_check::release_page()); true }, } diff --git a/nebula_app/src/update_check.rs b/nebula_app/src/update_check.rs index 591d991c1..17ffae0ed 100644 --- a/nebula_app/src/update_check.rs +++ b/nebula_app/src/update_check.rs @@ -17,13 +17,17 @@ use crate::event::{Event, EventType}; #[cfg(feature = "legacy-shell")] use crate::message_bar::{Message, MessageType}; -const RELEASES_API: &str = "https://api.github.com/repos/Kuddev/pebrel/releases/latest"; pub const RELEASES_PAGE: &str = "https://github.com/Kuddev/pebrel/releases"; const UPDATE_STATE_FILE: &str = "update_state.json"; const REMIND_LATER_SECS: u64 = 3 * 24 * 60 * 60; pub(crate) mod assets; mod fallback; +mod source; + +pub(crate) use source::{normalize_setting, release_page, validate_asset_url}; +#[cfg(test)] +pub(crate) use source::validate_official_asset_url; #[cfg(feature = "update-test-source")] pub(crate) mod test_source; @@ -142,7 +146,7 @@ pub fn spawn_once(proxy: EventLoopProxy) { log::debug!("update-check: v{current} is current (latest v{latest})"); return; } - let text = format!("Pebrel v{latest} 已发布(当前 v{current}),下载:{RELEASES_PAGE}"); + let text = format!("Pebrel v{latest} 已发布(当前 v{current}),下载:{}", release_page()); let _ = proxy.send_event(Event::new( EventType::Message(Message::new(text, MessageType::Warning)), None, @@ -293,8 +297,14 @@ fn fetch_latest_release() -> Result { let agent = test_source::agent(Duration::from_secs(10)); return fetch_release_with_agent(&agent, &url); } - let agent = crate::update_proxy::agent(RELEASES_API, Duration::from_secs(10)); - fetch_release_with_fallback(&agent, RELEASES_API, fallback::fetch_latest) + let source = source::configured()?; + let api = source.api_url(); + let agent = crate::update_proxy::agent(&api, Duration::from_secs(10)); + if source.is_default() { + fetch_release_with_fallback(&agent, &api, fallback::fetch_latest) + } else { + fetch_release_with_fallback(&agent, &api, |status| Err(format!("GitHub HTTP {status}"))) + } } #[cfg(any(test, feature = "update-test-source"))] @@ -329,9 +339,15 @@ fn fetch_release_with_fallback( fn parse_latest_release(bytes: &[u8]) -> Result { let release: GitHubRelease = serde_json::from_slice(bytes).map_err(|error| format!("GitHub 返回了无效数据:{error}"))?; - let version = release.tag_name.trim().trim_start_matches(['v', 'V']); - if version.is_empty() { - return Err("GitHub release 的版本号为空".to_owned()); + let tag = release.tag_name.trim(); + let version = tag.strip_prefix('v').or_else(|| tag.strip_prefix('V')).unwrap_or(tag); + if version.is_empty() + || !version.as_bytes().first().is_some_and(|byte| byte.is_ascii_digit()) + || !version + .bytes() + .all(|byte| byte.is_ascii_alphanumeric() || matches!(byte, b'.' | b'-' | b'+')) + { + return Err("GitHub release 的版本号无效".to_owned()); } let version = version.to_owned(); let asset = assets::select( @@ -449,6 +465,13 @@ mod tests { assert!(super::version_is_installable("1.8.0", "1.8.0", true)); } + #[test] + fn release_parser_accepts_semver_style_prerelease_tags() { + let release = parse_latest_release(br#"{"tag_name":"v2.0.0-beta.1","assets":[]}"#).unwrap(); + assert_eq!(release.version, "2.0.0-beta.1"); + assert!(parse_latest_release(br#"{"tag_name":"preview-v2.0.0","assets":[]}"#).is_err()); + } + #[test] fn version_comparison_is_numeric_per_segment() { assert!(is_newer("0.7.1", "0.7.0")); diff --git a/nebula_app/src/update_check/source.rs b/nebula_app/src/update_check/source.rs new file mode 100644 index 000000000..40474b96c --- /dev/null +++ b/nebula_app/src/update_check/source.rs @@ -0,0 +1,157 @@ +use super::{RELEASES_PAGE, UpdateAsset}; + +const GITHUB: &str = "https://github.com/"; +const OFFICIAL: &str = "Kuddev/pebrel"; +const LEGACY: &str = "Kuddev/nebula"; + +pub(super) struct ReleaseSource { + repo: String, + tag: Option, +} + +impl ReleaseSource { + fn official() -> Self { + Self { repo: OFFICIAL.into(), tag: None } + } + + fn parse(value: &str) -> Result { + let value = value.trim().trim_end_matches('/'); + if value.is_empty() { + return Ok(Self::official()); + } + let path = value + .strip_prefix(GITHUB) + .ok_or_else(|| "自定义更新地址必须使用 https://github.com".to_owned())?; + if path.contains('?') || path.contains('#') { + return Err("自定义更新地址不能包含查询参数或片段".into()); + } + let (repo_path, tag) = if let Some(repo) = path.strip_suffix("/releases/latest") { + (repo, None) + } else if let Some(repo) = path.strip_suffix("/releases") { + (repo, None) + } else if let Some((repo, tag)) = path.split_once("/releases/tag/") { + (repo, Some(tag)) + } else { + return Err("请填写 GitHub Releases 或 releases/tag/ 地址".into()); + }; + let Some((owner, repo)) = repo_path.split_once('/') else { + return Err("GitHub Release 地址无效".into()); + }; + if repo.contains('/') + || !component(owner) + || !component(repo) + || tag.is_some_and(|tag| !tag_name(tag)) + { + return Err("GitHub Release 地址无效".into()); + } + Ok(Self { repo: format!("{owner}/{repo}"), tag: tag.map(str::to_owned) }) + } + + pub(super) fn is_default(&self) -> bool { + self.repo == OFFICIAL && self.tag.is_none() + } + + pub(super) fn api_url(&self) -> String { + match &self.tag { + Some(tag) => format!("https://api.github.com/repos/{}/releases/tags/{tag}", self.repo), + None => format!("https://api.github.com/repos/{}/releases/latest", self.repo), + } + } + + fn page(&self) -> String { + match &self.tag { + Some(tag) => format!("{GITHUB}{}/releases/tag/{tag}", self.repo), + None if self.is_default() => RELEASES_PAGE.into(), + None => format!("{GITHUB}{}/releases", self.repo), + } + } + + fn accepts(&self, asset: &UpdateAsset) -> bool { + if self.is_default() { + return [OFFICIAL, LEGACY].iter().any(|repo| { + asset.download_url + == format!("{GITHUB}{repo}/releases/download/v{}/{}", asset.version, asset.name) + }); + } + let prefix = format!("{GITHUB}{}/releases/download/", self.repo); + let Some(path) = asset.download_url.strip_prefix(&prefix) else { + return false; + }; + let mut parts = path.split('/'); + let (Some(tag), Some(name), None) = (parts.next(), parts.next(), parts.next()) else { + return false; + }; + name == asset.name && tag_name(tag) && self.tag.as_deref().is_none_or(|value| value == tag) + } +} + +fn component(value: &str) -> bool { + !matches!(value, "" | "." | "..") + && value.bytes().all(|byte| { + byte.is_ascii_alphanumeric() || matches!(byte, b'.' | b'-' | b'_') + }) +} + +fn tag_name(value: &str) -> bool { + !matches!(value, "" | "." | "..") + && value.bytes().all(|byte| { + byte.is_ascii_alphanumeric() || matches!(byte, b'.' | b'-' | b'_' | b'+') + }) +} + +pub(super) fn configured() -> Result { + ReleaseSource::parse(&nebula_settings::RuntimeSettings::load().update_release_url) +} + +pub(crate) fn normalize_setting(value: &str) -> Result { + let source = ReleaseSource::parse(value)?; + Ok(if source.is_default() { String::new() } else { source.page() }) +} + +pub(crate) fn release_page() -> String { + configured().map(|source| source.page()).unwrap_or_else(|_| RELEASES_PAGE.into()) +} + +pub(crate) fn validate_asset_url(asset: &UpdateAsset) -> Result<(), String> { + configured()? + .accepts(asset) + .then_some(()) + .ok_or_else(|| "release 安装包 URL 不属于当前更新源".into()) +} + +#[cfg(test)] +pub(crate) fn validate_official_asset_url(asset: &UpdateAsset) -> Result<(), String> { + ReleaseSource::official() + .accepts(asset) + .then_some(()) + .ok_or_else(|| "release 安装包 URL 不属于 Pebrel 官方仓库".into()) +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn release_source_normalizes_and_pins_explicit_tags() { + assert_eq!( + normalize_setting("https://github.com/acme/pebrel/releases/latest").unwrap(), + "https://github.com/acme/pebrel/releases" + ); + assert!(normalize_setting("https://example.com/acme/pebrel/releases").is_err()); + + let source = + ReleaseSource::parse("https://github.com/acme/pebrel/releases/tag/v2.0.0-beta.1") + .unwrap(); + let asset = |tag: &str| UpdateAsset { + version: "2.0.0-beta.1".into(), + name: "Pebrel-v2.0.0-beta.1-windows-x64-setup.exe".into(), + download_url: format!( + "https://github.com/acme/pebrel/releases/download/{tag}/Pebrel-v2.0.0-beta.1-windows-x64-setup.exe" + ), + size: Some(42), + sha256: Some("a".repeat(64)), + }; + assert!(source.accepts(&asset("v2.0.0-beta.1"))); + assert!(!source.accepts(&asset("v2.0.0-beta.2"))); + } +} diff --git a/nebula_app/src/update_download.rs b/nebula_app/src/update_download.rs index d28dc8bce..dd44b34cd 100644 --- a/nebula_app/src/update_download.rs +++ b/nebula_app/src/update_download.rs @@ -20,7 +20,9 @@ use sha2::{Digest as _, Sha256}; use crate::i18n::{Message, UiLanguage}; use crate::update_check::UpdateAsset; +#[cfg(test)] const RELEASE_DOWNLOAD_PREFIX: &str = "https://github.com/Kuddev/pebrel/releases/download/"; +#[cfg(test)] const LEGACY_RELEASE_DOWNLOAD_PREFIX: &str = "https://github.com/Kuddev/nebula/releases/download/"; const MAX_INSTALLER_BYTES: u64 = 512 * 1024 * 1024; const DOWNLOAD_CHUNK_BYTES: usize = 64 * 1024; @@ -431,13 +433,24 @@ fn validate_asset(asset: &UpdateAsset) -> Result<(), String> { #[cfg(test)] fn validate_windows_asset_contract(asset: &UpdateAsset) -> Result<(), String> { - validate_asset_contract( + validate_asset_contract_official( asset, &crate::update_check::windows_x64_installer_names(&asset.version), ) } +#[cfg(test)] +fn validate_asset_contract_official(asset: &UpdateAsset, names: &[String]) -> Result<(), String> { + validate_asset_metadata(asset, names)?; + crate::update_check::validate_official_asset_url(asset) +} + fn validate_asset_contract(asset: &UpdateAsset, names: &[String]) -> Result<(), String> { + validate_asset_metadata(asset, names)?; + crate::update_check::validate_asset_url(asset) +} + +fn validate_asset_metadata(asset: &UpdateAsset, names: &[String]) -> Result<(), String> { if asset.version.is_empty() || !asset .version @@ -449,12 +462,6 @@ fn validate_asset_contract(asset: &UpdateAsset, names: &[String]) -> Result<(), if !names.contains(&asset.name) { return Err("release 资产不是当前平台的精确安装包".to_owned()); } - let trusted_url = [RELEASE_DOWNLOAD_PREFIX, LEGACY_RELEASE_DOWNLOAD_PREFIX] - .iter() - .any(|prefix| asset.download_url == format!("{prefix}v{}/{}", asset.version, asset.name)); - if !trusted_url { - return Err("release 安装包 URL 不属于 Pebrel 官方仓库".to_owned()); - } if asset.size.is_some_and(|bytes| bytes == 0 || bytes > MAX_INSTALLER_BYTES) { return Err("release 安装包大小无效".to_owned()); } @@ -776,10 +783,10 @@ mod macos_package_tests { size: Some(bytes.len() as u64), sha256: Some(Sha256::digest(&bytes).iter().map(|byte| format!("{byte:02x}")).collect()), }; - validate_asset_contract(&asset, &names).unwrap(); + validate_asset_contract_official(&asset, &names).unwrap(); verify_file(&path, &asset).unwrap(); assert!( - validate_asset_contract( + validate_asset_contract_official( &asset, &crate::update_check::assets::macos_names("1.9.1", "x86_64") ) @@ -792,6 +799,6 @@ mod macos_package_tests { Some(Sha256::digest(&bytes).iter().map(|byte| format!("{byte:02x}")).collect()); assert!(verify_file(&path, &asset).unwrap_err().contains("trailer")); asset.download_url = "https://example.invalid/image.dmg".into(); - assert!(validate_asset_contract(&asset, &names).is_err()); + assert!(validate_asset_contract_official(&asset, &names).is_err()); } } diff --git a/nebula_settings/src/lib.rs b/nebula_settings/src/lib.rs index f4d4eb1c5..b331a4310 100644 --- a/nebula_settings/src/lib.rs +++ b/nebula_settings/src/lib.rs @@ -1028,6 +1028,9 @@ pub struct RuntimeSettings { pub auto_check_updates: bool, /// Optional background package download; never grants install permission. pub auto_download_updates: bool, + /// Optional GitHub Releases page used instead of the official stable source. + /// Empty keeps the built-in Kuddev/pebrel update source. + pub update_release_url: String, pub keep_session: bool, /// Start the first window hidden when a system tray is available and enabled. pub silent_start: bool, @@ -1206,6 +1209,7 @@ impl RuntimeSettings { fetch: raw.bool_on("fetch").unwrap_or(false), auto_check_updates: raw.bool_on("auto_check_updates").unwrap_or(true), auto_download_updates: raw.bool_on("auto_download_updates").unwrap_or(false), + update_release_url: raw.value("update_release_url").unwrap_or_default().to_owned(), keep_session: raw.bool_on("keep_session").unwrap_or(false), silent_start: raw.bool_on("silent_start").unwrap_or(false), restore_session: raw.bool_on("restore_session").unwrap_or(true), @@ -1339,6 +1343,19 @@ mod tests { ); } + #[test] + fn update_release_url_round_trips_and_defaults_to_empty() { + let defaults = RuntimeSettings::from_raw(&RawSettings::default()); + assert!(defaults.update_release_url.is_empty()); + let settings = RuntimeSettings::from_raw(&RawSettings::from_text( + "update_release_url=https://github.com/acme/pebrel/releases/tag/v2.0.0-beta.1\n", + )); + assert_eq!( + settings.update_release_url, + "https://github.com/acme/pebrel/releases/tag/v2.0.0-beta.1" + ); + } + #[test] fn empty_quick_terminal_hotkey_is_distinct_from_an_unset_preference() { let unset = RuntimeSettings::from_raw(&RawSettings::from_text("theme=Nord\n")); diff --git a/nebula_settings/src/reset.rs b/nebula_settings/src/reset.rs index 494818d8f..eaadf6670 100644 --- a/nebula_settings/src/reset.rs +++ b/nebula_settings/src/reset.rs @@ -46,6 +46,7 @@ const RESET_KEYS: &[&str] = &[ "fetch", "auto_check_updates", "auto_download_updates", + "update_release_url", "keep_session", "restore_session", "resume_ai", From 5b3b8fe6bd85ec7c5ff962f18feeaf2b0843dccc Mon Sep 17 00:00:00 2001 From: GeekMr <140129782+WilliamWang1721@users.noreply.github.com> Date: Fri, 25 Sep 2026 18:04:31 +0800 Subject: [PATCH 02/10] fix(updater): invalidate stale checks when the source changes --- nebula_app/src/gpui_shell/settings_pane/about.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/nebula_app/src/gpui_shell/settings_pane/about.rs b/nebula_app/src/gpui_shell/settings_pane/about.rs index e2b0c263b..6895236c0 100644 --- a/nebula_app/src/gpui_shell/settings_pane/about.rs +++ b/nebula_app/src/gpui_shell/settings_pane/about.rs @@ -74,6 +74,7 @@ impl SettingsPane { self.update_release_input .update(cx, |input, cx| input.set_value(value.clone(), window, cx)); if value != self.runtime.update_release_url { + self.about_update_seq = self.about_update_seq.wrapping_add(1); self.persist(&[("update_release_url", value)], cx); if let Some(asset) = crate::update_download::cached_asset() { crate::update_download::cancel(&asset); @@ -242,7 +243,7 @@ impl SettingsPane { let update_source = h_flex() .items_center() .gap_2() - .child(div().w(px(300.0)).child(Input::new(&self.update_release_input).h(px(32.0)))) + .child(div().w(px(240.0)).child(Input::new(&self.update_release_input).h(px(32.0)))) .child( NebulaButton::new("save-update-release-source") .label(language.text(crate::i18n::Message::CommonSave)) From ff9f793fee1d7007148fff92ab6f4d2de949762b Mon Sep 17 00:00:00 2001 From: GeekMr <140129782+WilliamWang1721@users.noreply.github.com> Date: Sat, 26 Sep 2026 09:19:40 +0800 Subject: [PATCH 03/10] fix(ci): satisfy updater formatting and architecture checks --- .../2026-09-25-custom-release-source.md | 45 +++++++++++++------ nebula_app/src/update_check.rs | 2 +- nebula_app/src/update_check/source.rs | 12 ++--- 3 files changed, 39 insertions(+), 20 deletions(-) diff --git a/architecture/notes/nebula_app/update_check/2026-09-25-custom-release-source.md b/architecture/notes/nebula_app/update_check/2026-09-25-custom-release-source.md index 9f80e717e..d442e0d1b 100644 --- a/architecture/notes/nebula_app/update_check/2026-09-25-custom-release-source.md +++ b/architecture/notes/nebula_app/update_check/2026-09-25-custom-release-source.md @@ -1,20 +1,39 @@ # Configurable GitHub Release update source +## Status + +Accepted for this PR. + +## Context + +Pebrel currently checks the official GitHub Releases feed only. Fork builds and preview releases need one optional source override without duplicating the updater pipeline. + +## Evidence + +The existing updater already owns asset selection, size limits, SHA-256 verification, streamed downloads, and platform install handoff. Only release discovery and trusted repository validation need to vary. + ## Decision -Persist one optional `update_release_url`. Empty keeps the existing -`Kuddev/pebrel` updater. A custom value must be an HTTPS GitHub Releases URL; -`releases/tag/` selects that exact release, while `releases` uses GitHub's -latest-release API. +Persist one optional `update_release_url`. Empty keeps `Kuddev/pebrel`. A custom value must be an HTTPS GitHub Releases URL. `releases` or `releases/latest` selects the repository's latest release; `releases/tag/` pins an exact release. + +The official source keeps its existing 403/429 public-page fallback. Custom sources use the GitHub API directly and do not add another fallback protocol. + +## Rejected alternatives + +A second updater implementation per source was rejected because it would duplicate asset selection, verification, and install logic. Arbitrary download URLs were rejected because they would weaken repository and asset validation. + +## Consequences + +Existing settings remain unchanged when the field is absent or empty. Changing the source invalidates assets from another repository during download validation. Custom sources must keep Pebrel's existing native package naming and SHA-256 metadata contract. + +## Validation + +CI covers the architecture note contract, Rust formatting, native tests, and updater tests. The parser also tests latest-release normalization, explicit prerelease tags, and rejection of non-GitHub release URLs. + +## Supersedes -Only discovery and the trusted release-download repository become configurable. -The existing native asset names, size limits, SHA-256 requirement, streamed -verification and platform installation handoff remain unchanged. The official -source keeps its existing 403/429 public-page fallback; custom sources return the -GitHub API error instead of adding a second fallback protocol. +None. -## Compatibility +## Revisit when -Existing settings omit the key and keep current behavior. Clearing the field -restores the official source; changing it also prevents cached assets from a -different repository from passing download validation. +Revisit if Pebrel supports a non-GitHub release backend or if package identity and verification rules become source-specific. diff --git a/nebula_app/src/update_check.rs b/nebula_app/src/update_check.rs index 17ffae0ed..c0275fd8e 100644 --- a/nebula_app/src/update_check.rs +++ b/nebula_app/src/update_check.rs @@ -25,9 +25,9 @@ pub(crate) mod assets; mod fallback; mod source; -pub(crate) use source::{normalize_setting, release_page, validate_asset_url}; #[cfg(test)] pub(crate) use source::validate_official_asset_url; +pub(crate) use source::{normalize_setting, release_page, validate_asset_url}; #[cfg(feature = "update-test-source")] pub(crate) mod test_source; diff --git a/nebula_app/src/update_check/source.rs b/nebula_app/src/update_check/source.rs index 40474b96c..1456d82a9 100644 --- a/nebula_app/src/update_check/source.rs +++ b/nebula_app/src/update_check/source.rs @@ -87,16 +87,16 @@ impl ReleaseSource { fn component(value: &str) -> bool { !matches!(value, "" | "." | "..") - && value.bytes().all(|byte| { - byte.is_ascii_alphanumeric() || matches!(byte, b'.' | b'-' | b'_') - }) + && value + .bytes() + .all(|byte| byte.is_ascii_alphanumeric() || matches!(byte, b'.' | b'-' | b'_')) } fn tag_name(value: &str) -> bool { !matches!(value, "" | "." | "..") - && value.bytes().all(|byte| { - byte.is_ascii_alphanumeric() || matches!(byte, b'.' | b'-' | b'_' | b'+') - }) + && value + .bytes() + .all(|byte| byte.is_ascii_alphanumeric() || matches!(byte, b'.' | b'-' | b'_' | b'+')) } pub(super) fn configured() -> Result { From 9826c3f4ef9f015da60003e8ceeb8e5eef204746 Mon Sep 17 00:00:00 2001 From: GeekMr <140129782+WilliamWang1721@users.noreply.github.com> Date: Mon, 28 Sep 2026 19:55:05 +0800 Subject: [PATCH 04/10] fix(updater): invalidate stale source checks --- ...026-09-28-update-source-result-lifetime.md | 61 +++++++++++++++++++ nebula_app/src/gpui_shell/mod.rs | 5 +- nebula_app/src/gpui_shell/settings_pane.rs | 19 +++++- .../src/gpui_shell/settings_pane/about.rs | 26 ++++---- .../src/gpui_shell/settings_pane/reset.rs | 5 +- .../src/gpui_shell/workspace/residency.rs | 2 +- .../src/gpui_shell/workspace/windowing.rs | 5 +- nebula_app/src/update_check.rs | 43 +++++++++++-- 8 files changed, 141 insertions(+), 25 deletions(-) create mode 100644 architecture/notes/nebula_app/update_check/2026-09-28-update-source-result-lifetime.md diff --git a/architecture/notes/nebula_app/update_check/2026-09-28-update-source-result-lifetime.md b/architecture/notes/nebula_app/update_check/2026-09-28-update-source-result-lifetime.md new file mode 100644 index 000000000..f573e36e5 --- /dev/null +++ b/architecture/notes/nebula_app/update_check/2026-09-28-update-source-result-lifetime.md @@ -0,0 +1,61 @@ +# Update source result lifetime + +## Status + +Proposed with PR #294; maintainer review pending. + +## Context + +The configurable release source is read by manual checks, delayed startup checks, +and cached download hydration. A request can finish after the source changes or +Reset All restores the official source. Per-settings-pane sequencing protects +only one manual check and cannot invalidate startup work or results already queued +for another window. + +## Evidence + +- update_check::spawn_once and update_check::spawn_gpui_once publish background results. +- SettingsPane::check_for_updates can open its prompt after its state update. +- update_download::cancel invalidates the existing download generation, and + cached assets are validated against the configured source before reuse. +- The focused updater tests run through the repository's GitHub Actions workflows. + +## Decision + +Increment one process-local generation when the release source changes or all +settings reset. Each manual or startup check captures its generation and drops a +result when it is no longer current. GPUI update events carry the generation until +the main event dispatcher applies them. The About page also keeps its existing +per-pane sequence for repeated checks. Source invalidation clears the pane's +displayed check result and cancels the current download session. + +## Rejected alternatives + +Comparing source URLs alone would accept an old result if the setting changed +away and back while that request was running. Per-pane sequencing alone leaves +startup checks and another window's event queue unprotected. Cancelling every +network request would require new ownership across the synchronous release +fetcher; ignoring stale results uses the existing generation-based pattern. + +## Consequences + +Changing or resetting the source invalidates old results across all windows. +A check for the current generation remains usable. A stale cached asset does not +become installable because the existing asset validation still checks its source. + +## Validation + +The regression is +update_check::tests::invalidating_the_release_source_rejects_an_in_flight_result. +The PR description records GitHub Actions status for the final head; this note +does not claim UI end-to-end validation. + +## Supersedes + +None. This records result lifetime for +[the configurable release source](2026-09-25-custom-release-source.md). + +## Revisit when + +Revisit if release checks become cancellable and are actually cancelled on source +change, or if the updater moves source-generation ownership to another module. diff --git a/nebula_app/src/gpui_shell/mod.rs b/nebula_app/src/gpui_shell/mod.rs index a30d62fd7..2c8d58d08 100644 --- a/nebula_app/src/gpui_shell/mod.rs +++ b/nebula_app/src/gpui_shell/mod.rs @@ -70,7 +70,10 @@ pub(crate) enum GpuiShellEvent { TrayQuit, MuxAttach, RuntimeControl(std::sync::Arc), - UpdateAvailable(crate::update_check::UpdateCheckResult), + UpdateAvailable { + result: crate::update_check::UpdateCheckResult, + source_generation: u64, + }, SshPrompt(std::sync::Arc), } diff --git a/nebula_app/src/gpui_shell/settings_pane.rs b/nebula_app/src/gpui_shell/settings_pane.rs index fa8142fcc..50e24931c 100644 --- a/nebula_app/src/gpui_shell/settings_pane.rs +++ b/nebula_app/src/gpui_shell/settings_pane.rs @@ -1064,15 +1064,23 @@ impl SettingsPane { } self.about_update_seq = self.about_update_seq.wrapping_add(1); let sequence = self.about_update_seq; + let source_generation = crate::update_check::release_source_generation(); self.about_update = AboutUpdateState::Checking; let window_handle = window.window_handle(); let task = cx.background_executor().spawn(async { crate::update_check::check_now() }); cx.spawn(async move |this, cx| { let result = task.await; let prompt = result.as_ref().ok().filter(|result| result.update_available).cloned(); - let _ = this.update(cx, |pane, cx| { + let current = this.update(cx, |pane, cx| { if pane.about_update_seq != sequence { - return; + return false; + } + if !crate::update_check::release_source_is_current(source_generation) { + pane.about_update_seq = pane.about_update_seq.wrapping_add(1); + pane.about_update = AboutUpdateState::Idle; + pane.about_last_checked = None; + cx.notify(); + return false; } pane.about_last_checked = Some(chrono::Local::now().format("%Y-%m-%d %H:%M").to_string()); @@ -1084,9 +1092,16 @@ impl SettingsPane { Err(error) => AboutUpdateState::Failed(error), }; cx.notify(); + true }); + if !current.unwrap_or(false) { + return; + } if let Some(result) = prompt { let _ = window_handle.update(cx, move |_, window, cx| { + if !crate::update_check::release_source_is_current(source_generation) { + return; + } crate::gpui_shell::workspace::open_update_dialog(result, window, cx); }); } diff --git a/nebula_app/src/gpui_shell/settings_pane/about.rs b/nebula_app/src/gpui_shell/settings_pane/about.rs index 6895236c0..d997097ab 100644 --- a/nebula_app/src/gpui_shell/settings_pane/about.rs +++ b/nebula_app/src/gpui_shell/settings_pane/about.rs @@ -67,6 +67,16 @@ impl SettingsPane { .child(value) } + pub(super) fn invalidate_update_source(&mut self) { + self.about_update_seq = self.about_update_seq.wrapping_add(1); + crate::update_check::invalidate_release_source(); + self.about_update = AboutUpdateState::Idle; + self.about_last_checked = None; + if let Some(asset) = crate::update_download::cached_asset() { + crate::update_download::cancel(&asset); + } + } + fn save_update_release_source(&mut self, window: &mut Window, cx: &mut Context) { let raw = self.update_release_input.read(cx).value(); match crate::update_check::normalize_setting(&raw) { @@ -74,14 +84,12 @@ impl SettingsPane { self.update_release_input .update(cx, |input, cx| input.set_value(value.clone(), window, cx)); if value != self.runtime.update_release_url { - self.about_update_seq = self.about_update_seq.wrapping_add(1); self.persist(&[("update_release_url", value)], cx); - if let Some(asset) = crate::update_download::cached_asset() { - crate::update_download::cancel(&asset); - } + self.invalidate_update_source(); + } else { + self.about_update = AboutUpdateState::Idle; + self.about_last_checked = None; } - self.about_update = AboutUpdateState::Idle; - self.about_last_checked = None; }, Err(error) => crate::gpui_shell::toast::toast( window, @@ -288,11 +296,7 @@ impl SettingsPane { div().text_color(muted).child(last_checked), cx, )); - let release_page = if self.runtime.update_release_url.is_empty() { - crate::update_check::RELEASES_PAGE.to_owned() - } else { - self.runtime.update_release_url.clone() - }; + let release_page = crate::update_check::release_page(); let actions = v_flex() .flex_1() .min_w(px(280.0)) diff --git a/nebula_app/src/gpui_shell/settings_pane/reset.rs b/nebula_app/src/gpui_shell/settings_pane/reset.rs index f168fa3fd..b17bd1fcb 100644 --- a/nebula_app/src/gpui_shell/settings_pane/reset.rs +++ b/nebula_app/src/gpui_shell/settings_pane/reset.rs @@ -47,9 +47,8 @@ impl SettingsPane { return; }, }; + self.invalidate_update_source(); let active_section = self.active_section; - let about_update = std::mem::replace(&mut self.about_update, AboutUpdateState::Idle); - let about_last_checked = self.about_last_checked.take(); let about_update_seq = self.about_update_seq; let proxy_test_seq = self.proxy_test_seq.wrapping_add(1); let provider_test_seq = self.provider_test_seq.wrapping_add(1); @@ -62,8 +61,6 @@ impl SettingsPane { cx.set_global(settings); *self = Self::new(window, cx); self.active_section = active_section; - self.about_update = about_update; - self.about_last_checked = about_last_checked; self.about_update_seq = about_update_seq; self.proxy_test_seq = proxy_test_seq; self.provider_test_seq = provider_test_seq; diff --git a/nebula_app/src/gpui_shell/workspace/residency.rs b/nebula_app/src/gpui_shell/workspace/residency.rs index 8b5f3fa26..2114dd67b 100644 --- a/nebula_app/src/gpui_shell/workspace/residency.rs +++ b/nebula_app/src/gpui_shell/workspace/residency.rs @@ -102,7 +102,7 @@ impl NebulaWorkspace { }, // 更新通知由进程级 windowing dispatcher 选择 MRU 窗口;这个 // 旧的 workspace-local 分发器没有 Window,不能在此打开 Dialog。 - GpuiShellEvent::UpdateAvailable(_) | GpuiShellEvent::SshPrompt(_) => {}, + GpuiShellEvent::UpdateAvailable { .. } | GpuiShellEvent::SshPrompt(_) => {}, } } } diff --git a/nebula_app/src/gpui_shell/workspace/windowing.rs b/nebula_app/src/gpui_shell/workspace/windowing.rs index 4aa0234f9..7759a7cfa 100644 --- a/nebula_app/src/gpui_shell/workspace/windowing.rs +++ b/nebula_app/src/gpui_shell/workspace/windowing.rs @@ -902,7 +902,10 @@ pub(crate) fn dispatch_shell_events(events: Vec, cx: &mut App) { } }, GpuiShellEvent::RuntimeControl(dispatch) => dispatch_runtime(dispatch, cx), - GpuiShellEvent::UpdateAvailable(result) => { + GpuiShellEvent::UpdateAvailable { result, source_generation } => { + if !crate::update_check::release_source_is_current(source_generation) { + continue; + } let Some(entry) = entries_by_mru(cx).into_iter().next() else { continue }; let _ = entry.handle.update(cx, move |_, window, cx| { super::show_update_notification(result, window, cx); diff --git a/nebula_app/src/update_check.rs b/nebula_app/src/update_check.rs index c0275fd8e..f69f79946 100644 --- a/nebula_app/src/update_check.rs +++ b/nebula_app/src/update_check.rs @@ -5,7 +5,7 @@ //! GitHub outage all degrade to "no banner", never to an error the user sees. use std::sync::Mutex; -use std::sync::atomic::{AtomicBool, Ordering}; +use std::sync::atomic::{AtomicBool, AtomicU64, Ordering}; use std::time::{Duration, SystemTime, UNIX_EPOCH}; use serde::{Deserialize, Serialize}; @@ -33,6 +33,19 @@ pub(crate) use source::{normalize_setting, release_page, validate_asset_url}; pub(crate) mod test_source; static UPDATE_STATE_LOCK: Mutex<()> = Mutex::new(()); +static RELEASE_SOURCE_GENERATION: AtomicU64 = AtomicU64::new(0); + +pub(crate) fn release_source_generation() -> u64 { + RELEASE_SOURCE_GENERATION.load(Ordering::SeqCst) +} + +pub(crate) fn release_source_is_current(generation: u64) -> bool { + release_source_generation() == generation +} + +pub(crate) fn invalidate_release_source() { + RELEASE_SOURCE_GENERATION.fetch_add(1, Ordering::SeqCst); +} /// 自动提示状态独立于通用设置文件,避免后台版本检查改写用户设置正文。 /// 字段按版本生效,新版本不会继承旧版本的延迟或跳过选择。 @@ -133,6 +146,7 @@ pub fn spawn_once(proxy: EventLoopProxy) { let spawned = std::thread::Builder::new().name("update-check".into()).spawn(move || { // 等窗口与首个会话安顿好再查,别和启动抢磁盘/网络。 std::thread::sleep(Duration::from_secs(12)); + let source_generation = release_source_generation(); let release = match fetch_latest_release() { Ok(release) => release, Err(error) => { @@ -147,6 +161,9 @@ pub fn spawn_once(proxy: EventLoopProxy) { return; } let text = format!("Pebrel v{latest} 已发布(当前 v{current}),下载:{}", release_page()); + if !release_source_is_current(source_generation) { + return; + } let _ = proxy.send_event(Event::new( EventType::Message(Message::new(text, MessageType::Warning)), None, @@ -166,6 +183,7 @@ pub fn spawn_gpui_once(sender: std::sync::mpsc::Sender result, Err(error) => { @@ -209,7 +229,13 @@ pub fn spawn_gpui_once(sender: std::sync::mpsc::Sender bool { #[cfg(test)] mod tests { + #[test] + fn invalidating_the_release_source_rejects_an_in_flight_result() { + let generation = super::release_source_generation(); + super::invalidate_release_source(); + assert!(!super::release_source_is_current(generation)); + } + #[test] fn release_check_uses_the_resolved_proxy_for_an_unresolvable_target() { use crate::update_proxy::test_support::{Server, response}; From 9a415b846117272c754f014cca17e139c8d7cb40 Mon Sep 17 00:00:00 2001 From: GeekMr <140129782+WilliamWang1721@users.noreply.github.com> Date: Mon, 28 Sep 2026 20:00:59 +0800 Subject: [PATCH 05/10] style(updater): format update event --- nebula_app/src/gpui_shell/mod.rs | 5 +---- nebula_app/src/update_check.rs | 6 ++---- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/nebula_app/src/gpui_shell/mod.rs b/nebula_app/src/gpui_shell/mod.rs index 2c8d58d08..495084635 100644 --- a/nebula_app/src/gpui_shell/mod.rs +++ b/nebula_app/src/gpui_shell/mod.rs @@ -70,10 +70,7 @@ pub(crate) enum GpuiShellEvent { TrayQuit, MuxAttach, RuntimeControl(std::sync::Arc), - UpdateAvailable { - result: crate::update_check::UpdateCheckResult, - source_generation: u64, - }, + UpdateAvailable { result: crate::update_check::UpdateCheckResult, source_generation: u64 }, SshPrompt(std::sync::Arc), } diff --git a/nebula_app/src/update_check.rs b/nebula_app/src/update_check.rs index f69f79946..da9ca4b54 100644 --- a/nebula_app/src/update_check.rs +++ b/nebula_app/src/update_check.rs @@ -232,10 +232,8 @@ pub fn spawn_gpui_once(sender: std::sync::mpsc::Sender Date: Mon, 28 Sep 2026 21:03:32 +0800 Subject: [PATCH 06/10] fix(i18n): localize release source validation --- nebula_app/i18n/en-US.json | 1 + nebula_app/i18n/zh-CN.json | 1 + .../src/gpui_shell/settings_pane/about.rs | 6 ++-- nebula_app/src/update_check/source.rs | 36 ++++++++++--------- 4 files changed, 25 insertions(+), 19 deletions(-) diff --git a/nebula_app/i18n/en-US.json b/nebula_app/i18n/en-US.json index a55f5efd7..753cf56f2 100644 --- a/nebula_app/i18n/en-US.json +++ b/nebula_app/i18n/en-US.json @@ -832,6 +832,7 @@ }, "auto_download": "Download updates in the background", "source_label": "Custom release source", + "source_invalid": "Enter an HTTPS GitHub Releases URL; add /tag/ to select a specific release.", "source_placeholder": "Blank = official · https://github.com/owner/repo/releases", "stop_download": "Stop download", "skip_version": "Skip version", diff --git a/nebula_app/i18n/zh-CN.json b/nebula_app/i18n/zh-CN.json index ab8784e33..e4693faf5 100644 --- a/nebula_app/i18n/zh-CN.json +++ b/nebula_app/i18n/zh-CN.json @@ -832,6 +832,7 @@ }, "auto_download": "在后台预下载更新", "source_label": "自定义更新地址", + "source_invalid": "请输入 HTTPS GitHub Releases 地址;在末尾添加 /tag/ 可选择指定版本。", "source_placeholder": "留空 = 官方源 · https://github.com/owner/repo/releases", "stop_download": "停止下载", "skip_version": "跳过此版本", diff --git a/nebula_app/src/gpui_shell/settings_pane/about.rs b/nebula_app/src/gpui_shell/settings_pane/about.rs index d997097ab..dbb5da26b 100644 --- a/nebula_app/src/gpui_shell/settings_pane/about.rs +++ b/nebula_app/src/gpui_shell/settings_pane/about.rs @@ -80,7 +80,7 @@ impl SettingsPane { fn save_update_release_source(&mut self, window: &mut Window, cx: &mut Context) { let raw = self.update_release_input.read(cx).value(); match crate::update_check::normalize_setting(&raw) { - Ok(value) => { + Some(value) => { self.update_release_input .update(cx, |input, cx| input.set_value(value.clone(), window, cx)); if value != self.runtime.update_release_url { @@ -91,11 +91,11 @@ impl SettingsPane { self.about_last_checked = None; } }, - Err(error) => crate::gpui_shell::toast::toast( + None => crate::gpui_shell::toast::toast( window, cx, crate::gpui_shell::toast::ToastKind::Warning, - error, + language.text(crate::i18n::Message::UpdateSourceInvalid).to_owned(), ), } cx.notify(); diff --git a/nebula_app/src/update_check/source.rs b/nebula_app/src/update_check/source.rs index 1456d82a9..14d3195e4 100644 --- a/nebula_app/src/update_check/source.rs +++ b/nebula_app/src/update_check/source.rs @@ -1,4 +1,5 @@ use super::{RELEASES_PAGE, UpdateAsset}; +use crate::i18n::{LanguagePreference, Message}; const GITHUB: &str = "https://github.com/"; const OFFICIAL: &str = "Kuddev/pebrel"; @@ -14,16 +15,14 @@ impl ReleaseSource { Self { repo: OFFICIAL.into(), tag: None } } - fn parse(value: &str) -> Result { + fn parse(value: &str) -> Option { let value = value.trim().trim_end_matches('/'); if value.is_empty() { - return Ok(Self::official()); + return Some(Self::official()); } - let path = value - .strip_prefix(GITHUB) - .ok_or_else(|| "自定义更新地址必须使用 https://github.com".to_owned())?; + let path = value.strip_prefix(GITHUB)?; if path.contains('?') || path.contains('#') { - return Err("自定义更新地址不能包含查询参数或片段".into()); + return None; } let (repo_path, tag) = if let Some(repo) = path.strip_suffix("/releases/latest") { (repo, None) @@ -32,19 +31,17 @@ impl ReleaseSource { } else if let Some((repo, tag)) = path.split_once("/releases/tag/") { (repo, Some(tag)) } else { - return Err("请填写 GitHub Releases 或 releases/tag/ 地址".into()); - }; - let Some((owner, repo)) = repo_path.split_once('/') else { - return Err("GitHub Release 地址无效".into()); + return None; }; + let (owner, repo) = repo_path.split_once('/')?; if repo.contains('/') || !component(owner) || !component(repo) || tag.is_some_and(|tag| !tag_name(tag)) { - return Err("GitHub Release 地址无效".into()); + return None; } - Ok(Self { repo: format!("{owner}/{repo}"), tag: tag.map(str::to_owned) }) + Some(Self { repo: format!("{owner}/{repo}"), tag: tag.map(str::to_owned) }) } pub(super) fn is_default(&self) -> bool { @@ -100,12 +97,19 @@ fn tag_name(value: &str) -> bool { } pub(super) fn configured() -> Result { - ReleaseSource::parse(&nebula_settings::RuntimeSettings::load().update_release_url) + let settings = nebula_settings::RuntimeSettings::load(); + let language = settings.language; + ReleaseSource::parse(&settings.update_release_url).ok_or_else(|| { + LanguagePreference::from(language) + .resolved() + .text(Message::UpdateSourceInvalid) + .to_owned() + }) } -pub(crate) fn normalize_setting(value: &str) -> Result { +pub(crate) fn normalize_setting(value: &str) -> Option { let source = ReleaseSource::parse(value)?; - Ok(if source.is_default() { String::new() } else { source.page() }) + Some(if source.is_default() { String::new() } else { source.page() }) } pub(crate) fn release_page() -> String { @@ -137,7 +141,7 @@ mod tests { normalize_setting("https://github.com/acme/pebrel/releases/latest").unwrap(), "https://github.com/acme/pebrel/releases" ); - assert!(normalize_setting("https://example.com/acme/pebrel/releases").is_err()); + assert!(normalize_setting("https://example.com/acme/pebrel/releases").is_none()); let source = ReleaseSource::parse("https://github.com/acme/pebrel/releases/tag/v2.0.0-beta.1") From f56114d16039e8016b842a23de5185ac0e67c15e Mon Sep 17 00:00:00 2001 From: GeekMr <140129782+WilliamWang1721@users.noreply.github.com> Date: Mon, 28 Sep 2026 21:10:46 +0800 Subject: [PATCH 07/10] style(updater): format source error mapping --- nebula_app/src/update_check/source.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/nebula_app/src/update_check/source.rs b/nebula_app/src/update_check/source.rs index 14d3195e4..f93719471 100644 --- a/nebula_app/src/update_check/source.rs +++ b/nebula_app/src/update_check/source.rs @@ -100,10 +100,7 @@ pub(super) fn configured() -> Result { let settings = nebula_settings::RuntimeSettings::load(); let language = settings.language; ReleaseSource::parse(&settings.update_release_url).ok_or_else(|| { - LanguagePreference::from(language) - .resolved() - .text(Message::UpdateSourceInvalid) - .to_owned() + LanguagePreference::from(language).resolved().text(Message::UpdateSourceInvalid).to_owned() }) } From 4bb08109e015637afa71fbbcf0633b3dca711824 Mon Sep 17 00:00:00 2001 From: GeekMr <140129782+WilliamWang1721@users.noreply.github.com> Date: Mon, 28 Sep 2026 21:24:49 +0800 Subject: [PATCH 08/10] fix(updater): resolve source validation language --- nebula_app/src/gpui_shell/settings_pane/about.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/nebula_app/src/gpui_shell/settings_pane/about.rs b/nebula_app/src/gpui_shell/settings_pane/about.rs index dbb5da26b..38e7b35a4 100644 --- a/nebula_app/src/gpui_shell/settings_pane/about.rs +++ b/nebula_app/src/gpui_shell/settings_pane/about.rs @@ -78,6 +78,7 @@ impl SettingsPane { } fn save_update_release_source(&mut self, window: &mut Window, cx: &mut Context) { + let language = crate::gpui_shell::config::ui_language(cx); let raw = self.update_release_input.read(cx).value(); match crate::update_check::normalize_setting(&raw) { Some(value) => { From 7c1ec8d6994f922692d209c84ba7aaacf777996c Mon Sep 17 00:00:00 2001 From: GeekMr <140129782+WilliamWang1721@users.noreply.github.com> Date: Mon, 28 Sep 2026 22:11:55 +0800 Subject: [PATCH 09/10] fix(i18n): localize update source mismatch --- nebula_app/i18n/en-US.json | 1 + nebula_app/i18n/zh-CN.json | 1 + nebula_app/src/update_check/source.rs | 10 ++++++---- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/nebula_app/i18n/en-US.json b/nebula_app/i18n/en-US.json index 6102767b0..9c96660df 100644 --- a/nebula_app/i18n/en-US.json +++ b/nebula_app/i18n/en-US.json @@ -833,6 +833,7 @@ "auto_download": "Download updates in the background", "source_label": "Custom release source", "source_invalid": "Enter an HTTPS GitHub Releases URL; add /tag/ to select a specific release.", + "source_asset_mismatch": "The update package does not match the selected release source. Check for updates again.", "source_placeholder": "Blank = official · https://github.com/owner/repo/releases", "stop_download": "Stop download", "skip_version": "Skip version", diff --git a/nebula_app/i18n/zh-CN.json b/nebula_app/i18n/zh-CN.json index 4024251ee..e52c4fd32 100644 --- a/nebula_app/i18n/zh-CN.json +++ b/nebula_app/i18n/zh-CN.json @@ -833,6 +833,7 @@ "auto_download": "在后台预下载更新", "source_label": "自定义更新地址", "source_invalid": "请输入 HTTPS GitHub Releases 地址;在末尾添加 /tag/ 可选择指定版本。", + "source_asset_mismatch": "更新安装包与所选更新源不匹配,请重新检查更新。", "source_placeholder": "留空 = 官方源 · https://github.com/owner/repo/releases", "stop_download": "停止下载", "skip_version": "跳过此版本", diff --git a/nebula_app/src/update_check/source.rs b/nebula_app/src/update_check/source.rs index f93719471..a06585a23 100644 --- a/nebula_app/src/update_check/source.rs +++ b/nebula_app/src/update_check/source.rs @@ -114,10 +114,12 @@ pub(crate) fn release_page() -> String { } pub(crate) fn validate_asset_url(asset: &UpdateAsset) -> Result<(), String> { - configured()? - .accepts(asset) - .then_some(()) - .ok_or_else(|| "release 安装包 URL 不属于当前更新源".into()) + configured()?.accepts(asset).then_some(()).ok_or_else(|| { + LanguagePreference::from(nebula_settings::RuntimeSettings::load().language) + .resolved() + .text(Message::UpdateSourceAssetMismatch) + .to_owned() + }) } #[cfg(test)] From dbfcce92080e2566b8ae95c49a0bd36371e368f1 Mon Sep 17 00:00:00 2001 From: GeekMr <140129782+WilliamWang1721@users.noreply.github.com> Date: Wed, 30 Sep 2026 21:00:07 +0800 Subject: [PATCH 10/10] test(updater): exercise source input, save validation and persisted reset --- .../src/gpui_shell/settings_pane/about.rs | 7 +- .../settings_pane/theme_studio_tests.rs | 64 +++++++++++++++++++ 2 files changed, 70 insertions(+), 1 deletion(-) diff --git a/nebula_app/src/gpui_shell/settings_pane/about.rs b/nebula_app/src/gpui_shell/settings_pane/about.rs index cd0181224..7fad86e65 100644 --- a/nebula_app/src/gpui_shell/settings_pane/about.rs +++ b/nebula_app/src/gpui_shell/settings_pane/about.rs @@ -262,7 +262,12 @@ impl SettingsPane { let update_source = h_flex() .items_center() .gap_2() - .child(div().w(px(240.0)).child(Input::new(&self.update_release_input).h(px(32.0)))) + .child( + div() + .debug_selector(|| "update-release-source-input".to_owned()) + .w(px(240.0)) + .child(Input::new(&self.update_release_input).h(px(32.0))), + ) .child( NebulaButton::new("save-update-release-source") .label(language.text(crate::i18n::Message::CommonSave)) diff --git a/nebula_app/src/gpui_shell/settings_pane/theme_studio_tests.rs b/nebula_app/src/gpui_shell/settings_pane/theme_studio_tests.rs index f2f566936..ca60669bc 100644 --- a/nebula_app/src/gpui_shell/settings_pane/theme_studio_tests.rs +++ b/nebula_app/src/gpui_shell/settings_pane/theme_studio_tests.rs @@ -1509,3 +1509,67 @@ fn theme_editor_save_only_forks_a_non_active_custom_template_without_publishing_ assert_eq!(settings_file_snapshot(), before_save_settings); assert_eq!(settings_file_snapshot(), before_settings_file); } + +#[gpui::test] +fn update_source_form_rejects_invalid_urls_and_persists_keyboard_edits(cx: &mut TestAppContext) { + let _fixture_guard = lock_theme_studio(); + let _settings_guard = SettingsBytesGuard::capture(); + std::fs::create_dir_all(nebula_settings::settings_dir()).unwrap(); + std::fs::write(nebula_settings::settings_path(), TEST_SETTINGS).unwrap(); + let (pane, mut window) = open_settings(cx); + pane.update(&mut window, |pane, cx| { + pane.active_section = 0; + cx.notify(); + }); + draw(&mut window); + let generation = crate::update_check::release_source_generation(); + let selector = "update-release-source-input"; + let bounds = window.debug_bounds(selector).expect("source input is visible"); + assert!(f32::from(bounds.size.width) >= 200.0); + assert!(f32::from(bounds.size.height) >= 28.0); + click(selector, &mut window); + window.simulate_input("https://example.com/acme/pebrel/releases"); + draw(&mut window); + assert_eq!( + pane.read_with(&mut window, |pane, cx| pane.update_release_input.read(cx).value()), + "https://example.com/acme/pebrel/releases" + ); + click("nebula-btn-save-update-release-source", &mut window); + assert!(RuntimeSettings::load().update_release_url.is_empty()); + assert!(crate::update_check::release_source_is_current(generation)); + click(selector, &mut window); + let select_all = match crate::platform::Platform::current() { + crate::platform::Platform::MacOS => "cmd-a", + _ => "ctrl-a", + }; + window.simulate_keystrokes(select_all); + window.simulate_input("https://github.com/acme/pebrel/releases/latest/"); + draw(&mut window); + click("nebula-btn-save-update-release-source", &mut window); + assert_eq!( + RuntimeSettings::load().update_release_url, + "https://github.com/acme/pebrel/releases" + ); + assert!(!crate::update_check::release_source_is_current(generation)); + pane.read_with(&mut window, |pane, cx| { + assert_eq!( + pane.update_release_input.read(cx).value(), + RuntimeSettings::load().update_release_url + ); + assert!(matches!(pane.about_update, AboutUpdateState::Idle)); + assert!(pane.about_last_checked.is_none()); + }); + let reopened = window.update(|window, cx| cx.new(|cx| SettingsPane::new(window, cx))); + reopened.read_with(&mut window, |pane, cx| { + assert_eq!( + pane.update_release_input.read(cx).value(), + RuntimeSettings::load().update_release_url + ); + }); + click(selector, &mut window); + window.simulate_keystrokes(select_all); + window.simulate_keystrokes("backspace"); + draw(&mut window); + click("nebula-btn-save-update-release-source", &mut window); + assert!(RuntimeSettings::load().update_release_url.is_empty()); +}