Skip to content

Commit

Permalink
Use DPR from browser
Browse files Browse the repository at this point in the history
  • Loading branch information
Geometrically committed Dec 14, 2024
1 parent f8c8d9a commit 53d4f64
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
4 changes: 2 additions & 2 deletions apps/app-frontend/src/helpers/ads.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
12 changes: 7 additions & 5 deletions apps/app/src/api/ads.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ pub fn init<R: Runtime>() -> TauriPlugin<R> {

fn get_webview_position<R: Runtime>(
app: &tauri::AppHandle<R>,
dpr: f32,
) -> crate::api::Result<(PhysicalPosition<f32>, PhysicalSize<f32>)> {
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;
Expand All @@ -75,6 +75,7 @@ fn get_webview_position<R: Runtime>(
#[cfg(not(target_os = "linux"))]
pub async fn init_ads_window<R: Runtime>(
app: tauri::AppHandle<R>,
dpr: f32,
override_shown: bool,
) -> crate::api::Result<()> {
use tauri::WebviewUrl;
Expand All @@ -87,7 +88,7 @@ pub async fn init_ads_window<R: Runtime>(
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);
Expand Down Expand Up @@ -129,13 +130,14 @@ pub async fn init_ads_window() {}
#[tauri::command]
pub async fn show_ads_window<R: Runtime>(
app: tauri::AppHandle<R>,
dpr: f32,
) -> crate::api::Result<()> {
if let Some(webview) = app.webviews().get("ads-window") {
let state = app.state::<RwLock<AdsState>>();
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);
}
Expand Down

0 comments on commit 53d4f64

Please sign in to comment.