feat: add native window frame and unfuck my event listener
This commit is contained in:
parent
cd668fc33a
commit
1e02f4ee73
6 changed files with 57 additions and 22 deletions
|
|
@ -6,6 +6,8 @@ pub trait OneLauncherApi {
|
|||
async fn return_error() -> LauncherResult<()>;
|
||||
|
||||
async fn open_dev_tools<R: Runtime>(webview_window: tauri::WebviewWindow<R>);
|
||||
|
||||
async fn set_window_style<R: Runtime>(webview_window: tauri::WebviewWindow<R>, decorations: bool);
|
||||
}
|
||||
|
||||
#[taurpc::ipc_type]
|
||||
|
|
@ -24,4 +26,7 @@ impl OneLauncherApi for OneLauncherApiImpl {
|
|||
webview_window.open_devtools();
|
||||
}
|
||||
|
||||
async fn set_window_style<R: Runtime>(self, webview_window: tauri::WebviewWindow<R>, decorations: bool) {
|
||||
webview_window.set_decorations(decorations).ok();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -116,11 +116,16 @@ fn setup_window(handle: &tauri::AppHandle) -> Result<(), Box<dyn std::error::Err
|
|||
.get_webview_window("main")
|
||||
.ok_or_else(|| anyhow::anyhow!("no window called main was found"))?;
|
||||
|
||||
// tokio::task::spawn(async move {
|
||||
// // let state = State::get().await.expect("failed to get state");
|
||||
// // let settings = state.settings.read().await;
|
||||
// // win.set_decorations(settings.);
|
||||
// });
|
||||
// Initialize window decorations based on settings
|
||||
let win_clone = win.clone();
|
||||
tokio::task::spawn(async move {
|
||||
if let Ok(state) = State::get().await {
|
||||
let settings = state.settings.read().await;
|
||||
// native_window_frame=true means use native decorations
|
||||
// native_window_frame=false means use custom frame (no decorations)
|
||||
win_clone.set_decorations(settings.native_window_frame).ok();
|
||||
}
|
||||
});
|
||||
|
||||
win.show()?;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import type { ComponentType, JSX } from 'react';
|
||||
import type { PressEvent } from 'react-aria-components';
|
||||
import { Button } from '@onelauncher/common/components';
|
||||
import useSettings from '@/hooks/useSettings';
|
||||
import { Button, Show } from '@onelauncher/common/components';
|
||||
import { Window } from '@tauri-apps/api/window';
|
||||
import { ChevronLeftIcon, Maximize02Icon, Minimize01Icon, MinusIcon, XCloseIcon } from '@untitled-theme/icons-react';
|
||||
import { useEffect, useState } from 'react';
|
||||
|
|
@ -8,6 +9,7 @@ import { twMerge } from 'tailwind-merge';
|
|||
|
||||
function WindowFrame() {
|
||||
const [isMaximized, setIsMaximized] = useState(false);
|
||||
const { settings } = useSettings();
|
||||
|
||||
const back = () => history.back();
|
||||
const minimize = () => Window.getCurrent().minimize();
|
||||
|
|
@ -27,17 +29,19 @@ function WindowFrame() {
|
|||
}, []);
|
||||
|
||||
return (
|
||||
<div className="z-[99999] w-screen flex flex-row items-center justify-between gap-0.5 bg-window-frame" data-tauri-drag-region>
|
||||
<div className="flex-1 flex flex-row items-center pointer-events-none">
|
||||
<TitlebarButton icon={ChevronLeftIcon} onClick={back} />
|
||||
</div>
|
||||
<Show when={settings?.native_window_frame === false}>
|
||||
<div className="z-[99999] w-screen flex flex-row items-center justify-between gap-0.5 bg-window-frame" data-tauri-drag-region>
|
||||
<div className="flex-1 flex flex-row items-center pointer-events-none">
|
||||
<TitlebarButton icon={ChevronLeftIcon} onClick={back} />
|
||||
</div>
|
||||
|
||||
<div className="flex-1 flex flex-row items-center justify-end pointer-events-none">
|
||||
<TitlebarButton icon={MinusIcon} onClick={minimize} />
|
||||
<TitlebarButton icon={isMaximized ? Minimize01Icon : Maximize02Icon} onClick={toggleMaximize} />
|
||||
<TitlebarButton danger icon={XCloseIcon} onClick={quit} />
|
||||
<div className="flex-1 flex flex-row items-center justify-end pointer-events-none">
|
||||
<TitlebarButton icon={MinusIcon} onClick={minimize} />
|
||||
<TitlebarButton icon={isMaximized ? Minimize01Icon : Maximize02Icon} onClick={toggleMaximize} />
|
||||
<TitlebarButton danger icon={XCloseIcon} onClick={quit} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Show>
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import { createFileRoute, Link } from '@tanstack/react-router';
|
|||
import { convertFileSrc } from '@tauri-apps/api/core';
|
||||
import { PlayIcon } from '@untitled-theme/icons-react';
|
||||
import { OverlayScrollbarsComponent } from 'overlayscrollbars-react';
|
||||
import { useEffect } from 'react';
|
||||
|
||||
export const Route = createFileRoute('/app/')({
|
||||
component: RouteComponent,
|
||||
|
|
@ -27,12 +28,19 @@ hey future sassan here i guess the issue is solved idk
|
|||
function RouteComponent() {
|
||||
const result = useCommand('getClusters', bindings.core.getClusters);
|
||||
|
||||
bindings.events.ingress.on((e) => {
|
||||
if (typeof e.ingress_type === 'object')
|
||||
if ('PrepareCluster' in e.ingress_type)
|
||||
// eslint-disable-next-line no-console -- ok
|
||||
console.log(`Preparing cluster: ${e.ingress_type.PrepareCluster.cluster_name} %${e.percent}`);
|
||||
});
|
||||
useEffect(() => {
|
||||
let unlisten: (() => void) | undefined;
|
||||
(async () => {
|
||||
unlisten = await bindings.events.ingress.on((e) => {
|
||||
if (typeof e.ingress_type === 'object')
|
||||
if ('PrepareCluster' in e.ingress_type)
|
||||
// eslint-disable-next-line no-console -- ok
|
||||
console.log(`Preparing cluster: ${e.ingress_type.PrepareCluster.cluster_name} %${e.percent}`);
|
||||
});
|
||||
})();
|
||||
|
||||
return () => unlisten?.();
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div className="h-full flex flex-col gap-y-4 text-fg-primary">
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
import ScrollableContainer from '@/components/ScrollableContainer';
|
||||
import SettingsRow from '@/components/SettingsRow';
|
||||
import useSettings from '@/hooks/useSettings';
|
||||
import { bindings } from '@/main';
|
||||
import { THEMES } from '@/utils/theming';
|
||||
import { Switch } from '@onelauncher/common/components';
|
||||
import { createFileRoute } from '@tanstack/react-router';
|
||||
|
|
@ -11,6 +13,15 @@ export const Route = createFileRoute('/app/settings/appearance')({
|
|||
});
|
||||
|
||||
function RouteComponent() {
|
||||
const { settings, createSetting } = useSettings();
|
||||
|
||||
const [windowFrame, setFrameStyle] = createSetting('native_window_frame', settings?.native_window_frame);
|
||||
|
||||
const handleWindowFrameChange = async (value: boolean) => {
|
||||
await bindings.onelauncher.set_window_style(value);
|
||||
setFrameStyle(value);
|
||||
};
|
||||
|
||||
return (
|
||||
<Sidebar.Page>
|
||||
<ScrollableContainer>
|
||||
|
|
@ -56,7 +67,7 @@ function RouteComponent() {
|
|||
icon={<Monitor01Icon />}
|
||||
title="Custom Window Frame"
|
||||
>
|
||||
<Switch />
|
||||
<Switch defaultSelected={windowFrame} onChange={handleWindowFrameChange} />
|
||||
</SettingsRow>
|
||||
|
||||
<SettingsRow
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ pub struct Settings {
|
|||
pub discord_enabled: bool,
|
||||
pub max_concurrent_requests: usize,
|
||||
pub settings_version: u32,
|
||||
pub native_window_frame: bool
|
||||
}
|
||||
|
||||
impl Default for Settings {
|
||||
|
|
@ -26,6 +27,7 @@ impl Default for Settings {
|
|||
enable_gamemode: false,
|
||||
max_concurrent_requests: 25,
|
||||
settings_version: 1,
|
||||
native_window_frame: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue