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

Commit

Permalink
Performance improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Levminer committed Sep 30, 2022
1 parent 5bd8dae commit 36cd098
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 62 deletions.
13 changes: 0 additions & 13 deletions core/Cargo.lock

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

1 change: 0 additions & 1 deletion core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ tauri-build = { version = "1.1.1", features = [] }
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
tauri = { version = "1.1.1", features = ["api-all", "system-tray", "updater"] }
window-vibrancy = "0.3.0"
auto-launch = "0.3.0"
sysinfo = "0.25.3"
argon2 = "0.4"
Expand Down
57 changes: 18 additions & 39 deletions core/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use std::env;
use tauri::*;
use window_vibrancy::{apply_mica, apply_vibrancy, NSVisualEffectMaterial};

mod auto_launch;
mod encryption;
Expand All @@ -15,7 +14,7 @@ mod utils;

#[derive(Clone, serde::Serialize)]
struct Payload {
message: String,
event: bool,
}

fn make_tray() -> SystemTray {
Expand All @@ -30,18 +29,15 @@ fn handle_tray_event(app: &AppHandle, event: SystemTrayEvent) {
let toggle_window = |app: AppHandle| -> () {
let window = app.get_window("main").unwrap();
let menu_item = app.tray_handle().get_item("toggle");
let window_visible = window.is_visible().unwrap();

if window_visible {
app.emit_all("openCodes", Payload { event: false }).unwrap();

if window.is_visible().unwrap() {
window.hide().unwrap();
menu_item.set_title("Show Authme").unwrap();
} else {
app.emit_all(
"openCodes",
Payload {
message: "Open codes page".into(),
},
)
.unwrap();
app.emit_all("openCodes", Payload { event: true }).unwrap();

window.show().unwrap();
window.unminimize().unwrap();
Expand All @@ -62,18 +58,18 @@ fn handle_tray_event(app: &AppHandle, event: SystemTrayEvent) {

if id.as_str() == "settings" {
let window = app.get_window("main").unwrap();
let window_visible = window.is_visible().unwrap();

window.show().unwrap();
window.unminimize().unwrap();
window.set_focus().unwrap();
if window_visible {
window.hide().unwrap();
} else {
window.show().unwrap();
window.unminimize().unwrap();
window.set_focus().unwrap();
}

app.emit_all(
"openSettings",
Payload {
message: "Open settings page".into(),
},
)
.unwrap()
app.emit_all("openSettings", Payload { event: true })
.unwrap()
}

if id.as_str() == "toggle" {
Expand Down Expand Up @@ -108,13 +104,8 @@ fn main() {

let window = app.get_window("main").unwrap();

app.emit_all(
"openCodes",
Payload {
message: "Open codes page".into(),
},
)
.unwrap();
app.emit_all("openCodes", Payload { event: true.into() })
.unwrap();

window.show().unwrap();
window.unminimize().unwrap();
Expand All @@ -125,15 +116,6 @@ fn main() {
.setup(|app| {
let window = app.get_window("main").unwrap();

// Transparent effects
#[cfg(target_os = "macos")]
apply_vibrancy(&window, NSVisualEffectMaterial::HudWindow, None, None)
.expect("Unsupported platform! 'apply_vibrancy' is only supported on macOS");

#[cfg(target_os = "windows")]
apply_mica(&window)
.expect("Unsupported platform! 'apply_blur' is only supported on Windows");

// Launch args
let args: Vec<String> = env::args().collect();

Expand All @@ -155,9 +137,6 @@ fn main() {
window.set_focus().unwrap();
}

// Temporary fix for transparency
window.set_decorations(true).unwrap();

Ok(())
})
.on_window_event(|event| match event.event() {
Expand Down
2 changes: 0 additions & 2 deletions core/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@
"minWidth": 1000,
"minHeight": 600,
"maximized": true,
"transparent": true,
"decorations": false,
"visible": false
}
]
Expand Down
4 changes: 3 additions & 1 deletion interface/layout/app.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@
import Edit from "../windows/edit/edit.svelte"
onMount(() => {
router.subscribe(() => {
router.subscribe((data) => {
console.log("Path changed:", data)
document.querySelector(".top").scrollIntoView()
})
})
Expand Down
8 changes: 6 additions & 2 deletions interface/layout/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,20 @@ const setBackground = async () => {
setBackground()

// Tray settings open handler
event.listen("openSettings", () => {
event.listen("openSettings", (data: any) => {
if (state.authenticated === true) {
navigate("settings")
}
})

// Tray navigate to codes handler
event.listen("openCodes", () => {
event.listen("openCodes", (data: any) => {
const event: boolean = data.payload.event

if (state.authenticated === true && location.pathname === "/idle") {
navigate("codes")
} else if (state.authenticated === true && location.pathname === "/codes" && event === false) {
navigate("idle")
}
})

Expand Down
16 changes: 12 additions & 4 deletions interface/utils/shortcuts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,18 @@ export const registerShortcuts = () => {

if (windowShown === true) {
window.appWindow.hide()

if (state.authenticated === true && location.pathname === "/codes") {
navigate("idle")
}
} else {
await window.appWindow.show()
await window.appWindow.unminimize()
await window.appWindow.setFocus()
}

if (state.authenticated === true && location.pathname === "idle") {
navigate("codes")
if (state.authenticated === true && location.pathname === "/idle") {
navigate("codes")
}
}
})
}
Expand All @@ -156,7 +160,11 @@ export const registerShortcuts = () => {
const windowShown = await window.appWindow.isVisible()

if (windowShown === false) {
window.appWindow.show()
await window.appWindow.show()
await window.appWindow.unminimize()
await window.appWindow.setFocus()
} else {
window.appWindow.hide()
}

if (state.authenticated === true) {
Expand Down

0 comments on commit 36cd098

Please sign in to comment.