fix(macos): drop in-app self-update
Swapping the Mach-O inside a .app breaks a signed bundle. The release stays the .app zip; Windows and Linux updates are unchanged.
@@ -28,15 +28,11 @@ const EXECUTABLE_MAGIC: &[u8] = b"MZ";
28
28
const ASSET_SUFFIX: &str = "-linux-amd64";
29
29
#[cfg(target_os = "linux")]
30
30
const EXECUTABLE_MAGIC: &[u8] = b"\x7fELF";
31
/// Universal Mach-O from `scripts/build-macos.sh` (lipo fat binary, not the .app zip).
32
#[cfg(target_os = "macos")]
33
const ASSET_SUFFIX: &str = "-macos-universal";
34
#[cfg(target_os = "macos")]
35
const EXECUTABLE_MAGIC: &[u8] = b"\xca\xfe\xba\xbe";
36
/// Other targets still compile. The suffix matches no release asset, so the feed stays idle.
37
#[cfg(not(any(windows, target_os = "linux", target_os = "macos")))]
31
/// macOS and any other target still compile. The suffix matches no release asset,
32
/// so the feed stays idle. macOS updates by replacing the `.app`, not a Mach-O in place.
33
#[cfg(not(any(windows, target_os = "linux")))]
38
34
const ASSET_SUFFIX: &str = "-unsupported";
39
#[cfg(not(any(windows, target_os = "linux", target_os = "macos")))]
35
#[cfg(not(any(windows, target_os = "linux")))]
40
36
const EXECUTABLE_MAGIC: &[u8] = b"\0unsupported";
41
37
const PARTIAL_SUFFIX: &str = ".partial";
42
38
const DOWNLOAD_CHUNK: usize = 64 * 1024;
@@ -28,15 +28,11 @@ const EXECUTABLE_MAGIC: &[u8] = b"MZ";28
const ASSET_SUFFIX: &str = "-linux-amd64";28
const ASSET_SUFFIX: &str = "-linux-amd64";29
#[cfg(target_os = "linux")]29
#[cfg(target_os = "linux")]30
const EXECUTABLE_MAGIC: &[u8] = b"\x7fELF";30
const EXECUTABLE_MAGIC: &[u8] = b"\x7fELF";31
/// Universal Mach-O from `scripts/build-macos.sh` (lipo fat binary, not the .app zip).31
/// macOS and any other target still compile. The suffix matches no release asset,32
#[cfg(target_os = "macos")]32
/// so the feed stays idle. macOS updates by replacing the `.app`, not a Mach-O in place.33
const ASSET_SUFFIX: &str = "-macos-universal";33
#[cfg(not(any(windows, target_os = "linux")))]34
#[cfg(target_os = "macos")]35
const EXECUTABLE_MAGIC: &[u8] = b"\xca\xfe\xba\xbe";36
/// Other targets still compile. The suffix matches no release asset, so the feed stays idle.37
#[cfg(not(any(windows, target_os = "linux", target_os = "macos")))]38
const ASSET_SUFFIX: &str = "-unsupported";34
const ASSET_SUFFIX: &str = "-unsupported";39
#[cfg(not(any(windows, target_os = "linux", target_os = "macos")))]35
#[cfg(not(any(windows, target_os = "linux")))]40
const EXECUTABLE_MAGIC: &[u8] = b"\0unsupported";36
const EXECUTABLE_MAGIC: &[u8] = b"\0unsupported";41
const PARTIAL_SUFFIX: &str = ".partial";37
const PARTIAL_SUFFIX: &str = ".partial";42
const DOWNLOAD_CHUNK: usize = 64 * 1024;38
const DOWNLOAD_CHUNK: usize = 64 * 1024;@@ -266,8 +266,8 @@ mod platform {
266
266
267
267
/// Whether this build may replace itself from GitHub releases. On Linux only the copy
268
268
/// installed in `~/.local/share/rusty-teams` updates; a binary run from a
269
/// build folder or a package location is left alone. On macOS only an unsigned `.app`
270
/// may swap its Mach-O; a signed or notarized bundle would fail Gatekeeper after that.
269
/// build folder or a package location is left alone. macOS ships a `.app` and does not
270
/// swap its Mach-O in place.
271
271
pub fn self_update_allowed() -> bool {
272
272
#[cfg(target_os = "linux")]
273
273
{
@@ -276,52 +276,16 @@ pub fn self_update_allowed() -> bool {
276
276
.is_some_and(|layout| crate::linux_desktop::is_installed(&executable, &layout))
277
277
});
278
278
}
279
#[cfg(target_os = "macos")]
280
{
281
return std::env::current_exe().is_ok_and(|executable| {
282
let Some(bundle) = app_bundle(&executable) else {
283
return false;
284
};
285
macos_self_update_ok(&executable, bundle_is_signed(bundle))
286
});
287
}
288
279
#[cfg(windows)]
289
280
{
290
281
return true;
291
282
}
292
#[cfg(not(any(windows, target_os = "linux", target_os = "macos")))]
283
#[cfg(not(any(windows, target_os = "linux")))]
293
284
{
294
285
false
295
286
}
296
287
}
297
288
298
#[cfg(any(test, target_os = "macos"))]
299
fn app_bundle(executable: &Path) -> Option<&Path> {
300
executable.ancestors().find(|path| {
301
path.file_name()
302
.and_then(|name| name.to_str())
303
.is_some_and(|name| name.ends_with(".app"))
304
})
305
}
306
307
/// `signed` is the `codesign` result for the bundle. A signed Mach-O must stay put.
308
#[cfg(any(test, target_os = "macos"))]
309
fn macos_self_update_ok(executable: &Path, signed: bool) -> bool {
310
app_bundle(executable).is_some() && !signed
311
}
312
313
#[cfg(target_os = "macos")]
314
fn bundle_is_signed(bundle: &Path) -> bool {
315
match Command::new("/usr/bin/codesign")
316
.args(["--verify", "--strict"])
317
.arg(bundle)
318
.output()
319
{
320
Ok(output) => output.status.success(),
321
Err(_) => true,
322
}
323
}
324
325
289
/// Reading the new exe once lets the virus scanner finish before the restart, which otherwise blocks process start for seconds.
326
290
pub fn prescan(update_exe: &Path) {
327
291
if let Ok(mut file) = std::fs::File::open(update_exe) {
@@ -390,15 +354,6 @@ mod tests {
390
354
assert!(!update_is_ready("a-1", Some(" \n"), true));
391
355
}
392
356
393
#[test]
394
fn macos_self_update_stays_off_for_a_signed_bundle() {
395
let executable = Path::new("/Applications/RustyTeams.app/Contents/MacOS/teams");
396
assert!(macos_self_update_ok(executable, false));
397
assert!(!macos_self_update_ok(executable, true));
398
assert!(!macos_self_update_ok(Path::new("/tmp/teams"), false));
399
assert!(app_bundle(executable).is_some());
400
}
401
402
357
#[test]
403
358
fn plan_lists_the_operations_in_order() {
404
359
let paths = UpdatePaths::beside(&Path::new("/app").join(EXE_NAME));
@@ -266,8 +266,8 @@ mod platform {266
266
267
/// Whether this build may replace itself from GitHub releases. On Linux only the copy267
/// Whether this build may replace itself from GitHub releases. On Linux only the copy268
/// installed in `~/.local/share/rusty-teams` updates; a binary run from a268
/// installed in `~/.local/share/rusty-teams` updates; a binary run from a269
/// build folder or a package location is left alone. On macOS only an unsigned `.app`269
/// build folder or a package location is left alone. macOS ships a `.app` and does not270
/// may swap its Mach-O; a signed or notarized bundle would fail Gatekeeper after that.270
/// swap its Mach-O in place.271
pub fn self_update_allowed() -> bool {271
pub fn self_update_allowed() -> bool {272
#[cfg(target_os = "linux")]272
#[cfg(target_os = "linux")]273
{273
{@@ -276,52 +276,16 @@ pub fn self_update_allowed() -> bool {276
.is_some_and(|layout| crate::linux_desktop::is_installed(&executable, &layout))276
.is_some_and(|layout| crate::linux_desktop::is_installed(&executable, &layout))277
});277
});278
}278
}279
#[cfg(target_os = "macos")]280
{281
return std::env::current_exe().is_ok_and(|executable| {282
let Some(bundle) = app_bundle(&executable) else {283
return false;284
};285
macos_self_update_ok(&executable, bundle_is_signed(bundle))286
});287
}288
#[cfg(windows)]279
#[cfg(windows)]289
{280
{290
return true;281
return true;291
}282
}292
#[cfg(not(any(windows, target_os = "linux", target_os = "macos")))]283
#[cfg(not(any(windows, target_os = "linux")))]293
{284
{294
false285
false295
}286
}296
}287
}297
288
298
#[cfg(any(test, target_os = "macos"))]299
fn app_bundle(executable: &Path) -> Option<&Path> {300
executable.ancestors().find(|path| {301
path.file_name()302
.and_then(|name| name.to_str())303
.is_some_and(|name| name.ends_with(".app"))304
})305
}306
307
/// `signed` is the `codesign` result for the bundle. A signed Mach-O must stay put.308
#[cfg(any(test, target_os = "macos"))]309
fn macos_self_update_ok(executable: &Path, signed: bool) -> bool {310
app_bundle(executable).is_some() && !signed311
}312
313
#[cfg(target_os = "macos")]314
fn bundle_is_signed(bundle: &Path) -> bool {315
match Command::new("/usr/bin/codesign")316
.args(["--verify", "--strict"])317
.arg(bundle)318
.output()319
{320
Ok(output) => output.status.success(),321
Err(_) => true,322
}323
}324
325
/// Reading the new exe once lets the virus scanner finish before the restart, which otherwise blocks process start for seconds.289
/// Reading the new exe once lets the virus scanner finish before the restart, which otherwise blocks process start for seconds.326
pub fn prescan(update_exe: &Path) {290
pub fn prescan(update_exe: &Path) {327
if let Ok(mut file) = std::fs::File::open(update_exe) {291
if let Ok(mut file) = std::fs::File::open(update_exe) {@@ -390,15 +354,6 @@ mod tests {390
assert!(!update_is_ready("a-1", Some(" \n"), true));354
assert!(!update_is_ready("a-1", Some(" \n"), true));391
}355
}392
356
393
#[test]394
fn macos_self_update_stays_off_for_a_signed_bundle() {395
let executable = Path::new("/Applications/RustyTeams.app/Contents/MacOS/teams");396
assert!(macos_self_update_ok(executable, false));397
assert!(!macos_self_update_ok(executable, true));398
assert!(!macos_self_update_ok(Path::new("/tmp/teams"), false));399
assert!(app_bundle(executable).is_some());400
}401
402
#[test]357
#[test]403
fn plan_lists_the_operations_in_order() {358
fn plan_lists_the_operations_in_order() {404
let paths = UpdatePaths::beside(&Path::new("/app").join(EXE_NAME));359
let paths = UpdatePaths::beside(&Path::new("/app").join(EXE_NAME));@@ -22,7 +22,6 @@ Run on a real Mac (`.app` from `scripts/build-macos.sh` or a release zip). Unit
22
22
1. Menu-bar tray icon appears; Open / presence / Quit work.
23
23
2. Settings → General → Close to tray: close hides/reopens via the tray (new window path like Linux).
24
24
3. Incoming chat still uses in-app toasts on this branch (Notification Center is a follow-up after the Linux desktop-toast path).
25
4. From an installed `.app` under `/Applications` (or any `*.app/Contents/MacOS/…` path), Settings can offer a self-update when a newer `*-macos-universal` release asset exists.
26
25
27
26
## Packaging
28
27
@@ -22,7 +22,6 @@ Run on a real Mac (`.app` from `scripts/build-macos.sh` or a release zip). Unit22
1. Menu-bar tray icon appears; Open / presence / Quit work.22
1. Menu-bar tray icon appears; Open / presence / Quit work.23
2. Settings → General → Close to tray: close hides/reopens via the tray (new window path like Linux).23
2. Settings → General → Close to tray: close hides/reopens via the tray (new window path like Linux).24
3. Incoming chat still uses in-app toasts on this branch (Notification Center is a follow-up after the Linux desktop-toast path).24
3. Incoming chat still uses in-app toasts on this branch (Notification Center is a follow-up after the Linux desktop-toast path).25
4. From an installed `.app` under `/Applications` (or any `*.app/Contents/MacOS/…` path), Settings can offer a self-update when a newer `*-macos-universal` release asset exists.26
25
27
## Packaging26
## Packaging28
27
@@ -1,7 +1,7 @@
1
1
#!/usr/bin/env bash
2
2
# Build a universal macOS binary (arm64 + x86_64) from a crate. Needs Xcode CLT only.
3
3
# Wraps it in a .app bundle (icon, Info.plist) and zips that for distribution.
4
# Also keeps the bare lipo binary for self-update (release asset *-macos-universal).
4
# The published artifact is the `.app` zip. There is no in-app Mach-O swap.
5
5
#
6
6
# Optional signing / notarization when Apple credentials are present:
7
7
# MACOS_CODESIGN_IDENTITY e.g. "Developer ID Application: …"
@@ -123,10 +123,6 @@ fi
123
123
# ditto keeps the bundle intact (plain zip would not); the result is the .app release asset.
124
124
ditto -c -k --keepParent "$app" "$outputDirectory/teams-macos.zip"
125
125
126
# Bare universal binary for in-app self-update (Mach-O fat; magic cafe babe).
127
cp "$output" "$outputDirectory/teams-macos-universal"
128
chmod +x "$outputDirectory/teams-macos-universal"
129
130
126
if [ -n "${MACOS_CODESIGN_IDENTITY:-}" ] && [ -n "${MACOS_NOTARY_PROFILE:-}" ]; then
131
127
echo "notarize with profile $MACOS_NOTARY_PROFILE"
132
128
xcrun notarytool submit "$outputDirectory/teams-macos.zip" \
@@ -139,4 +135,4 @@ fi
139
135
140
136
file "$output"
141
137
ls -la "$output" "$app/Contents/MacOS/$binary" \
142
"$outputDirectory/teams-macos.zip" "$outputDirectory/teams-macos-universal"
138
"$outputDirectory/teams-macos.zip"
@@ -1,7 +1,7 @@1
#!/usr/bin/env bash1
#!/usr/bin/env bash2
# Build a universal macOS binary (arm64 + x86_64) from a crate. Needs Xcode CLT only.2
# Build a universal macOS binary (arm64 + x86_64) from a crate. Needs Xcode CLT only.3
# Wraps it in a .app bundle (icon, Info.plist) and zips that for distribution.3
# Wraps it in a .app bundle (icon, Info.plist) and zips that for distribution.4
# Also keeps the bare lipo binary for self-update (release asset *-macos-universal).4
# The published artifact is the `.app` zip. There is no in-app Mach-O swap.5
#5
#6
# Optional signing / notarization when Apple credentials are present:6
# Optional signing / notarization when Apple credentials are present:7
# MACOS_CODESIGN_IDENTITY e.g. "Developer ID Application: …"7
# MACOS_CODESIGN_IDENTITY e.g. "Developer ID Application: …"@@ -123,10 +123,6 @@ fi123
# ditto keeps the bundle intact (plain zip would not); the result is the .app release asset.123
# ditto keeps the bundle intact (plain zip would not); the result is the .app release asset.124
ditto -c -k --keepParent "$app" "$outputDirectory/teams-macos.zip"124
ditto -c -k --keepParent "$app" "$outputDirectory/teams-macos.zip"125
125
126
# Bare universal binary for in-app self-update (Mach-O fat; magic cafe babe).127
cp "$output" "$outputDirectory/teams-macos-universal"128
chmod +x "$outputDirectory/teams-macos-universal"129
130
if [ -n "${MACOS_CODESIGN_IDENTITY:-}" ] && [ -n "${MACOS_NOTARY_PROFILE:-}" ]; then126
if [ -n "${MACOS_CODESIGN_IDENTITY:-}" ] && [ -n "${MACOS_NOTARY_PROFILE:-}" ]; then131
echo "notarize with profile $MACOS_NOTARY_PROFILE"127
echo "notarize with profile $MACOS_NOTARY_PROFILE"132
xcrun notarytool submit "$outputDirectory/teams-macos.zip" \128
xcrun notarytool submit "$outputDirectory/teams-macos.zip" \@@ -139,4 +135,4 @@ fi139
135
140
file "$output"136
file "$output"141
ls -la "$output" "$app/Contents/MacOS/$binary" \137
ls -la "$output" "$app/Contents/MacOS/$binary" \142
"$outputDirectory/teams-macos.zip" "$outputDirectory/teams-macos-universal"138
"$outputDirectory/teams-macos.zip"