Skip to content
This repository has been archived by the owner on Oct 19, 2022. It is now read-only.

Commit

Permalink
Tray improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Levminer committed Sep 11, 2022
1 parent 3294d3a commit b09f958
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 10 deletions.
8 changes: 8 additions & 0 deletions core/src/libraries.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use std::env;

#[tauri::command]
pub fn get_args() -> Vec<String> {
let args: Vec<String> = env::args().collect();

args.into()
}
15 changes: 15 additions & 0 deletions core/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use window_vibrancy::{apply_mica, apply_vibrancy, NSVisualEffectMaterial};

mod auto_launch;
mod encryption;
mod libraries;
mod system_info;

#[derive(Clone, serde::Serialize)]
Expand All @@ -34,6 +35,14 @@ fn handle_tray_event(app: &AppHandle, event: SystemTrayEvent) {
window.hide().unwrap();
menu_item.set_title("Show Authme").unwrap();
} else {
app.emit_all(
"openCodes",
Payload {
message: "Open codes page".into(),
},
)
.unwrap();

window.show().unwrap();
window.unminimize().unwrap();
menu_item.set_title("Hide Authme").unwrap();
Expand Down Expand Up @@ -87,6 +96,7 @@ fn main() {
encryption::receive_encryption_key,
encryption::set_encryption_key,
encryption::delete_entry,
libraries::get_args,
])
.plugin(tauri_plugin_single_instance::init(|app, argv, cwd| {
println!("{}, {argv:?}, {cwd}", app.package_info().name);
Expand Down Expand Up @@ -120,6 +130,11 @@ fn main() {
window.maximize().unwrap();
window.show().unwrap();
window.set_focus().unwrap();
} else {
window.maximize().unwrap();

let menu_item = app.tray_handle().get_item("toggle");
menu_item.set_title("Show Authme").unwrap();
}
} else {
window.maximize().unwrap();
Expand Down
16 changes: 15 additions & 1 deletion interface/layout/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ event.listen("openSettings", () => {
navigate("settings")
})

// Tray navigate to codes handler
event.listen("openCodes", () => {
navigate("codes")
})

// Listen for focus changes
window.appWindow.onFocusChanged((focused) => {
const path = location.pathname
Expand All @@ -64,5 +69,14 @@ document.addEventListener("contextmenu", (event) => {
event.preventDefault()
})

// Handle launch options
const launchOptions = async () => {
const args: string[] = await invoke("get_args")

if (args[1] === "--minimized" && state.authenticated === true) {
navigate("idle")
}
}

launchOptions()

export default app
18 changes: 9 additions & 9 deletions interface/libraries/encryption.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ export const generateRandomKey = async (): Promise<Buffer> => {
}

/**
* Sets an entry on the system keychain
* Encrypts a string with the encryption key
*/
export const setEntry = async (name: string, data: string) => {
await invoke("set_entry", { name, data })
export const encryptData = async (data: string): Promise<string> => {
return await invoke("encrypt_data", { data })
}

/**
* Encrypts a string with the encryption key
* Decrypts a string with the encryption key
*/
export const encryptData = async (data: string): Promise<string> => {
const res: string = await invoke("encrypt_data", { data })
export const decryptData = async (data: string): Promise<string> => {
const res: string = await invoke("decrypt_data", { data })

if (res === "error") {
dialog.message("Failed to decrypt your codes!\n\n Please restart the app and try again!", { type: "error" })
Expand All @@ -28,10 +28,10 @@ export const encryptData = async (data: string): Promise<string> => {
}

/**
* Decrypts a string with the encryption key
* Sets an entry on the system keychain
*/
export const decryptData = async (data: string): Promise<string> => {
return await invoke("decrypt_data", { data })
export const setEntry = async (name: string, data: string) => {
await invoke("set_entry", { name, data })
}

/**
Expand Down

0 comments on commit b09f958

Please sign in to comment.