From 835ed443a50fdfeb84f7a782cf027313e19c0775 Mon Sep 17 00:00:00 2001 From: Huang Xin Date: Wed, 26 Mar 2025 01:58:23 +0800 Subject: [PATCH] fix: style tweaks for Windows (#707) --- apps/readest-app/src-tauri/src/lib.rs | 18 ++++++++- apps/readest-app/src/app/auth/page.tsx | 37 +++++++++++++------ .../app/library/components/LibraryHeader.tsx | 2 +- .../app/library/components/SettingsMenu.tsx | 4 +- apps/readest-app/src/app/library/page.tsx | 2 +- .../src/app/reader/components/ViewMenu.tsx | 4 +- apps/readest-app/src/app/user/page.tsx | 33 ++++++++++++----- apps/readest-app/src/components/Toast.tsx | 4 +- apps/readest-app/src/services/appService.ts | 1 + .../src/services/nativeAppService.ts | 9 ++++- .../readest-app/src/services/webAppService.ts | 1 + apps/readest-app/src/styles/globals.css | 2 +- apps/readest-app/src/types/system.ts | 1 + 13 files changed, 82 insertions(+), 36 deletions(-) diff --git a/apps/readest-app/src-tauri/src/lib.rs b/apps/readest-app/src-tauri/src/lib.rs index 4db66df2..1b12ecbf 100644 --- a/apps/readest-app/src-tauri/src/lib.rs +++ b/apps/readest-app/src-tauri/src/lib.rs @@ -63,6 +63,15 @@ fn set_window_open_with_files(app: &AppHandle, files: Vec) { } } +#[cfg(desktop)] +fn set_rounded_window(app: &AppHandle, rounded: bool) { + let window = app.get_webview_window("main").unwrap(); + let script = format!("window.IS_ROUNDED = {};", rounded); + if let Err(e) = window.eval(&script) { + eprintln!("Failed to set IS_ROUNDED variable: {}", e); + } +} + #[command] async fn start_server(window: Window) -> Result { start(move |url| { @@ -185,6 +194,12 @@ pub fn run() { app_handle.get_webview_window("main").unwrap() .eval("window.__READEST_CLI_ACCESS = true; window.__READEST_UPDATER_ACCESS = true;") .expect("Failed to set cli access config"); + + set_rounded_window(&app_handle, true); + #[cfg(target_os = "windows")] + if tauri_plugin_os::version() <= tauri_plugin_os::Version::from_string("10.0.19045") { + set_rounded_window(&app_handle, false); + } }); } @@ -225,8 +240,7 @@ pub fn run() { .title("Readest"); if cfg!(target_os = "windows") { - let version = tauri_plugin_os::version(); - if version <= tauri_plugin_os::Version::from_string("10.0.19045") { + if tauri_plugin_os::version() <= tauri_plugin_os::Version::from_string("10.0.19045") { win_builder = win_builder.shadow(false); } else { win_builder = win_builder.shadow(true); diff --git a/apps/readest-app/src/app/auth/page.tsx b/apps/readest-app/src/app/auth/page.tsx index c9696fd3..90ac992e 100644 --- a/apps/readest-app/src/app/auth/page.tsx +++ b/apps/readest-app/src/app/auth/page.tsx @@ -23,6 +23,7 @@ import { openUrl } from '@tauri-apps/plugin-opener'; import { handleAuthCallback } from '@/helpers/auth'; import { getAppleIdAuth, Scope } from './utils/appleIdAuth'; import { authWithSafari } from './utils/safariAuth'; +import WindowButtons from '@/components/WindowButtons'; type OAuthProvider = 'google' | 'apple' | 'azure' | 'github'; @@ -47,11 +48,11 @@ const ProviderLogin: React.FC = ({ provider, handleSignIn, Ic onClick={() => handleSignIn(provider)} className={clsx( 'mb-2 flex w-64 items-center justify-center rounded border p-2.5', - 'bg-base-100 border-gray-300 shadow-sm transition hover:bg-gray-50', + 'bg-base-100 border-base-300 hover:bg-base-200 shadow-sm transition', )} > - {label} + {label} ); }; @@ -67,6 +68,8 @@ export default function AuthPage() { const isOAuthServerRunning = useRef(false); const [isMounted, setIsMounted] = useState(false); + const headerRef = useRef(null); + const getTauriRedirectTo = (isOAuth: boolean) => { if (process.env.NODE_ENV === 'production' || appService?.isMobile) { if (appService?.isIOSApp) { @@ -298,21 +301,31 @@ export default function AuthPage() { return isTauriAppPlatform() ? (
- + + + {appService?.hasWindowBar && ( + + )} +
-
+
= ({
= ({ setIsDropdownOpen }) => { onClick={toggleScreenWakeLock} />
- {appService?.hasRoundedWindow && ( - - )} + {appService?.hasWindow && }
{isWebApp && } diff --git a/apps/readest-app/src/app/library/page.tsx b/apps/readest-app/src/app/library/page.tsx index 87250dff..0396240d 100644 --- a/apps/readest-app/src/app/library/page.tsx +++ b/apps/readest-app/src/app/library/page.tsx @@ -508,7 +508,7 @@ const LibraryPageContent = ({ searchParams }: { searchParams: ReadonlyURLSearchP
= ({
- {appService?.hasRoundedWindow && ( - - )} + {appService?.hasWindow && } { @@ -29,6 +30,8 @@ const ProfilePage = () => { const [quotas, setQuotas] = React.useState([]); const [showConfirmDelete, setShowConfirmDelete] = useState(false); + const headerRef = useRef(null); + useTheme(); useEffect(() => { @@ -154,21 +157,31 @@ const ProfilePage = () => { return (
- + + + {appService?.hasWindowBar && ( + + )} +
diff --git a/apps/readest-app/src/components/Toast.tsx b/apps/readest-app/src/components/Toast.tsx index d607c5e4..c53e96e3 100644 --- a/apps/readest-app/src/components/Toast.tsx +++ b/apps/readest-app/src/components/Toast.tsx @@ -64,8 +64,8 @@ export const Toast = () => { > diff --git a/apps/readest-app/src/services/appService.ts b/apps/readest-app/src/services/appService.ts index 295298ff..21ee82a3 100644 --- a/apps/readest-app/src/services/appService.ts +++ b/apps/readest-app/src/services/appService.ts @@ -49,6 +49,7 @@ export abstract class BaseAppService implements AppService { abstract isAndroidApp: boolean; abstract isIOSApp: boolean; abstract hasTrafficLight: boolean; + abstract hasWindow: boolean; abstract hasWindowBar: boolean; abstract hasContextMenu: boolean; abstract hasRoundedWindow: boolean; diff --git a/apps/readest-app/src/services/nativeAppService.ts b/apps/readest-app/src/services/nativeAppService.ts index efad7750..d825592d 100644 --- a/apps/readest-app/src/services/nativeAppService.ts +++ b/apps/readest-app/src/services/nativeAppService.ts @@ -23,6 +23,12 @@ import { isValidURL } from '@/utils/misc'; import { BaseAppService } from './appService'; import { LOCAL_BOOKS_SUBDIR } from './constants'; +declare global { + interface Window { + IS_ROUNDED?: boolean; + } +} + const OS_TYPE = osType(); const resolvePath = (fp: string, base: BaseDir): { baseDir: number; base: BaseDir; fp: string } => { @@ -122,9 +128,10 @@ export class NativeAppService extends BaseAppService { isAndroidApp = OS_TYPE === 'android'; isIOSApp = OS_TYPE === 'ios'; hasTrafficLight = OS_TYPE === 'macos'; + hasWindow = !(OS_TYPE === 'ios' || OS_TYPE === 'android'); hasWindowBar = !(OS_TYPE === 'ios' || OS_TYPE === 'android'); hasContextMenu = !(OS_TYPE === 'ios' || OS_TYPE === 'android'); - hasRoundedWindow = !(OS_TYPE === 'ios' || OS_TYPE === 'android'); + hasRoundedWindow = !(OS_TYPE === 'ios' || OS_TYPE === 'android') && !!window.IS_ROUNDED; hasSafeAreaInset = OS_TYPE === 'ios' || OS_TYPE === 'android'; hasHaptics = OS_TYPE === 'ios' || OS_TYPE === 'android'; hasSysFontsList = !(OS_TYPE === 'ios' || OS_TYPE === 'android'); diff --git a/apps/readest-app/src/services/webAppService.ts b/apps/readest-app/src/services/webAppService.ts index fa327f9e..482ef1ff 100644 --- a/apps/readest-app/src/services/webAppService.ts +++ b/apps/readest-app/src/services/webAppService.ts @@ -184,6 +184,7 @@ export class WebAppService extends BaseAppService { isAndroidApp = false; isIOSApp = false; hasTrafficLight = false; + hasWindow = false; hasWindowBar = false; hasContextMenu = false; hasRoundedWindow = false; diff --git a/apps/readest-app/src/styles/globals.css b/apps/readest-app/src/styles/globals.css index 0a6a8b5e..d358ec3d 100644 --- a/apps/readest-app/src/styles/globals.css +++ b/apps/readest-app/src/styles/globals.css @@ -209,7 +209,7 @@ foliate-view { } .scroll-container { - overflow-y: scroll; + overflow-y: auto; scrollbar-width: thin; -webkit-overflow-scrolling: touch; } diff --git a/apps/readest-app/src/types/system.ts b/apps/readest-app/src/types/system.ts index aedff190..ce1e06f5 100644 --- a/apps/readest-app/src/types/system.ts +++ b/apps/readest-app/src/types/system.ts @@ -25,6 +25,7 @@ export interface AppService { osPlatform: string; appPlatform: AppPlatform; hasTrafficLight: boolean; + hasWindow: boolean; hasWindowBar: boolean; hasContextMenu: boolean; hasRoundedWindow: boolean;