remove browser and android_fs crates

This commit is contained in:
2025-09-26 15:38:13 +02:00
parent d025819888
commit b36b4e4280
4 changed files with 0 additions and 692 deletions

View File

@ -1,94 +0,0 @@
#[cfg(target_os = "android")]
#[tauri::command]
pub async fn request_storage_permission(app_handle: tauri::AppHandle) -> Result<String, String> {
Ok("Settings opened - Enable 'Allow management of all files'".to_string())
/* use tauri_plugin_opener::OpenerExt;
// Korrekte Android Settings Intent
let intent_uri = "android.settings.MANAGE_ALL_FILES_ACCESS_PERMISSION";
match app.opener().open_url(intent_uri, None::<&str>) {
Ok(_) => Ok("Settings opened - Enable 'Allow management of all files'".to_string()),
Err(_) => {
// Fallback: App-spezifische Settings
let app_settings = format!(
"android.settings.APPLICATION_DETAILS_SETTINGS?package={}",
app.config().identifier
);
match app.opener().open_url(&app_settings, None::<&str>) {
Ok(_) => Ok("App settings opened - Go to Permissions > Files and media".to_string()),
Err(_) => Ok("Manually go to: Settings > Apps > Special app access > All files access > HaexHub > Allow".to_string())
}
}
}*/
}
#[cfg(target_os = "android")]
#[tauri::command]
pub async fn has_storage_permission() -> Result<bool, String> {
use std::path::Path;
// Teste Schreibzugriff auf externen Speicher
let test_paths = [
"/storage/emulated/0/Android",
"/sdcard/Android",
"/storage/emulated/0",
];
for path in &test_paths {
if Path::new(path).exists() {
// Versuche Testdatei zu erstellen
let test_file = format!("{}/haex_test.tmp", path);
match std::fs::write(&test_file, "test") {
Ok(_) => {
let _ = std::fs::remove_file(&test_file);
return Ok(true);
}
Err(_) => continue,
}
}
}
Ok(false)
}
#[cfg(target_os = "android")]
#[tauri::command]
pub async fn get_external_storage_paths() -> Result<Vec<String>, String> {
let mut paths = Vec::new();
let common_paths = [
"/storage/emulated/0",
"/sdcard",
"/storage/emulated/0/Download",
"/storage/emulated/0/Documents",
"/storage/emulated/0/Pictures",
"/storage/emulated/0/DCIM",
];
for path in &common_paths {
if std::path::Path::new(path).exists() {
paths.push(path.to_string());
}
}
Ok(paths)
}
#[cfg(not(target_os = "android"))]
#[tauri::command]
pub async fn request_storage_permission(_app: tauri::AppHandle) -> Result<String, String> {
Ok("aaaaaaaa".to_string())
}
#[cfg(not(target_os = "android"))]
#[tauri::command]
pub async fn has_storage_permission() -> Result<bool, String> {
Ok(true)
}
#[cfg(not(target_os = "android"))]
#[tauri::command]
pub async fn get_external_storage_paths() -> Result<Vec<String>, String> {
Ok(vec![])
}

View File

