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
This commit is contained in:
Vítor Vasconcellos 2024-05-29 01:26:33 -03:00 committed by GitHub
parent b7c3eb6f5c
commit 4a62d268ef
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 35 additions and 21 deletions

View file

@ -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?

View file

@ -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);
// }

View file

@ -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(),
);
};
}
});

View file

@ -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",