-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from shm11C3/feature/toggle-decoration
Feature/toggle-decoration
- Loading branch information
Showing
7 changed files
with
61 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod background_image; | ||
pub mod config; | ||
pub mod hardware; | ||
pub mod ui; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
use tauri::App; | ||
use tauri::Manager; | ||
use tauri_plugin_store::StoreExt; | ||
|
||
#[warn(unused_must_use)] | ||
pub fn init(app: &mut App) { | ||
let store = app.store("store.json").unwrap(); | ||
|
||
// 設定値をロードしてウィンドウの初期状態を設定 | ||
if let Some(is_decorated) = store.get("window_decorated").and_then(|v| v.as_bool()) { | ||
let window = app.get_webview_window("main").unwrap(); | ||
set_decoration(window, is_decorated); | ||
} | ||
} | ||
|
||
#[tauri::command] | ||
pub fn set_decoration(window: tauri::WebviewWindow, is_decorated: bool) { | ||
let _ = window.set_fullscreen(!is_decorated); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { toggleDecoration } from "@/services/uiService"; | ||
import { useEffect } from "react"; | ||
import { useTauriStore } from "./useTauriStore"; | ||
|
||
export const useKeydown = () => { | ||
const [isDecorated, setDecorated] = useTauriStore("window_decorated", false); | ||
|
||
useEffect(() => { | ||
const handleDecoration = async () => { | ||
try { | ||
await toggleDecoration(!isDecorated); | ||
await setDecorated(!isDecorated); | ||
} catch (e) { | ||
console.error("Failed to toggle window decoration:", e); | ||
} | ||
}; | ||
|
||
const handleKeyDown = async (event: KeyboardEvent) => { | ||
if (event.key === "F11") handleDecoration(); | ||
}; | ||
|
||
window.addEventListener("keydown", handleKeyDown, { passive: true }); | ||
return () => { | ||
window.removeEventListener("keydown", handleKeyDown); | ||
}; | ||
}, [isDecorated, setDecorated]); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { invoke } from "@tauri-apps/api/core"; | ||
|
||
export const toggleDecoration = async (isDecorated: boolean): Promise<void> => { | ||
return await invoke("set_decoration", { isDecorated }); | ||
}; |