@ -1,285 +0,0 @@
//mod middleware;
use std::collections::HashMap;
use std::sync::{Arc, Mutex};
use tauri::{webview, AppHandle, LogicalPosition, LogicalSize, Manager, WebviewUrl, Window};
//use uuid::Uuid;
#[derive(Debug, Clone)]
pub struct Tab {
pub id: String,
pub webview_label: String,
pub title: String,
pub url: String,
pub is_loading: bool,
pub is_visible: bool,
}
pub struct BrowserManager {
tabs: Arc<Mutex<HashMap<String, Tab>>>,
active_tab_id: Arc<Mutex<Option<String>>>,
//middleware: Arc<RoutingMiddleware>,
}
impl BrowserManager {
pub fn new() -> Self {
Self {
tabs: Arc::new(Mutex::new(HashMap::new())),
active_tab_id: Arc::new(Mutex::new(None)),
//middleware: Arc::new(RoutingMiddleware::new()),
}
}
/* pub async fn create_window(app: tauri::AppHandle) -> Result<tauri::WebviewWindow, _> {
let webview_window = tauri::WebviewWindowBuilder::new(
&app,
"label",
tauri::WebviewUrl::App("index.html".into()),
)
.build()
.unwrap();
Ok(webview_window);
} */
pub fn create_tab(&self, app: AppHandle, url: &str) {
// Generiere eine eindeutige ID für den Tab
/* let tab_id = Uuid::new_v4().to_string();
let webview_label = format!("webview-{}", tab_id); */
// Überprüfe URL mit Middleware
//let processed_url = self.middleware.process_url(url);
// Hole das Hauptfenster
let main_window = app.get_webview_window("main").unwrap();
// Berechne die Position und Größe für den Webview
// Hier nehmen wir an, dass wir einen Header-Bereich von 100 Pixeln haben
/* let window_size = main_window.inner_size()?;
let header_height = 100.0;
let webview_position = LogicalPosition::new(0.0, header_height);
let webview_size = LogicalSize::new(window_size.width, window_size.height - header_height);
*/
/* let webview = tauri::WebviewWindowBuilder::new(
&app,
"label",
//WebviewUrl::External(processed_url.parse().unwrap()),
WebviewUrl::External(url),
)
.build()
.unwrap() */
/* .on_navigation(move |url| {
// Middleware für Navigation anwenden
self.middleware.process_navigation(url.as_str())
})
.on_web_resource_request(move |request, response| {
// Middleware für HTTP-Anfragen anwenden
self.middleware.process_request(request, response)
}); */
// Erstelle Tab-Objekt
/* let tab = Tab {
id: tab_id.clone(),
webview_label: webview_label.clone(),
title: "Neuer Tab".to_string(),
url: processed_url.to_string(),
is_loading: true,
is_visible: false,
}; */
// Speichere Tab
/* {
let mut tabs = self.tabs.lock().unwrap();
tabs.insert(tab_id.clone(), tab.clone());
} */
// Setze als aktiven Tab
//self.activate_tab(app, &tab_id)?;
// Injiziere die Webview-Bridge
/* let script = include_str!("../assets/webview-bridge.js");
webview.evaluate_script(script)?; */
// Registriere Event-Handler für Titeländerungen
let tab_manager = self.clone();
//let tab_id_clone = tab_id.clone();
/* webview.listen("tauri://title-changed", move |event| {
if let Some(title) = event.payload().and_then(|p| p.as_str()) {
tab_manager.update_tab_title(&tab_id_clone, title);
}
}); */
// Registriere Event-Handler für Ladestatus
let tab_manager = self.clone();
//let tab_id_clone = tab_id.clone();
/* webview.listen("tauri://load-changed", move |event| {
if let Some(status) = event.payload().and_then(|p| p.as_str()) {
let is_loading = status == "loading";
tab_manager.update_tab_loading_status(&tab_id_clone, is_loading);
}
}); */
//Ok()
}
pub fn close_tab(&self, app: &AppHandle, tab_id: &str) -> Result<(), tauri::Error> {
// Hole das Hauptfenster
let main_window = app.get_webview_window("main").unwrap();
// Entferne Tab aus der Verwaltung
let webview_label = {
let mut tabs = self.tabs.lock().unwrap();
if let Some(tab) = tabs.remove(tab_id) {
tab.webview_label
} else {
return Ok(());
}
};
// Entferne den Webview
//main_window.remove_child(&webview_label)?;
// Aktualisiere aktiven Tab, falls nötig
{
let mut active_tab_id = self.active_tab_id.lock().unwrap();
if active_tab_id.as_ref().map_or(false, |id| id == tab_id) {
// Wähle einen anderen Tab als aktiv
let tabs = self.tabs.lock().unwrap();
*active_tab_id = tabs.keys().next().cloned();
// Aktiviere den neuen Tab, falls vorhanden
if let Some(new_active_id) = active_tab_id.clone() {
drop(active_tab_id); // Mutex freigeben vor dem rekursiven Aufruf
self.activate_tab(app, &new_active_id)?;
}
}
}
Ok(())
}
pub fn activate_tab(&self, app: &AppHandle, tab_id: &str) -> Result<(), tauri::Error> {
// Hole das Hauptfenster
let main_window = app.get_webview_window("main").unwrap();
// Setze Tab als aktiv
{
let mut active_tab_id = self.active_tab_id.lock().unwrap();
*active_tab_id = Some(tab_id.to_string());
}
// Verstecke alle anderen Tabs und zeige den aktiven
let mut tabs = self.tabs.lock().unwrap();
for (id, tab) in tabs.iter_mut() {
if id == tab_id {
// Zeige den aktiven Tab
/* main_window
.get_webview_window(&tab.webview_label)?
.set_visible(true)?; */
tab.is_visible = true;
} else {
// Verstecke alle anderen Tabs
/* main_window
.get_webview_window(&tab.webview_label)?
.set_visible(false)?; */
tab.is_visible = false;
}
}
Ok(())
}
pub fn navigate_to_url(
&self,
app: &AppHandle,
tab_id: &str,
url: &str,
) -> Result<(), tauri::Error> {
// Überprüfe URL mit Middleware
//let processed_url = self.middleware.process_url(url);
// Aktualisiere URL im Tab
{
let mut tabs = self.tabs.lock().unwrap();
if let Some(tab) = tabs.get_mut(tab_id) {
tab.url = url.to_string() //processed_url.to_string();
}
}
// Navigiere zum URL im Webview
let tabs = self.tabs.lock().unwrap();
if let Some(tab) = tabs.get(tab_id) {
let main_window = app.get_webview_window("main").unwrap();
/* let webview = main_window.get_webview_window(&tab.webview_label)?;
webview.navigate(&processed_url)?; */
}
Ok(())
}
pub fn get_all_tabs(&self) -> Vec<Tab> {
let tabs = self.tabs.lock().unwrap();
tabs.values().cloned().collect()
}
pub fn get_active_tab_id(&self) -> Option<String> {
let active_tab_id = self.active_tab_id.lock().unwrap();
active_tab_id.clone()
}
pub fn update_tab_title(&self, tab_id: &str, title: &str) {
let mut tabs = self.tabs.lock().unwrap();
if let Some(tab) = tabs.get_mut(tab_id) {
tab.title = title.to_string();
}
}
pub fn update_tab_loading_status(&self, tab_id: &str, is_loading: bool) {
let mut tabs = self.tabs.lock().unwrap();
if let Some(tab) = tabs.get_mut(tab_id) {
tab.is_loading = is_loading;
}
}
// Weitere Methoden für Browser-Navigation
pub fn go_back(&self, app: &AppHandle, tab_id: &str) -> Result<(), tauri::Error> {
let tabs = self.tabs.lock().unwrap();
if let Some(tab) = tabs.get(tab_id) {
let main_window = app.get_webview_window("main").unwrap();
/* let webview = main_window.get_webview(&tab.webview_label)?;
webview.evaluate_script("window.history.back()")?; */
}
Ok(())
}
pub fn go_forward(&self, app: &AppHandle, tab_id: &str) -> Result<(), tauri::Error> {
let tabs = self.tabs.lock().unwrap();
if let Some(tab) = tabs.get(tab_id) {
let main_window = app.get_webview_window("main").unwrap();
/* let webview = main_window.get_webview(&tab.webview_label)?;
webview.evaluate_script("window.history.forward()")?; */
}
Ok(())
}
pub fn inject_content_script(
&self,
app: &AppHandle,
tab_id: &str,
script: &str,
) -> Result<(), tauri::Error> {
let tabs = self.tabs.lock().unwrap();
if let Some(tab) = tabs.get(tab_id) {
let main_window = app.get_webview_window("main").unwrap();
/* let webview = main_window.get_webview(&tab.webview_label)?;
webview.evaluate_script(script)?; */
}
Ok(())
}
pub fn clone(&self) -> Self {
Self {
tabs: Arc::clone(&self.tabs),
active_tab_id: Arc::clone(&self.active_tab_id),
//middleware: Arc::clone(&self.middleware),
}
}
}

