Skip to content

Commit

Permalink
Auto launch and clear data fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Levminer committed Oct 16, 2022
1 parent 33a0e6a commit 22af5a0
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 12 deletions.
26 changes: 20 additions & 6 deletions core/src/auto_launch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,37 @@ use auto_launch::*;
use std::env;

#[tauri::command]
pub fn auto_launch() {
pub fn enable_auto_launch() {
let exe = env::current_exe().unwrap();
let exe_string = exe.to_str().unwrap();

let auto = AutoLaunchBuilder::new()
.set_app_name("Authme v4")
.set_app_name("Authme")
.set_app_path(exe_string)
.set_use_launch_agent(false)
.set_args(&["--minimized"])
.build()
.unwrap();

let enabled = auto.is_enabled().unwrap();

if enabled == false {
if !auto.is_enabled().unwrap() {
auto.enable().unwrap();
} else {
}
}

#[tauri::command]
pub fn disable_auto_launch() {
let exe = env::current_exe().unwrap();
let exe_string = exe.to_str().unwrap();

let auto = AutoLaunchBuilder::new()
.set_app_name("Authme")
.set_app_path(exe_string)
.set_use_launch_agent(false)
.set_args(&["--minimized"])
.build()
.unwrap();

if auto.is_enabled().unwrap() {
auto.disable().unwrap();
}
}
3 changes: 2 additions & 1 deletion core/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ fn main() {

tauri::Builder::default()
.invoke_handler(tauri::generate_handler![
auto_launch::auto_launch,
auto_launch::enable_auto_launch,
auto_launch::disable_auto_launch,
system_info::system_info,
encryption::encrypt_password,
encryption::verify_password,
Expand Down
2 changes: 1 addition & 1 deletion interface/stores/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const defaultSettings: LibSettings = {

// Setup auto launch on first start
if (build.dev === false && localStorage.settings === undefined) {
invoke("auto_launch")
invoke("enable_auto_launch")
}

// Create store
Expand Down
20 changes: 16 additions & 4 deletions interface/windows/settings/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import build from "../../../build.json"
import { path, invoke, os, dialog, app } from "@tauri-apps/api"
import { path, invoke, os, dialog, app, process } from "@tauri-apps/api"
import { UAParser } from "ua-parser-js"
import { navigate, open } from "../../utils/navigate"
import { deleteEncryptionKey } from "interface/utils/encryption"
import { getSettings } from "interface/stores/settings"

const settings = getSettings()

export const about = async () => {
const appVersion = await app.getVersion()
Expand Down Expand Up @@ -44,8 +47,13 @@ export const clearData = async () => {

await deleteEncryptionKey("encryptionKey")

navigate("/")
location.reload()
if (build.dev === false) {
await invoke("disable_auto_launch")
process.exit()
} else {
navigate("/")
location.reload()
}
}
}

Expand All @@ -55,5 +63,9 @@ export const showLogs = async () => {
}

export const launchOnStartup = () => {
invoke("auto_launch")
if (settings.settings.launchOnStartup === true) {
invoke("disable_auto_launch")
} else {
invoke("enable_auto_launch")
}
}

0 comments on commit 22af5a0

Please sign in to comment.