gpui: Make MacPlatform::os_version infallible (#29008)

Core change:
```rust
fn os_version() -> Result<SemanticVersion>
```

```rust
fn os_version() -> SemanticVersion
```


Release Notes:

- N/A
This commit is contained in:
tidely 2025-04-18 20:00:43 +03:00 committed by GitHub
parent 4405ed04d0
commit 1e0ae35f69
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -353,8 +353,7 @@ impl MacPlatform {
ns_string(key_to_native(&keystroke.key).as_ref()), ns_string(key_to_native(&keystroke.key).as_ref()),
) )
.autorelease(); .autorelease();
if MacPlatform::os_version().unwrap() >= SemanticVersion::new(12, 0, 0) if Self::os_version() >= SemanticVersion::new(12, 0, 0) {
{
let _: () = msg_send![item, setAllowsAutomaticKeyEquivalentLocalization: NO]; let _: () = msg_send![item, setAllowsAutomaticKeyEquivalentLocalization: NO];
} }
item.setKeyEquivalentModifierMask_(mask); item.setKeyEquivalentModifierMask_(mask);
@ -402,16 +401,16 @@ impl MacPlatform {
} }
} }
fn os_version() -> Result<SemanticVersion> { fn os_version() -> SemanticVersion {
unsafe { let version = unsafe {
let process_info = NSProcessInfo::processInfo(nil); let process_info = NSProcessInfo::processInfo(nil);
let version = process_info.operatingSystemVersion(); process_info.operatingSystemVersion()
Ok(SemanticVersion::new( };
version.majorVersion as usize, SemanticVersion::new(
version.minorVersion as usize, version.majorVersion as usize,
version.patchVersion as usize, version.minorVersion as usize,
)) version.patchVersion as usize,
} )
} }
} }
@ -609,7 +608,7 @@ impl Platform for MacPlatform {
// API only available post Monterey // API only available post Monterey
// https://developer.apple.com/documentation/appkit/nsworkspace/3753004-setdefaultapplicationaturl // https://developer.apple.com/documentation/appkit/nsworkspace/3753004-setdefaultapplicationaturl
let (done_tx, done_rx) = oneshot::channel(); let (done_tx, done_rx) = oneshot::channel();
if Self::os_version().ok() < Some(SemanticVersion::new(12, 0, 0)) { if Self::os_version() < SemanticVersion::new(12, 0, 0) {
return Task::ready(Err(anyhow!( return Task::ready(Err(anyhow!(
"macOS 12.0 or later is required to register URL schemes" "macOS 12.0 or later is required to register URL schemes"
))); )));
@ -736,9 +735,7 @@ impl Platform for MacPlatform {
// you can manually create a file called `a.sql.s`. That said it seems better // you can manually create a file called `a.sql.s`. That said it seems better
// to break that use-case than breaking `a.sql`. // to break that use-case than breaking `a.sql`.
if chunks.len() == 3 && chunks[1].starts_with(chunks[2]) { if chunks.len() == 3 && chunks[1].starts_with(chunks[2]) {
if Self::os_version() if Self::os_version() >= SemanticVersion::new(15, 0, 0) {
.is_ok_and(|v| v >= SemanticVersion::new(15, 0, 0))
{
let new_filename = OsStr::from_bytes( let new_filename = OsStr::from_bytes(
&filename.as_bytes() &filename.as_bytes()
[..chunks[0].len() + 1 + chunks[1].len()], [..chunks[0].len() + 1 + chunks[1].len()],