Visual Studio Code, rebuilt in Rust
Rust
fix(update): find updates on Insiders builds and show the app icon (#85)
Artur Rok8a8b4701ac64
diff --git a/native/crates/app/src/app_icon.rs b/native/crates/app/src/app_icon.rsindex 44aa8c76c4d..72b5ad6c8bb 100644--- a/native/crates/app/src/app_icon.rs+++ b/native/crates/app/src/app_icon.rs@@ -35,6 +35,19 @@ pub fn image(_look: &str, _dark: bool, _bundled: bool) -> Option<&'static [u8]>None}+/// The product logo of the update tooltip, VS Code's branded code-icon.svg (updateTooltip.css `.product-logo`): the+/// Dock's icon for `look`.+#[cfg(target_os = "macos")]+pub fn logo(look: &str, dark: bool) -> &'static [u8] {+ image(look, dark, false).expect("a run outside the bundle has a PNG for every look")+}++/// The desktop file's icon, as package-linux installs it.+#[cfg(any(target_os = "linux", target_os = "windows"))]+pub fn logo(_look: &str, _dark: bool) -> &'static [u8] {+ include_bytes!("../../../../port/AppIcon.png")+}+/// Sets the Dock icon; `None` restores the bundle's.#[cfg(all(not(test), target_os = "macos"))]pub fn set(image: Option<&[u8]>) {diff --git a/native/crates/app/src/workbench.rs b/native/crates/app/src/workbench.rsindex 89390adb479..6c06d0423c4 100644--- a/native/crates/app/src/workbench.rs+++ b/native/crates/app/src/workbench.rs@@ -355,6 +355,8 @@ pub struct Workbench {pub host_colors: themes::HostColorScheme,/// The Dock icon last set for `window.appIcon`; `None` is the bundle's, what the app starts with.pub app_icon: Option<&'static [u8]>,+ /// The update tooltip's logo, decoded once per `window.appIcon` look and appearance.+ pub app_logo: Arc<gpui::Image>,/// `--wait` of command lines that opened files here, until their editors close.wait_files: Vec<command_line::WaitFiles>,/// When the window finished restoring (`LifecyclePhase.Restored`).@@ -785,6 +787,7 @@ impl Workbench {gallery_url: exthost::gallery::SERVICE_URL.into(),host_colors: themes::host_color_scheme(cx),app_icon: None,+ app_logo: themes::logo_image("default", false),wait_files: Vec::new(),restored_at: None,unattended_restart_logged: String::new(),diff --git a/native/crates/app/src/workbench/configuration/tests.rs b/native/crates/app/src/workbench/configuration/tests.rsindex ca41a544b16..d13f96225aa 100644--- a/native/crates/app/src/workbench/configuration/tests.rs+++ b/native/crates/app/src/workbench/configuration/tests.rs@@ -102,6 +102,7 @@ fn the_app_icon_setting_swaps_the_dock_icon_and_follows_the_appearance(cx: &mutlet (sender, _messages) = std::sync::mpsc::channel();let (workbench, cx) = cx.add_window_view(|_, cx| Workbench::new(theme, app_root.clone(), None, Languages::new(&[]), settings, HostSync::new(sender), cx));let icon = |cx: &mut gpui::VisualTestContext| workbench.read_with(cx, |workbench, _| workbench.app_icon);+ let logo = |cx: &mut gpui::VisualTestContext| workbench.read_with(cx, |workbench, _| workbench.app_logo.bytes().to_vec());workbench.update(cx, |workbench, _| {workbench.host_colors.dark = false;workbench.sync_app_icon();@@ -119,11 +120,13 @@ fn the_app_icon_setting_swaps_the_dock_icon_and_follows_the_appearance(cx: &mutworkbench.sync_app_icon();});assert_eq!(icon(cx), Some(crate::app_icon::BARS_DARK));+ assert_eq!(logo(cx), crate::app_icon::BARS_DARK, "the update tooltip shows the Dock's icon");std::fs::write(&user_settings, r#"{ "window.appIcon": "default" }"#).unwrap();workbench.update(cx, |workbench, cx| workbench.reload_changed_settings_files(cx));assert!(icon(cx).is_some_and(|image| image != default_light && image != crate::app_icon::BARS_DARK), "the dark default");assert_eq!(crate::app_icon::image("default", true, true), None, "the bundle's own icon in VSRustium.app");+ assert_eq!(Some(logo(cx).as_slice()), icon(cx), "the update tooltip shows the default icon, not VS Code's code-icon.svg");std::fs::remove_dir_all(dir).unwrap();}diff --git a/native/crates/app/src/workbench/themes.rs b/native/crates/app/src/workbench/themes.rsindex 218bd6035ef..66d71e1e037 100644--- a/native/crates/app/src/workbench/themes.rs+++ b/native/crates/app/src/workbench/themes.rs@@ -57,6 +57,10 @@ pub fn host_color_scheme(cx: &gpui::App) -> HostColorScheme {HostColorScheme { dark, high_contrast: false }}+pub fn logo_image(look: &str, dark: bool) -> std::sync::Arc<gpui::Image> {+ std::sync::Arc::new(gpui::Image::from_bytes(gpui::ImageFormat::Png, crate::app_icon::logo(look, dark).to_vec()))+}+/// themeConfiguration.ts `getColorThemeSettingId`: the setting that names the color theme for this host scheme.pub fn color_theme_setting_id(settings: &Settings, host: HostColorScheme) -> &'static str {let enabled = |key| settings.get_value(Some(key), &Default::default()) == Some(json!(true));@@ -368,11 +372,15 @@ impl Workbench {pub fn sync_app_icon(&mut self) {let look = self.setting("window.appIcon");let bundled = crate::product::is_bundled(&self.app_root);- let image = crate::app_icon::image(look.as_str().unwrap_or("default"), self.host_colors.dark, bundled);+ let look = look.as_str().unwrap_or("default");+ let image = crate::app_icon::image(look, self.host_colors.dark, bundled);if image != self.app_icon {self.app_icon = image;crate::app_icon::set(image);}+ if self.app_logo.bytes() != crate::app_icon::logo(look, self.host_colors.dark) {+ self.app_logo = logo_image(look, self.host_colors.dark);+ }}/// `WorkbenchThemeService.setColorTheme`: applies the theme, tells the extension host its kind, and writesdiff --git a/native/crates/app/src/workbench/update_title_bar.rs b/native/crates/app/src/workbench/update_title_bar.rsindex 63aa922ac2b..65905db68b3 100644--- a/native/crates/app/src/workbench/update_title_bar.rs+++ b/native/crates/app/src/workbench/update_title_bar.rs@@ -276,8 +276,7 @@ impl Workbench {details = details.child(div().child(format!("Released {date}")));details_height += LINE;}- let logo = self.app_root.join("src/vs/workbench/browser/media/code-icon.svg");- tooltip = tooltip.child(div().flex().gap(px(12.)).child(div().id("update-tooltip-logo").flex_none().size(px(48.)).p(px(5.)).role(gpui::Role::Image).aria_label(crate::product::name_long().to_owned()).child(img(logo).size_full())).child(details));+ tooltip = tooltip.child(div().flex().gap(px(12.)).child(div().id("update-tooltip-logo").flex_none().size(px(48.)).p(px(5.)).role(gpui::Role::Image).aria_label(crate::product::name_long().to_owned()).child(img(self.app_logo.clone()).size_full())).child(details));height += GAP + details_height.max(48.);if let Some(progress) = content.progress {diff --git a/native/crates/config/src/registry.rs b/native/crates/config/src/registry.rsindex 936bb5d5e78..de9f407a5ad 100644--- a/native/crates/config/src/registry.rs+++ b/native/crates/config/src/registry.rs@@ -151,11 +151,12 @@ impl Registry {let default = schema.get("default").cloned();registry.insert(key, Property { scope, restricted, default: Value::Null, default_default: default, source: None, schema });}- // Port addition (port/notes.md "Update feed"): upstream's channel is the build's quality.+ // Port addition (port/notes.md "Update feed"): upstream's channel is the build's quality, so it is the default.+ let channel = if stable { "latest" } else { "pre-release" };let schema = json!({"type": "string","enum": ["latest", "pre-release"],- "default": "latest",+ "default": channel,"scope": 1,"description": "Configure which releases you receive updates from. The updates are fetched from the GitHub releases of VSRustium.","enumDescriptions": ["Receive only releases that are not marked as pre-release.", "Receive pre-releases too, and any newer release."],@@ -163,7 +164,7 @@ impl Registry {"section": { "id": "update", "title": "Update", "order": 15 },"restricted": false,});- registry.insert("update.releaseChannel".into(), Property { scope: Scope::Application, restricted: false, default: Value::Null, default_default: Some(json!("latest")), source: None, schema });+ registry.insert("update.releaseChannel".into(), Property { scope: Scope::Application, restricted: false, default: Value::Null, default_default: Some(json!(channel)), source: None, schema });registry.register_defaults(&json!({"[plaintext]": { "editor.unicodeHighlight.ambiguousCharacters": false, "editor.unicodeHighlight.invisibleCharacters": false },@@ -626,6 +627,9 @@ mod tests {assert_eq!(default(&stable, "window.menuStyle"), Some(json!("native")));assert!(oss.properties.contains_key("extensions.autoRestart"));assert!(!stable.properties.contains_key("extensions.autoRestart"));+ assert_eq!(default(&stable, "update.releaseChannel"), Some(json!("latest")));+ assert_eq!(default(&oss, "update.releaseChannel"), Some(json!("pre-release")));+ assert_eq!(oss.properties["update.releaseChannel"].schema["default"], "pre-release");}fn registry(properties: Value, defaults: &[Value]) -> Registry {diff --git a/port/notes.md b/port/notes.mdindex 19fa3e03f99..3fc7d5f70a8 100644--- a/port/notes.md+++ b/port/notes.md@@ -812,7 +812,7 @@ Scope as in the M19 Work row of port/ledger.md.- Not ported, nothing to gate: releaseNotesEditor.ts conditional blocks (`STABLE`/`INSIDERS`: the port renders the GitHub release body), extensionsWorkbenchService.ts system extension updates and the 1 hour Insiders check interval, Download VSIX actions, codeCacheCleaner.ts and languagePackCachedDataCleaner.ts (no V8 code cache), preferences.ts recommended extension lookup, issueTroubleshoot.ts, survey.contribution.ts, window.ts translation URL, telemetry and assignment services, notebook kernel marketplace query, every chat, sessions and agent host gate (AI left out), update.ts SwitchProductQualityContribution (web only).- Update feed (`update.rs`): product.json `updateUrl` is the GitHub releases URL of rokartur/vsrustium. A release channel's feed is one static JSON file in upstream's `IUpdate` shape (the answer of update.code.visualstudio.com's `/api/update/<platform>/<quality>/<commit>`), one per platform the app is built for, VS Code's target platform names `darwin-arm64` and `darwin-x64` (`exthost::gallery::CURRENT_TARGET_PLATFORM`, from `cfg!(target_arch)`):`{"version": "<commit>", "productVersion": "1.148.0", "release": 1, "timestamp": <ms since epoch>, "url": "<zip URL>", "sha256hash": "<hex SHA-256 of the zip>", "prerelease": false}`.- Channels (port addition: setting `update.releaseChannel`, `latest` or `pre-release`, default `latest`; upstream's channel is the build's `quality`): `latest` reads `<updateUrl>/latest/download/<platform>.json`, which GitHub serves from the newest release not marked pre-release; `pre-release` reads `<updateUrl>/download/pre-release/<platform>-prerelease.json` (the arm64 names are the ones the first published build, v1.147.0-insider, reads), from a release tagged `pre-release` whose asset each publish replaces (GitHub has no "latest including pre-releases" URL). Port version (Artur): product.json `version` stays VS Code's semantic version (`1.148.0`, `1.148.0-insider`, what upstream code and extensions read) and product.json `release` is the port's build of it, a positive integer in port/product.json, bumped by hand for each release and set back to 1 on every uplift; build-exthost leaves it out of the extension host's product, and `VERSION` in main.rs (what extensions see) never includes it. Users see the display version `<major>.<minor>.<patch>.<release>` with `-insider` on an Insiders build (`product::display_version`, app-files.ts `displayVersion`): `1.148.0.1`, `1.148.0.1-insider`, in About, `--version`, `--status`, the startup performance view, the update title bar and tooltip, the release notes (tag `v1.148.0.1`) and the package names. Info.plist `CFBundleShortVersionString` stays VS Code's version (Apple's three-number format; update-check reads it). The feed keeps `productVersion` semantic and adds `release`, so builds from before releases still parse the entry (they compare version and timestamp only); the port shows `productVersion` with the release. The entry is an update when its (`productVersion`, `release`, `timestamp`) is higher than the running (product.json `version`, `release`, `date`), in that order: a higher VS Code version wins whatever the releases, then a higher release whatever the timestamps; an entry or a build without `release` is release 0, a `release` that is not a non-negative integer is an error (`version`, the commit, decides nothing: builds of one commit can differ in version); a lower one never is, so switching to `latest` on a pre-release newer than the latest stable keeps it until a newer stable comes. A build without `commit` and `date` (written by package-app) has updates disabled, as upstream's without `commit`. 204, 401, 403 and 404 are no update. `url` resolves against the feed's URL and must be https (http only on 127.0.0.1 or localhost).+ Channels (port addition: setting `update.releaseChannel`, `latest` or `pre-release`, default the build's quality as upstream's channel is: `latest` on a `stable` build, `pre-release` on an Insiders one; 1.148.0.2-insider and older default to `latest` and, with no release yet off pre-release, see 404 and "no updates"; so v1.148.0.2-insider is GitHub's latest release, not marked pre-release, with the `<platform>.json` feeds too, and the next release, the first with the quality default, goes there the same way): `latest` reads `<updateUrl>/latest/download/<platform>.json`, which GitHub serves from the newest release not marked pre-release; `pre-release` reads `<updateUrl>/download/pre-release/<platform>-prerelease.json` (the arm64 names are the ones the first published build, v1.147.0-insider, reads), from a release tagged `pre-release` whose asset each publish replaces (GitHub has no "latest including pre-releases" URL). Port version (Artur): product.json `version` stays VS Code's semantic version (`1.148.0`, `1.148.0-insider`, what upstream code and extensions read) and product.json `release` is the port's build of it, a positive integer in port/product.json, bumped by hand for each release and set back to 1 on every uplift; build-exthost leaves it out of the extension host's product, and `VERSION` in main.rs (what extensions see) never includes it. Users see the display version `<major>.<minor>.<patch>.<release>` with `-insider` on an Insiders build (`product::display_version`, app-files.ts `displayVersion`): `1.148.0.1`, `1.148.0.1-insider`, in About, `--version`, `--status`, the startup performance view, the update title bar and tooltip, the release notes (tag `v1.148.0.1`) and the package names. Info.plist `CFBundleShortVersionString` stays VS Code's version (Apple's three-number format; update-check reads it). The feed keeps `productVersion` semantic and adds `release`, so builds from before releases still parse the entry (they compare version and timestamp only); the port shows `productVersion` with the release. The entry is an update when its (`productVersion`, `release`, `timestamp`) is higher than the running (product.json `version`, `release`, `date`), in that order: a higher VS Code version wins whatever the releases, then a higher release whatever the timestamps; an entry or a build without `release` is release 0, a `release` that is not a non-negative integer is an error (`version`, the commit, decides nothing: builds of one commit can differ in version); a lower one never is, so switching to `latest` on a pre-release newer than the latest stable keeps it until a newer stable comes. A build without `commit` and `date` (written by package-app) has updates disabled, as upstream's without `commit`. 204, 401, 403 and 404 are no update. `url` resolves against the feed's URL and must be https (http only on 127.0.0.1 or localhost).Publishing a release (Artur, by hand): bump `release` in port/product.json (then `port/tools/build-exthost`: package-app refuses an extension host bundle older than port/product.json), then `port/tools/package-app` (VERSION, TAG default `v<display version>`, e.g. `v1.148.0.1`, PRERELEASE=1 for a pre-release, which is a VS Code Insiders build: product.json `quality: insider` and version `<VERSION>-insider`, as gulpfile.vscode.ts writes them; builds of one Insiders version are told apart by `date`) writes next to the app, for ARCH (`arm64` or `x64`, default the host's) `VSRustium-<display version>-darwin-<arch>.zip` (`ditto -c -k --keepParent` of the signed app; e.g. `VSRustium-1.148.0.1-insider-darwin-arm64.zip`), `darwin-<arch>-prerelease.json` and, unless PRERELEASE=1, `darwin-<arch>.json`; the feed `url` names the versioned zip. Run it once per arch (the x64 one after `cargo build --release -p app --target x86_64-apple-darwin`). Upload both zips and both `darwin-<arch>.json` to the release TAG (marked pre-release for a pre-release), and both `darwin-<arch>-prerelease.json` to the `pre-release` release, replacing its assets (a stable release goes there too, so pre-release users get it). A Linux build names its archive `VSRustium-<display version>-linux-<arch>.tar.gz` the same way, and its `VSRustium-<display version>-linux-<arch>.AppImage`, uploaded beside the archive (no feed names it). Extensions see the API version (`VERSION` in main.rs, 1.147.0, with `-<quality>` on a non-stable build), not product.json `version`: on an Insiders build `vscode.version` is `1.147.0-insider` and `env.appQuality` `insider`, what extensions test for VS Code Insiders (copilot's completions `vscode.version.endsWith('-insider')`, tunnel-forwarding's `appQuality`, a `resolvers` proposal). `env.appName` stays `VSRustium` (branding (1) below); the one `appName.includes('Insiders')` check upstream is the Copilot extension's, which the port does not ship. `engines.vscode` checks use the same string; as extensionValidator.ts, `-insider` in a range or version decides nothing, only the numbers (`cargo test -p exthost insider_engines`; update-check installs the Open VSX VSIX of `[email protected]`, engines `^1.89.0-insider`, in P and activates it, and installs the pre-release of `rust-lang.rust-analyzer` from the gallery (`installPreReleaseVersion`, publisher trust answered) and activates it as one).- Update service (`update.rs`, `update/install.rs`, updateService.darwin.ts with Squirrel.Mac's part): one per app, created with the first window; `update.mode` as upstream (`none` disables and drops a pending download, `manual`, `start` 30 s after startup, `default` also hourly). A check first refuses a bundle it cannot replace (App Translocation, a read-only volume, no write access) with Squirrel's message, then reads the feed; a newer build downloads at once with curl into `~/Library/Caches/com.rokartur.vsrustium.ShipIt/update` (progress from the file size and Content-Length), then is verified: the zip's SHA-256 against the feed, `ditto -x -k`, exactly one `.app`, `codesign --verify --deep --strict` against the installed app's designated requirement (Squirrel's check: an Apple-issued certificate, the Team ID and the bundle id) and the same `Identifier` and `TeamIdentifier`; an ad-hoc signed installed app verifies nothing. States: Uninitialized, Disabled, Idle, CheckingForUpdates, AvailableForDownload, Downloading, Downloaded, Ready, Restarting; an error goes back to Idle, with its message only for an explicit check (upstream). On a metered connection (`network.meteredConnection` or the OS's) an automatic check is skipped, and an update an automatic check found waits as AvailableForDownload; both resume once the connection is not metered (abstractUpdateService.ts). Not reached: Updating (Windows), Overwriting, Cancelling.ShipIt (`vsrustium --apply-update <pid> <staged> <installed> [--relaunch <args>]`, logging to `ShipIt_stderr.log` in the ShipIt folder): Restart to Update quits every window (a veto puts Ready back) and the helper starts on app quit; a plain Quit while Ready installs too, without relaunch (Squirrel installs a downloaded update on quit). The helper waits for the app's pid to exit, verifies the staged bundle again, renames the installed app to `.VSRustium.app.old`, moves the update in (a ditto copy across volumes) or on any failure puts the old one back, relaunches the executable with the app's arguments, then deletes the old copy.