diff --git a/apps/app-frontend/src/helpers/ads.js b/apps/app-frontend/src/helpers/ads.js index ec0113f9b..f4a6430b2 100644 --- a/apps/app-frontend/src/helpers/ads.js +++ b/apps/app-frontend/src/helpers/ads.js @@ -1,11 +1,11 @@ import { invoke } from '@tauri-apps/api/core' export async function init_ads_window(overrideShown = false) { - return await invoke('plugin:ads|init_ads_window', { overrideShown }) + return await invoke('plugin:ads|init_ads_window', { overrideShown, dpr: window.devicePixelRatio }) } export async function show_ads_window() { - return await invoke('plugin:ads|show_ads_window') + return await invoke('plugin:ads|show_ads_window', { dpr: window.devicePixelRatio }) } export async function hide_ads_window(reset) { diff --git a/apps/app/src/api/ads.rs b/apps/app/src/api/ads.rs index 232be8298..ecf6511b4 100644 --- a/apps/app/src/api/ads.rs +++ b/apps/app/src/api/ads.rs @@ -54,12 +54,12 @@ pub fn init() -> TauriPlugin { fn get_webview_position( app: &tauri::AppHandle, + dpr: f32, ) -> crate::api::Result<(PhysicalPosition, PhysicalSize)> { let main_window = app.get_window("main").unwrap(); - let scale_factor = main_window.scale_factor()? as f32; - let width = 300.0 * scale_factor; - let height = 250.0 * scale_factor; + let width = 300.0 * dpr; + let height = 250.0 * dpr; let main_window_size = main_window.inner_size()?; let x = (main_window_size.width as f32) - width; @@ -75,6 +75,7 @@ fn get_webview_position( #[cfg(not(target_os = "linux"))] pub async fn init_ads_window( app: tauri::AppHandle, + dpr: f32, override_shown: bool, ) -> crate::api::Result<()> { use tauri::WebviewUrl; @@ -87,7 +88,7 @@ pub async fn init_ads_window( state.shown = true; } - if let Ok((position, size)) = get_webview_position(&app) { + if let Ok((position, size)) = get_webview_position(&app, dpr) { if let Some(webview) = app.webviews().get("ads-window") { if state.shown { let _ = webview.set_position(position); @@ -129,13 +130,14 @@ pub async fn init_ads_window() {} #[tauri::command] pub async fn show_ads_window( app: tauri::AppHandle, + dpr: f32, ) -> crate::api::Result<()> { if let Some(webview) = app.webviews().get("ads-window") { let state = app.state::>(); let state = state.read().await; if state.shown { - let (position, size) = get_webview_position(&app)?; + let (position, size) = get_webview_position(&app, dpr)?; let _ = webview.set_size(size); let _ = webview.set_position(position); }