View File

@ -1,125 +0,0 @@
use std::sync::{Arc, Mutex};
use tauri::http::{Request, Response, ResponseBuilder};
pub struct RoutingMiddleware {
extensions: Arc<Mutex<Vec<Box<dyn MiddlewareExtension + Send + Sync>>>>,
}
pub trait MiddlewareExtension: Send + Sync {
fn name(&self) -> &str;
fn process_url(&self, url: &str) -> String;
fn process_navigation(&self, url: &str) -> bool;
fn process_request(&self, request: &Request, response: &mut Response) -> bool;
}
impl RoutingMiddleware {
pub fn new() -> Self {
let mut middleware = Self {
extensions: Arc::new(Mutex::new(Vec::new())),
};
// Registriere Standard-Erweiterungen
//middleware.register_extension(Box::new(AdBlockerExtension::new()));
middleware
}
pub fn register_extension(&mut self, extension: Box<dyn MiddlewareExtension + Send + Sync>) {
let mut extensions = self.extensions.lock().unwrap();
extensions.push(extension);
}
pub fn process_url(&self, url: &str) -> String {
let extensions = self.extensions.lock().unwrap();
let mut processed_url = url.to_string();
for extension in extensions.iter() {
processed_url = extension.process_url(&processed_url);
}
processed_url
}
pub fn process_navigation(&self, url: &str) -> bool {
let extensions = self.extensions.lock().unwrap();
for extension in extensions.iter() {
if !extension.process_navigation(url) {
return false;
}
}
true
}
pub fn process_request(&self, request: &Request, response: &mut Response) -> bool {
let extensions = self.extensions.lock().unwrap();
for extension in extensions.iter() {
if extension.process_request(request, response) {
return true;
}
}
false
}
}
// Beispiel für eine Ad-Blocker-Erweiterung
struct AdBlockerExtension {
block_patterns: Vec<String>,
}
impl AdBlockerExtension {
fn new() -> Self {
Self {
block_patterns: vec![
"ads".to_string(),
"analytics".to_string(),
"tracker".to_string(),
"banner".to_string(),
],
}
}
fn is_blocked_url(&self, url: &str) -> bool {
for pattern in &self.block_patterns {
if url.contains(pattern) {
return true;
}
}
false
}
}
impl MiddlewareExtension for AdBlockerExtension {
fn name(&self) -> &str {
"AdBlocker"
}
fn process_url(&self, url: &str) -> String {
// Für vollständige Navigationen blockieren wir normalerweise nicht die ganze Seite
url.to_string()
}
fn process_navigation(&self, url: &str) -> bool {
// Blockiere nur vollständige Navigationen zu Werbeseiten
let is_ad_site = url.contains("doubleclick.net")
|| url.contains("googleadservices.com")
|| url.contains("ads.example.com");
!is_ad_site
}
fn process_request(&self, request: &Request, response: &mut Response) -> bool {
let url = request.uri().to_string();
if self.is_blocked_url(&url) {
println!("AdBlocker: Blockiere Anfrage: {}", url);
*response = ResponseBuilder::new()
.status(403)
.body("Zugriff verweigert durch AdBlocker".as_bytes().to_vec())
.unwrap();
return true;
}
false
}
}

