tauri icon indicating copy to clipboard operation
tauri copied to clipboard

[bug] Webview error

Open ar-cyber opened this issue 6 months ago • 4 comments

Describe the bug

When I build an app for android it builds fine. When I launch it on a device it crashes immediately.

Reproduction

  1. Build the program using npm run tauri android build
  2. Sign the APK
  3. Launch the APK

Expected behavior

It loads to a page.

Full tauri info output

[✔] Environment
    - OS: Windows 10.0.19045 x86_64 (X64)
    ✔ WebView2: 136.0.3240.92
    ✔ MSVC: Visual Studio Community 2022
    ✔ rustc: 1.87.0 (17067e9ac 2025-05-09)
    ✔ cargo: 1.87.0 (99624be96 2025-05-06)
    ✔ rustup: 1.28.2 (e4f3ad6f8 2025-04-28)
    ✔ Rust toolchain: stable-x86_64-pc-windows-msvc (default)
    - node: 22.16.0
    - npm: 10.9.2

[-] Packages
    - tauri 🦀: 2.5.1
    - tauri-build 🦀: 2.2.0
    - wry 🦀: 0.51.2
    - tao 🦀: 0.33.0
    - @tauri-apps/api : 2.5.0
    - @tauri-apps/cli : 2.5.0

[-] Plugins
    - tauri-plugin-deep-link 🦀: 2.3.0
    - @tauri-apps/plugin-deep-link : 2.3.0
    - tauri-plugin-notification 🦀: 2.2.2
    - @tauri-apps/plugin-notification : 2.2.2
    - tauri-plugin-single-instance 🦀: 2.2.4
    - @tauri-apps/plugin-single-instance : not installed!
    - tauri-plugin-opener 🦀: 2.2.6, (outdated, latest: 2.2.7)
    - @tauri-apps/plugin-opener : 2.2.6 (outdated, latest: 2.2.7)

[-] App
    - build-type: bundle
    - CSP: unset
    - frontendDist: ../build
    - devUrl: http://localhost:1420/
    - framework: Svelte
    - bundler: Vite

Stack trace

Please view attachment

Additional context

THE PROVIDED STACK TRACE IS THE OUTPUT OF adb logcat

logcat.txt

ar-cyber avatar Jun 01 '25 11:06 ar-cyber

can you show us your session.rs and/or settings.rs file(s)?

FabianLars avatar Jun 01 '25 12:06 FabianLars

Where are they located?

ar-cyber avatar Jun 01 '25 21:06 ar-cyber

idk, those are the files the stack trace complained about and it sounded like they are part of your src-tauri/src/ directory.

Are they not? Did you even add custom rust code?

FabianLars avatar Jun 02 '25 07:06 FabianLars

Session.rs:

use serde::{Deserialize, Serialize};
use std::{
    fs,
    io::{self, Read},
    path::PathBuf,
};

/// Location: `$DATA_DIR/DesQTA/session.json`
fn session_file() -> PathBuf {
    // e.g. %APPDATA%/DesQTA on Windows, ~/.local/share/DesQTA on Linux/macOS
    let mut dir = dirs_next::data_dir().expect("Unable to determine data dir");
    dir.push("DesQTA");
    if !dir.exists() {
        fs::create_dir_all(&dir).expect("Unable to create data dir");
    }
    dir.push("session.json");
    dir
}

/// Saved session state.
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
pub struct Session {
    pub base_url: String,
    pub jsessionid: String,
    pub additional_cookies: Vec<Cookie>,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct Cookie {
    pub name: String,
    pub value: String,
    pub domain: Option<String>,
    pub path: Option<String>,
}

impl Session {
    /// Load from disk; returns empty/default if none.
    pub fn load() -> Self {
        let path = session_file();
        if let Ok(mut file) = fs::File::open(path) {
            let mut contents = String::new();
            if file.read_to_string(&mut contents).is_ok() {
                if let Ok(sess) = serde_json::from_str::<Session>(&contents) {
                    return sess;
                }
            }
        }
        Session {
            base_url: String::new(),
            jsessionid: String::new(),
            additional_cookies: Vec::new(),
        }
    }

    /// Persist to disk.
    pub fn save(&self) -> io::Result<()> {
        let path = session_file();
        fs::write(path, serde_json::to_string(self).unwrap())
    }

    /// True if both URL and cookie are present.
    pub fn exists() -> bool {
        let s = Self::load();
        !(s.base_url.is_empty() || s.jsessionid.is_empty())
    }

    /// Clear the session data and remove the file
    pub fn clear() -> io::Result<()> {
        let path = session_file();
        if path.exists() {
            fs::remove_file(path)?;
        }
        Ok(())
    }
}

settings.rs:

use serde::{Deserialize, Serialize};
use std::{
    fs,
    io::{self, Read},
    path::PathBuf,
};

/// Location: `$DATA_DIR/DesQTA/settings.json`
fn settings_file() -> PathBuf {
    let mut dir = dirs_next::data_dir().expect("Unable to determine data dir");
    dir.push("DesQTA");
    if !dir.exists() {
        fs::create_dir_all(&dir).expect("Unable to create data dir");
    }
    dir.push("settings.json");
    dir
}

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct Settings {
    pub shortcuts: Vec<Shortcut>,
    pub weather_enabled: bool,
    pub weather_city: String,
    pub weather_country: String,
    pub reminders_enabled: bool,
    pub force_use_location: bool,
}

impl Default for Settings {
    fn default() -> Self {
        Self {
            shortcuts: Vec::new(),
            weather_enabled: false,
            force_use_location: false,
            weather_city: String::new(),
            weather_country: String::new(),
            reminders_enabled: true,
        }
    }
}

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct Shortcut {
    pub name: String,
    pub icon: String,
    pub url: String,
}

impl Settings {
    /// Load from disk; returns default if none.
    pub fn load() -> Self {
        let path = settings_file();
        if let Ok(mut file) = fs::File::open(path) {
            let mut contents = String::new();
            if file.read_to_string(&mut contents).is_ok() {
                if let Ok(settings) = serde_json::from_str::<Settings>(&contents) {
                    return settings;
                }
            }
        }
        Settings::default()
    }

    /// Persist to disk.
    pub fn save(&self) -> io::Result<()> {
        let path = settings_file();
        fs::write(path, serde_json::to_string(self).unwrap())
    }
}

#[tauri::command]
pub fn get_settings() -> Settings {
    Settings::load()
}

#[tauri::command]
pub fn save_settings(new_settings: Settings) -> Result<(), String> {
    println!("Saving settings: {:?}", new_settings);
    new_settings.save().map_err(|e| e.to_string())
}

ar-cyber avatar Jun 02 '25 08:06 ar-cyber