mirror of
https://github.com/SableClient/Sable.git
synced 2026-11-29 21:32:44 -08:00
fix(cef): resize webview with window
This commit is contained in:
3 files changed
+46
-30
No files matched your search
+28
-12
@@ -25,18 +25,8 @@ use tauri::Wry as BrowserEngine;
|
||||
pub const MAIN_WINDOW_LABEL: &str = "main";
|
||||
|
||||
#[cfg(desktop)]
|
||||
pub(crate) fn main_window_title(app: &AppHandle<crate::BrowserEngine>) -> &'static str {
|
||||
if app
|
||||
.package_info()
|
||||
.version
|
||||
.pre
|
||||
.as_str()
|
||||
.starts_with("nightly.")
|
||||
{
|
||||
"Sable Nightly"
|
||||
} else {
|
||||
"Sable"
|
||||
}
|
||||
pub(crate) fn main_window_title(app: &AppHandle<crate::BrowserEngine>) -> &str {
|
||||
app.config().product_name.as_deref().unwrap_or("Sable")
|
||||
}
|
||||
|
||||
#[cfg(all(
|
||||
@@ -104,6 +94,29 @@ fn resolve_webview_permission(
|
||||
allowed
|
||||
}
|
||||
|
||||
#[cfg(all(feature = "cef", target_os = "linux"))]
|
||||
fn setup_cef_resize_workaround(
|
||||
webview_window: &tauri::WebviewWindow<BrowserEngine>,
|
||||
) -> tauri::Result<()> {
|
||||
let webview = webview_window.as_ref().clone();
|
||||
webview.set_auto_resize(false)?;
|
||||
webview_window.on_window_event(move |event| {
|
||||
let size = match event {
|
||||
tauri::WindowEvent::Resized(size) => *size,
|
||||
tauri::WindowEvent::ScaleFactorChanged { new_inner_size, .. } => *new_inner_size,
|
||||
_ => return,
|
||||
};
|
||||
|
||||
if let Err(error) = webview.set_bounds(tauri::Rect {
|
||||
position: tauri::Position::Physical(tauri::PhysicalPosition::new(0, 0)),
|
||||
size: tauri::Size::Physical(size),
|
||||
}) {
|
||||
log::warn!("failed to resize CEF webview: {error}");
|
||||
}
|
||||
});
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn show_or_create_main_window(app: &AppHandle<crate::BrowserEngine>) -> tauri::Result<()> {
|
||||
if let Some(_window) = app.get_webview_window(MAIN_WINDOW_LABEL) {
|
||||
#[cfg(desktop)]
|
||||
@@ -152,6 +165,9 @@ pub fn show_or_create_main_window(app: &AppHandle<crate::BrowserEngine>) -> taur
|
||||
|
||||
let webview_window = builder.build()?;
|
||||
|
||||
#[cfg(all(feature = "cef", target_os = "linux"))]
|
||||
setup_cef_resize_workaround(&webview_window)?;
|
||||
|
||||
#[cfg(desktop)]
|
||||
desktop::tray::setup_close_to_background(&webview_window);
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { atom } from 'jotai';
|
||||
import { isTauri } from '@tauri-apps/api/core';
|
||||
import { type as osType } from '@tauri-apps/plugin-os';
|
||||
import { LazyStore } from '@tauri-apps/plugin-store';
|
||||
import { getDesktopRuntimeState, syncDesktopSettings } from '$generated/tauri/commands';
|
||||
import type { DesktopSettings as GeneratedDesktopSettings } from '$generated/tauri/desktop/DesktopSettings';
|
||||
import type { DesktopRuntimeState } from '$generated/tauri/desktop/DesktopRuntimeState';
|
||||
import { getDesktopTauriPlatform, isDesktopTauri } from '$utils/platform';
|
||||
import type { DesktopTauriPlatform } from '$utils/platform';
|
||||
|
||||
type DesktopSettingsState = {
|
||||
ready: boolean;
|
||||
@@ -22,7 +22,7 @@ export type { DesktopRuntimeState };
|
||||
const DESKTOP_SETTINGS_STORE_PATH = 'desktop-preferences.json' as const;
|
||||
const LEGACY_KEEP_BACKGROUND_RUNNING_KEY = 'keepBackgroundRunning' as const;
|
||||
|
||||
type DesktopPlatform = 'windows' | 'linux' | 'macos' | undefined;
|
||||
type DesktopPlatform = DesktopTauriPlatform | undefined;
|
||||
|
||||
export function desktopSettingsDefaultsForPlatform(platform: DesktopPlatform): DesktopSettings {
|
||||
return {
|
||||
@@ -37,14 +37,8 @@ export const DEFAULT_DESKTOP_RUNTIME_STATE: DesktopRuntimeState = {
|
||||
trayAvailable: true,
|
||||
};
|
||||
|
||||
function getDesktopPlatform(): DesktopPlatform {
|
||||
if (!isTauri()) return undefined;
|
||||
|
||||
const os = osType();
|
||||
return os === 'windows' || os === 'linux' || os === 'macos' ? os : undefined;
|
||||
}
|
||||
|
||||
export const DEFAULT_DESKTOP_SETTINGS = desktopSettingsDefaultsForPlatform(getDesktopPlatform());
|
||||
export const DEFAULT_DESKTOP_SETTINGS =
|
||||
desktopSettingsDefaultsForPlatform(getDesktopTauriPlatform());
|
||||
|
||||
const DESKTOP_SETTING_KEYS = Object.keys(DEFAULT_DESKTOP_SETTINGS) as DesktopSettingKey[];
|
||||
|
||||
@@ -55,10 +49,6 @@ const desktopSettingsStore = new LazyStore(DESKTOP_SETTINGS_STORE_PATH, {
|
||||
let currentDesktopSettings = DEFAULT_DESKTOP_SETTINGS;
|
||||
let currentDesktopRuntimeState = DEFAULT_DESKTOP_RUNTIME_STATE;
|
||||
|
||||
function isDesktopTauri(): boolean {
|
||||
return getDesktopPlatform() !== undefined;
|
||||
}
|
||||
|
||||
function readBoolean(value: boolean | undefined, fallback: boolean): boolean {
|
||||
return value === undefined ? fallback : value;
|
||||
}
|
||||
@@ -85,7 +75,7 @@ export function desktopSettingsFromStoreValues(
|
||||
showSystemTrayIcon: boolean | undefined,
|
||||
legacyKeepBackgroundRunning: boolean | undefined,
|
||||
useCustomTitleBar: boolean | undefined,
|
||||
platform = getDesktopPlatform()
|
||||
platform = getDesktopTauriPlatform()
|
||||
): DesktopSettings {
|
||||
const defaults = desktopSettingsDefaultsForPlatform(platform);
|
||||
|
||||
|
||||
@@ -6,10 +6,20 @@ export function hasServiceWorker(): boolean {
|
||||
return 'serviceWorker' in navigator && !isTauri();
|
||||
}
|
||||
|
||||
const DESKTOP_TAURI_OS = new Set(['linux', 'macos', 'windows']);
|
||||
export type DesktopTauriPlatform = 'linux' | 'macos' | 'windows';
|
||||
|
||||
const DESKTOP_TAURI_OS = new Set<DesktopTauriPlatform>(['linux', 'macos', 'windows']);
|
||||
|
||||
export function getDesktopTauriPlatform(): DesktopTauriPlatform | undefined {
|
||||
if (!isTauri()) return undefined;
|
||||
const os = osType() as string;
|
||||
return DESKTOP_TAURI_OS.has(os as DesktopTauriPlatform)
|
||||
? (os as DesktopTauriPlatform)
|
||||
: undefined;
|
||||
}
|
||||
|
||||
export function isDesktopTauri(): boolean {
|
||||
return isTauri() && DESKTOP_TAURI_OS.has(osType());
|
||||
return getDesktopTauriPlatform() !== undefined;
|
||||
}
|
||||
|
||||
export function hasControllingServiceWorker(): boolean {
|
||||
|
||||
Reference in new issue
Block a user