View File

@ -1,188 +0,0 @@
use serde::{Deserialize, Serialize};
use tauri::{AppHandle, Manager, State};
mod manager;
#[derive(Serialize, Deserialize)]
pub struct TabInfo {
id: String,
title: String,
url: String,
is_loading: bool,
is_active: bool,
}
// Einfache Kommandos für die Tab-Verwaltung
#[tauri::command]
pub fn create_tab(app_handle: tauri::AppHandle, tab_id: String, url: String) -> Result<(), String> {
let main_window = app_handle
.get_webview_window("main")
.ok_or("Hauptfenster nicht gefunden")?;
let window_size = main_window.inner_size().map_err(|e| e.to_string())?;
// Erstelle eine neue Webview als eigenständiges Fenster
let webview = tauri::WebviewWindowBuilder::new(
&app_handle,
tab_id.clone(),
tauri::WebviewUrl::External(url.parse::<tauri::Url>().map_err(|e| e.to_string())?),
//tauri::WebviewUrl::External("http://google.de"),
)
.title(format!("Tab: {}", tab_id))
.inner_size(window_size.width as f64, window_size.height as f64 - 50.0)
.position(0.0, 50.0)
.build()
.map_err(|e| e.to_string())?;
// Sende die Tab-ID zurück an das Hauptfenster
/* main_window
.emit("tab-created", tab_id)
.map_err(|e| e.to_string())?; */
Ok(())
}
#[tauri::command]
pub fn show_tab(app_handle: tauri::AppHandle, tab_id: String) -> Result<(), String> {
// Hole alle Webview-Fenster
let windows = app_handle.webview_windows();
// Zeige das ausgewählte Tab und verstecke die anderen
for (id, window) in windows {
if id != "main" {
// Hauptfenster nicht verstecken
if id == tab_id {
window.show().map_err(|e| e.to_string())?;
window.set_focus().map_err(|e| e.to_string())?;
} else {
window.hide().map_err(|e| e.to_string())?;
}
}
}
Ok(())
}
#[tauri::command]
pub fn close_tab(app_handle: tauri::AppHandle, tab_id: String) -> Result<(), String> {
if let Some(window) = app_handle.get_webview_window(&tab_id) {
window.close().map_err(|e| e.to_string())?;
}
Ok(())
}
/* #[tauri::command]
pub fn create_tab(app: AppHandle, url: String) -> Result<TabInfo, String> {
let browser_manager = app.state::<manager::BrowserManager>();
match browser_manager.create_tab(&app, &url) {
Ok(tab) => {
let active_tab_id = browser_manager.get_active_tab_id();
let is_active = active_tab_id.as_ref().map_or(false, |id| id == &tab.id);
let main = app.get_webview_window("main");
//main.unwrap().
// Sende Event an Frontend
/* app.emit_all(
"tab-created",
TabInfo {
id: tab.id.clone(),
title: tab.title.clone(),
url: tab.url.clone(),
is_loading: tab.is_loading,
is_active,
},
)
.unwrap(); */
Ok(TabInfo {
id: tab.id,
title: tab.title,
url: tab.url,
is_loading: tab.is_loading,
is_active: true,
})
}
Err(e) => Err(format!("Fehler beim Erstellen des Tabs: {}", e)),
}
} */
/* #[tauri::command]
pub fn close_tab(app: AppHandle, tab_id: String) -> Result<(), String> {
let browser_manager = app.state::<manager::BrowserManager>();
match browser_manager.close_tab(&app, &tab_id) {
Ok(_) => {
// Sende Event an Frontend
//app.emit_all("tab-closed", tab_id).unwrap();
Ok(())
}
Err(e) => Err(format!("Fehler beim Schließen des Tabs: {}", e)),
}
} */
#[tauri::command]
pub fn navigate_to_url(app: AppHandle, tab_id: String, url: String) -> Result<(), String> {
let browser_manager = app.state::<manager::BrowserManager>();
match browser_manager.navigate_to_url(&app, &tab_id, &url) {
Ok(_) => Ok(()),
Err(e) => Err(format!("Fehler bei der Navigation: {}", e)),
}
}
#[tauri::command]
pub fn get_current_url(app: AppHandle, tab_id: String) -> Result<String, String> {
let browser_manager = app.state::<manager::BrowserManager>();
let tabs = browser_manager.get_all_tabs();
for tab in tabs {
if tab.id == tab_id {
return Ok(tab.url);
}
}
Err("Tab nicht gefunden".to_string())
}
#[tauri::command]
pub fn go_back(app: AppHandle, tab_id: String) -> Result<(), String> {
let browser_manager = app.state::<manager::BrowserManager>();
match browser_manager.go_back(&app, &tab_id) {
Ok(_) => Ok(()),
Err(e) => Err(format!("Fehler beim Zurückgehen: {}", e)),
}
}
#[tauri::command]
pub fn go_forward(app: AppHandle, tab_id: String) -> Result<(), String> {
let browser_manager = app.state::<manager::BrowserManager>();
match browser_manager.go_forward(&app, &tab_id) {
Ok(_) => Ok(()),
Err(e) => Err(format!("Fehler beim Vorwärtsgehen: {}", e)),
}
}
#[tauri::command]
pub fn block_resource_request(url: String, resource_type: String) -> bool {
// Diese Funktion wird vom Frontend aufgerufen, um zu prüfen, ob eine Ressource blockiert werden soll
// Die eigentliche Logik wird im JavaScript-Erweiterungssystem implementiert
// Hier könnten Sie zusätzliche Rust-seitige Prüfungen durchführen
println!("Prüfe Ressourcenanfrage: {} (Typ: {})", url, resource_type);
// Einfache Prüfung für Beispielzwecke
url.contains("ads") || url.contains("analytics") || url.contains("tracker")
}
#[tauri::command]
pub fn inject_content_script(app: AppHandle, tab_id: String, script: String) -> Result<(), String> {
let browser_manager = app.state::<manager::BrowserManager>();
match browser_manager.inject_content_script(&app, &tab_id, &script) {
Ok(_) => Ok(()),
Err(e) => Err(format!("Fehler beim Injizieren des Scripts: {}", e)),
}
}