Skip to content

Commit

Permalink
Merge pull request #72 from KilleenCode/feat/auto-update
Browse files Browse the repository at this point in the history
feat: add auto-launch on startup
  • Loading branch information
RyKilleen authored Apr 4, 2022
2 parents b079880 + 40bbb75 commit 2d15893
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 3 deletions.
38 changes: 37 additions & 1 deletion src-tauri/Cargo.lock

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

2 changes: 2 additions & 0 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ open = "2.0.2"
directories = "4.0.1"
log = "0.4"
pretty_env_logger = "0.4"
auto-launch = "0.2"
dunce = "1.0.2"

[features]
# by default Tauri runs in production mode
Expand Down
20 changes: 18 additions & 2 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ mod user_config;
mod windows;
mod workflows;
use app_config::{set_custom_user_config_path, AppConfig};
use auto_launch::{AutoLaunch, AutoLaunchBuilder};
use serde::Serialize;
use std::{path::PathBuf, sync::Mutex};
use tauri::{
api::dialog::blocking::FileDialogBuilder, AppHandle, CustomMenuItem, GlobalShortcutManager,
Manager, RunEvent, State, SystemTray, SystemTrayEvent, SystemTrayMenu, SystemTrayMenuItem,
api::dialog::blocking::FileDialogBuilder, utils::platform::current_exe, AppHandle,
CustomMenuItem, GlobalShortcutManager, Manager, RunEvent, State, SystemTray, SystemTrayEvent,
SystemTrayMenu, SystemTrayMenuItem,
};

use user_config::{set_user_config, UserConfig};
Expand Down Expand Up @@ -187,8 +189,22 @@ fn open_omnibar(app: &AppHandle) -> Result<(), tauri::Error> {
Ok(())
}

pub fn init_autolaunch() -> AutoLaunch {
let app_exe = current_exe().unwrap();
let app_exe = dunce::canonicalize(app_exe).unwrap();
let app_name = app_exe.file_stem().unwrap().to_str().unwrap();
let app_path = app_exe.as_os_str().to_str().unwrap();

AutoLaunchBuilder::new()
.set_app_name(app_name)
.set_app_path(app_path)
.build()
}

fn main() {
pretty_env_logger::init();
let autolaunch = init_autolaunch();
autolaunch.enable().unwrap();
let app_config = app_config::get_or_create_app_config();
let user_config = user_config::get_user_config(app_config.user_config_path.clone());

Expand Down

0 comments on commit 2d15893

Please sign in to comment.