Skip to content

Commit

Permalink
feat(all): open on startup and start minimized
Browse files Browse the repository at this point in the history
  • Loading branch information
SpikeHD committed Sep 9, 2023
1 parent 48b6566 commit 66f8f46
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 12 deletions.
35 changes: 33 additions & 2 deletions src-tauri/Cargo.lock

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

3 changes: 3 additions & 0 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ sysinfo = { version = "0.26.8" }
tide = "0.16.0"
urlencoding = "2.1.3"

# launch on startup
auto-launch = { git = "https://github.com/OmegaJak/auto-launch/", branch = "report_task_manager_disabled_as_disabled" }

[target."cfg(any(target_os = \"linux\", target_os = \"dragonfly\", target_os = \"freebsd\", target_os = \"openbsd\", target_os = \"netbsd\"))".dependencies]
webkit2gtk = "0.18.2"

Expand Down
6 changes: 3 additions & 3 deletions src-tauri/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub struct Config {
pub streamer_mode_detection: Option<bool>,
pub rpc_server: Option<bool>,
pub open_on_startup: Option<bool>,
pub startup_minimize: Option<bool>
pub startup_minimized: Option<bool>
}

pub fn init() {
Expand Down Expand Up @@ -61,7 +61,7 @@ pub fn default_config() -> Config {
streamer_mode_detection: Option::from(false),
rpc_server: Option::from(false),
open_on_startup: Option::from(false),
startup_minimize: Option::from(false)
startup_minimized: Option::from(false)
}
}

Expand Down Expand Up @@ -153,5 +153,5 @@ pub fn get_open_on_startup() -> bool {
pub fn get_startup_minimize() -> bool {
let parsed: Config =
serde_json::from_str(read_config_file().as_str()).unwrap_or_else(|_| default_config());
parsed.startup_minimize.unwrap_or(false)
parsed.startup_minimized.unwrap_or(false)
}
42 changes: 35 additions & 7 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
)]

use std::time::Duration;
use auto_launch::*;

use config::{get_client_type, get_start_maximized};
use injection::{injection_runner, local_html, plugin, theme};
Expand Down Expand Up @@ -206,6 +207,8 @@ fn main() {

modify_window(&win);

setup_autostart(app);

#[cfg(not(target_os = "macos"))]
hotkeys::start_hotkey_watcher(win.clone());

Expand Down Expand Up @@ -250,16 +253,41 @@ fn close(win: Window) {
* Applies various window modifications, most being platform-dependent
*/
fn modify_window(window: &Window) {
let startup = std::env::args().any(|arg| arg == "--startup");

// If we are opening on startup (which we know from the --startup arg), check to minimize the window
if startup {
if config::get_startup_minimize() {
window.hide().unwrap_or_default();
}
}

if get_start_maximized() {
window.maximize().unwrap_or_else(|_| {
println!("Failed to maximize window!");
});
window.maximize().unwrap_or_default();
}

window_zoom_level(window);
}

fn setup_autostart(app: &mut tauri::App) {
let app_name = &app.package_info().name;
let current_exe = std::env::current_exe().unwrap();

let autolaunch = AutoLaunchBuilder::new()
.set_app_name(&app_name)
.set_app_path(&current_exe.to_str().unwrap())
.set_use_launch_agent(true)
.set_args(&["--startup"])
.build()
.unwrap();

let should_enable = config::get_open_on_startup();

autolaunch.enable().unwrap();

if !should_enable {
autolaunch.disable().unwrap();
}

// window
// .with_webview(move |webview| unsafe {
// })
// .unwrap();
println!("Autolaunch enabled: {}", autolaunch.is_enabled().unwrap());
}

0 comments on commit 66f8f46

Please sign in to comment.