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

Commit

Permalink
Focus search on focus
Browse files Browse the repository at this point in the history
  • Loading branch information
Levminer committed Aug 21, 2022
1 parent 93ac8a6 commit 7f4710b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
14 changes: 14 additions & 0 deletions core/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,20 @@ fn main() {

event.window().hide().unwrap();
}

tauri::WindowEvent::Focused(focused) => {
let app = event.window().app_handle();

if *focused {
app.emit_all(
"focusSearch",
Payload {
message: "Focus search bar".into(),
},
)
.unwrap()
}
}
_ => {}
})
.run(context)
Expand Down
2 changes: 1 addition & 1 deletion interface/components/routeTransition.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@

<script>
import { router } from "tinro"
import { fade, fly } from "svelte/transition"
import { fade } from "svelte/transition"
</script>
18 changes: 17 additions & 1 deletion interface/layout/app.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import App from "./app.svelte"
import "../styles/index.css"
import { fs, path, os } from "@tauri-apps/api"
import { fs, path, os, event } from "@tauri-apps/api"
import { navigate } from "../libraries/navigate"

const getSettingsPath = async () => {
const folderPath = await path.join(await path.configDir(), "Levminer", "Authme 4")
Expand Down Expand Up @@ -30,6 +31,21 @@ const setBackground = async () => {

setBackground()

// Tray event handler
event.listen("openSettings", () => {
navigate("settings")
})

// Tray event handler
event.listen("focusSearch", () => {
const path = location.pathname

if (path === "/codes") {
document.querySelector<HTMLInputElement>(".search").focus()
}
})

// Create svelte app
const app = new App({
target: document.body,
})
Expand Down

0 comments on commit 7f4710b

Please sign in to comment.