Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ tauri = {version = "2.9", features = ["tray-icon"] }
tauri-plugin-dialog = "2"
tauri-plugin-log = "2.7"
tauri-plugin-opener = "2.5"
tauri-plugin-autostart = "2"

# Sendspin native client
# Using phase3-artwork-visualizer branch for full protocol support (commands, state, artwork)
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/capabilities/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"identifier": "default",
"description": "enables the default permissions",
"windows": ["main"],
"permissions": ["core:default", "opener:default"]
"permissions": ["core:default", "opener:default", "autostart:allow-enable", "autostart:allow-disable", "autostart:allow-is-enabled"]
}
8 changes: 6 additions & 2 deletions src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ mod settings;

use mdns_discovery::DiscoveredServer;
use now_playing::NowPlaying;
use tauri_plugin_autostart::MacosLauncher;

static SERVICES_STARTER: Once = Once::new();

Expand Down Expand Up @@ -344,8 +345,8 @@ fn get_settings() -> settings::Settings {

/// Set a single setting
#[tauri::command]
fn set_setting(key: String, value: bool) -> Result<(), String> {
settings::set_setting(&key, value)
fn set_setting(app: tauri::AppHandle, key: String, value: bool) -> Result<(), String> {
settings::set_setting(app, &key, value)
}

/// Set a string setting
Expand Down Expand Up @@ -490,6 +491,9 @@ pub fn run() {
builder
.plugin(tauri_plugin_dialog::init())
.plugin(tauri_plugin_opener::init())
.plugin(tauri_plugin_autostart::init(
MacosLauncher::AppleScript,
None,))
.plugin(tauri_plugin_updater::Builder::new().build())
.invoke_handler(tauri::generate_handler![
is_companion_app,
Expand Down
18 changes: 11 additions & 7 deletions src-tauri/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use serde::{Deserialize, Serialize};
use std::fs;
use std::path::PathBuf;
use std::sync::RwLock;
use tauri_plugin_autostart::ManagerExt;

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[serde(rename_all = "lowercase")]
Expand Down Expand Up @@ -148,7 +149,7 @@ pub fn get_settings() -> Settings {
.map_or_else(|_| Settings::default(), |s| s.clone())
}

pub fn set_setting(key: &str, value: bool) -> Result<(), String> {
pub fn set_setting(app: tauri::AppHandle, key: &str, value: bool) -> Result<(), String> {
let mut settings = get_settings();

match key {
Expand All @@ -166,7 +167,7 @@ pub fn set_setting(key: &str, value: bool) -> Result<(), String> {
// Handle autostart registration
#[cfg(desktop)]
{
set_autostart(value);
set_autostart(value, app);
}
}
"sendspin_enabled" => {
Expand Down Expand Up @@ -230,9 +231,12 @@ pub fn set_int_setting(key: &str, value: i32) -> Result<(), String> {
}

#[cfg(desktop)]
fn set_autostart(_enabled: bool) {
// TODO: Platform-specific autostart implementation
// macOS: launchd or Login Items
// Windows: registry or Task Scheduler
// Linux: .desktop file in autostart
fn set_autostart(enabled: bool, app: tauri::AppHandle) {
let autostart_manager = app.autolaunch();

if enabled {
let _ = autostart_manager.enable();
} else {
let _ = autostart_manager.disable();
}
}
Loading