You've already forked AstralRinth
forked from didirus/AstralRinth
Mute audio from playing in ads (#2471)
* Mute audio from playing in ads * Update tauri version, get rid of custom * bump wry * fix more * Fix lint
This commit is contained in:
@@ -4,6 +4,7 @@ use std::time::{Duration, Instant};
|
||||
use tauri::plugin::TauriPlugin;
|
||||
use tauri::{Emitter, LogicalPosition, LogicalSize, Manager, Runtime};
|
||||
use tauri_plugin_shell::ShellExt;
|
||||
use theseus::settings;
|
||||
use tokio::sync::RwLock;
|
||||
|
||||
pub struct AdsState {
|
||||
@@ -14,6 +15,8 @@ pub struct AdsState {
|
||||
pub malicious_origins: HashSet<String>,
|
||||
}
|
||||
|
||||
const AD_LINK: &str = "https://modrinth.com/wrapper/app-ads-cookie";
|
||||
|
||||
pub fn init<R: Runtime>() -> TauriPlugin<R> {
|
||||
tauri::plugin::Builder::<R>::new("ads")
|
||||
.setup(|app, _api| {
|
||||
@@ -31,11 +34,7 @@ pub fn init<R: Runtime>() -> TauriPlugin<R> {
|
||||
loop {
|
||||
if let Some(webview) = app.webviews().get_mut("ads-window")
|
||||
{
|
||||
let _ = webview.navigate(
|
||||
"https://modrinth.com/wrapper/app-ads-cookie"
|
||||
.parse()
|
||||
.unwrap(),
|
||||
);
|
||||
let _ = webview.navigate(AD_LINK.parse().unwrap());
|
||||
}
|
||||
|
||||
tokio::time::sleep(std::time::Duration::from_secs(60 * 5))
|
||||
@@ -52,6 +51,7 @@ pub fn init<R: Runtime>() -> TauriPlugin<R> {
|
||||
show_ads_window,
|
||||
record_ads_click,
|
||||
open_link,
|
||||
get_ads_personalization,
|
||||
])
|
||||
.build()
|
||||
}
|
||||
@@ -84,11 +84,11 @@ pub async fn init_ads_window<R: Runtime>(
|
||||
let _ = webview.set_size(LogicalSize::new(width, height));
|
||||
}
|
||||
} else if let Some(window) = app.get_window("main") {
|
||||
let window = window.add_child(
|
||||
let _ = window.add_child(
|
||||
tauri::webview::WebviewBuilder::new(
|
||||
"ads-window",
|
||||
WebviewUrl::External(
|
||||
"https://modrinth.com/wrapper/app-ads-cookie".parse().unwrap(),
|
||||
AD_LINK.parse().unwrap(),
|
||||
),
|
||||
)
|
||||
.initialization_script(LINK_SCRIPT)
|
||||
@@ -102,12 +102,6 @@ pub async fn init_ads_window<R: Runtime>(
|
||||
},
|
||||
LogicalSize::new(width, height),
|
||||
);
|
||||
|
||||
if let Ok(window) = window {
|
||||
window.listen_any("click", |event| {
|
||||
println!("click: {:?}", event);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@@ -214,3 +208,9 @@ pub async fn open_link<R: Runtime>(
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn get_ads_personalization() -> crate::api::Result<bool> {
|
||||
let res = settings::get().await?;
|
||||
Ok(res.personalized_ads)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user