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
25 changes: 25 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ objc2-application-services = { version = "0.3.2", default-features = false, feat
] }
objc2-core-foundation = "0.3.2"
objc2-foundation = { version = "0.3.2", features = ["NSString"] }
objc2-service-management = "0.3.2"
once_cell = "1.21.3"
rand = "0.9.2"
rayon = "1.11.0"
Expand Down
1 change: 1 addition & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ pub enum Editable<T> {
pub enum Message {
WriteConfig(bool),
SaveRanking,
ToggleAutoStartup(bool),
LoadRanking,
ToggleFavouriteApp(String),
UpdateAvailable,
Expand Down
11 changes: 11 additions & 0 deletions src/app/pages/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,16 @@ pub fn settings_page(config: Config) -> Element<'static, Message> {
),
]);

let theme_clone = theme.clone();
let start_at_login = settings_item_row([
settings_hint_text(theme.clone(), "Start at login"),
checkbox(config.clone().start_at_login)
.style(move |_, _| settings_checkbox_style(&theme_clone))
.on_toggle(Message::ToggleAutoStartup)
.into(),
notice_item(theme.clone(), "If you want rustcast to start on login"),
]);

let theme_clone = theme.clone();
let haptic = Row::from_iter([
settings_hint_text(theme.clone(), "Haptic feedback"),
Expand Down Expand Up @@ -394,6 +404,7 @@ pub fn settings_page(config: Config) -> Element<'static, Message> {
placeholder_setting.into(),
search.into(),
debounce.into(),
start_at_login.into(),
haptic.into(),
tray_icon.into(),
auto_suggest.into(),
Expand Down
12 changes: 12 additions & 0 deletions src/app/tile/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ use crate::commands::Function;
use crate::config::Config;
use crate::config::MainPage;
use crate::debounce::DebouncePolicy;
use crate::platform::macos::{start_at_login, stop_at_login};
use crate::quit::get_open_apps;
use crate::unit_conversion;
use crate::utils::is_valid_url;
Expand Down Expand Up @@ -96,6 +97,17 @@ pub fn handle_update(tile: &mut Tile, message: Message) -> Task<Message> {
Task::none()
}

Message::ToggleAutoStartup(set_to) => {
if set_to {
start_at_login();
tile.config.start_at_login = true
} else {
stop_at_login();
tile.config.start_at_login = false
}
Task::none()
}

Message::EscKeyPressed(id) => {
if !tile.query_lc.is_empty() {
return Task::batch([
Expand Down
2 changes: 2 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub struct Config {
pub clipboard_hotkey: String,
pub buffer_rules: Buffer,
pub main_page: MainPage,
pub start_at_login: bool,
pub theme: Theme,
pub placeholder: String,
pub search_url: String,
Expand All @@ -42,6 +43,7 @@ impl Default for Config {
clipboard_hotkey: "SUPER+SHIFT+C".to_string(),
buffer_rules: Buffer::default(),
theme: Theme::default(),
start_at_login: true,
placeholder: String::from("Time to be productive!"),
search_url: "https://duckduckgo.com/search?q=%s".to_string(),
haptic_feedback: false,
Expand Down
5 changes: 4 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use std::{fs::OpenOptions, path::Path};
use crate::{
app::tile::{self, Tile},
config::Config,
platform::macos::get_autostart_status,
};

use global_hotkey::{
Expand All @@ -43,11 +44,13 @@ fn main() -> iced::Result {
.unwrap();
}

let config: Config = match std::fs::read_to_string(&file_path) {
let mut config: Config = match std::fs::read_to_string(&file_path) {
Ok(a) => toml::from_str(&a).unwrap_or(Config::default()),
Err(_) => Config::default(),
};

config.start_at_login = get_autostart_status();

if cfg!(debug_assertions) {
let sub = tracing_subscriber::fmt().finish();
EnvFilter::new("rustcast=info").with_subscriber(sub).init();
Expand Down
Empty file added src/platform/macos/login.rs
Empty file.
25 changes: 25 additions & 0 deletions src/platform/macos/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,31 @@ use iced::wgpu::rwh::WindowHandle;
pub(super) use self::discovery::get_installed_apps;
pub(super) use self::haptics::perform_haptic;

use objc2_service_management::SMAppService;

pub fn start_at_login() {
unsafe {
SMAppService::mainAppService().registerAndReturnError().ok();
}
}

pub fn stop_at_login() {
unsafe {
SMAppService::mainAppService()
.unregisterAndReturnError()
.ok();
}
}

pub fn get_autostart_status() -> bool {
unsafe {
SMAppService::mainAppService()
.registerAndReturnError()
.ok()
.is_some()
}
}

/// This sets the activation policy of the app to Accessory, allowing rustcast to be visible ontop
/// of fullscreen apps
pub(super) fn set_activation_policy_accessory() {
Expand Down
Loading