From 4a62d268efea7dd6ff573531b1e2b2970c7ba562 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADtor=20Vasconcellos?= Date: Wed, 29 May 2024 01:26:33 -0300 Subject: [PATCH] Disable AppNap for macOS and fix app version in deb (#2517) * Remove version field from tauri conf - Let tauri default to the version from Cargo.toml * Allow app to toggle app nap --- .../crates/macos/src-swift/window.swift | 29 +++++++++++++++++++ apps/desktop/crates/macos/src/lib.rs | 21 ++------------ apps/desktop/src-tauri/src/main.rs | 5 +++- apps/desktop/src-tauri/tauri.conf.json | 1 - 4 files changed, 35 insertions(+), 21 deletions(-) diff --git a/apps/desktop/crates/macos/src-swift/window.swift b/apps/desktop/crates/macos/src-swift/window.swift index b969965a5..e5f50f871 100644 --- a/apps/desktop/crates/macos/src-swift/window.swift +++ b/apps/desktop/crates/macos/src-swift/window.swift @@ -1,4 +1,5 @@ import AppKit +import SwiftRs @objc public enum AppThemeType: Int { @@ -7,6 +8,34 @@ public enum AppThemeType: Int { case dark = 1 } +var activity: NSObjectProtocol? + +@_cdecl("disable_app_nap") +public func disableAppNap(reason: SRString) -> Bool { + // Check if App Nap is already disabled + guard activity == nil else { + return false + } + + activity = ProcessInfo.processInfo.beginActivity( + options: .userInitiatedAllowingIdleSystemSleep, + reason: reason.toString() + ) + return true +} + +@_cdecl("enable_app_nap") +public func enableAppNap() -> Bool { + // Check if App Nap is already enabled + guard let pinfo = activity else { + return false + } + + ProcessInfo.processInfo.endActivity(pinfo) + activity = nil + return true +} + @_cdecl("lock_app_theme") public func lockAppTheme(themeType: AppThemeType) { var theme: NSAppearance? diff --git a/apps/desktop/crates/macos/src/lib.rs b/apps/desktop/crates/macos/src/lib.rs index 7986de5b0..9a1e07d92 100644 --- a/apps/desktop/crates/macos/src/lib.rs +++ b/apps/desktop/crates/macos/src/lib.rs @@ -9,10 +9,10 @@ pub enum AppThemeType { Dark = 1 as Int, } +swift!(pub fn disable_app_nap(reason: &SRString) -> Bool); +swift!(pub fn enable_app_nap() -> Bool); swift!(pub fn lock_app_theme(theme_type: Int)); swift!(pub fn set_titlebar_style(window: &NSObject, is_fullscreen: Bool)); -// swift!(pub fn setup_disk_watcher(window: &NSObject, transparent: Bool, large: Bool)); -// swift!(pub fn disk_event_callback(mounted: Bool, path: &SRString)); swift!(pub fn reload_webview(webview: &NSObject)); #[repr(C)] @@ -30,20 +30,3 @@ pub fn open_file_paths_with(file_urls: &[String], with_url: &str) { let file_url = file_urls.join("\0"); unsafe { open_file_path_with(&file_url.as_str().into(), &with_url.into()) } } - -// main!(|_| { -// unsafe { setup_disk_watcher() }; -// print!("Waiting for disk events... "); -// Ok(()) -// }); - -// #[no_mangle] -// pub extern "C" fn disk_event_callback(mounted: Bool, path: *const SRString) { -// let mounted_str = if mounted { "mounted" } else { "unmounted" }; - -// // Convert the raw pointer to a reference -// let path_ref = unsafe { &*path }; -// let path_str = path_ref.to_string(); // Assuming SRString has a to_string method - -// println!("Disk at path {} was {}", path_str, mounted_str); -// } diff --git a/apps/desktop/src-tauri/src/main.rs b/apps/desktop/src-tauri/src/main.rs index 92f13eec5..0491784c2 100644 --- a/apps/desktop/src-tauri/src/main.rs +++ b/apps/desktop/src-tauri/src/main.rs @@ -289,7 +289,10 @@ async fn main() -> tauri::Result<()> { sd_desktop_macos::set_titlebar_style( &window.ns_window().expect("NSWindows must exist on macOS"), false, - ) + ); + sd_desktop_macos::disable_app_nap( + &"File indexer needs to run unimpeded".into(), + ); }; } }); diff --git a/apps/desktop/src-tauri/tauri.conf.json b/apps/desktop/src-tauri/tauri.conf.json index bec72554e..bb3efbb7a 100644 --- a/apps/desktop/src-tauri/tauri.conf.json +++ b/apps/desktop/src-tauri/tauri.conf.json @@ -1,7 +1,6 @@ { "$schema": "https://github.com/tauri-apps/tauri/raw/tauri-v2.0.0-beta.17/core/tauri-config-schema/schema.json", "productName": "Spacedrive", - "version": "0.2.13", "identifier": "com.spacedrive.desktop", "build": { "beforeDevCommand": "pnpm dev",