move focus event to JS with built-in events

This commit is contained in:
maxichrome
2022-05-11 15:50:46 -05:00
parent f6bee3c119
commit f420bf4192
3 changed files with 16 additions and 10 deletions

View File

@@ -2,16 +2,6 @@ use tauri::{GlobalWindowEvent, Runtime, Window, Wry};
pub(crate) fn handle_window_event(event: GlobalWindowEvent<Wry>) {
match event.event() {
tauri::WindowEvent::Focused(_focus) => {
// let fullscreen = event.window().is_fullscreen().unwrap_or(false);
// println!("fullscreen, {}", fullscreen);
// #[cfg(target_os = "macos")]
// event
// .window()
// .set_transparent_titlebar(!fullscreen, !fullscreen);
}
_ => {}
}
}

View File

@@ -45,12 +45,23 @@ function App() {
}
const [platform, setPlatform] = useState<Platform>('macOS');
const [focused, setFocused] = useState(true);
useEffect(() => {
os.platform().then((platform) => setPlatform(getPlatform(platform)));
invoke('app_ready');
}, []);
useEffect(() => {
const unlistenFocus = listen('tauri://focus', () => setFocused(true));
const unlistenBlur = listen('tauri://blur', () => setFocused(false));
return () => {
unlistenFocus.then((unlisten) => unlisten());
unlistenBlur.then((unlisten) => unlisten());
};
}, []);
return (
<SpacedriveInterface
useMemoryRouter
@@ -64,6 +75,7 @@ function App() {
}): Promise<string | string[]> {
return dialog.open(options);
}}
isFocused={focused}
onClose={() => appWindow.close()}
onFullscreen={() => appWindow.setFullscreen(true)}
onMinimize={() => appWindow.minimize()}

View File

@@ -51,6 +51,7 @@ export interface AppProps {
onMinimize?: () => void;
onFullscreen?: () => void;
onOpen?: (path: string) => void;
isFocused?: boolean;
useMemoryRouter: boolean;
demoMode?: boolean;
}
@@ -214,6 +215,9 @@ export default function App(props: AppProps) {
console.log('App props', props);
// default prop values
props.isFocused ??= true;
return (
<>
{/* @ts-ignore */}