mirror of
https://github.com/tauri-apps/tauri.git
synced 2026-04-03 10:11:15 +02:00
Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
This commit is contained in:
@@ -30,7 +30,7 @@ thiserror = "1.0.24"
|
||||
once_cell = "1.7.2"
|
||||
tauri-api = { version = "0.7.5", path = "../tauri-api" }
|
||||
tauri-macros = { version = "0.1", path = "../tauri-macros" }
|
||||
wry = { git = "https://github.com/tauri-apps/wry", rev = "39575983dbd128fbbcde933d742b33b691fd1def" }
|
||||
wry = { git = "https://github.com/tauri-apps/wry", rev = "8dd58eec77d4c89491b1af427d06c4ee6cfa8e58" }
|
||||
rand = "0.8"
|
||||
|
||||
[build-dependencies]
|
||||
|
||||
@@ -154,6 +154,9 @@ pub trait WebviewBuilderExt: Sized {
|
||||
/// Whether the icon was set or not.
|
||||
fn has_icon(&self) -> bool;
|
||||
|
||||
/// User data path for the webview. Actually only supported on Windows.
|
||||
fn user_data_path(self, user_data_path: Option<PathBuf>) -> Self;
|
||||
|
||||
/// Builds the webview instance.
|
||||
fn finish(self) -> crate::Result<Self::Webview>;
|
||||
}
|
||||
|
||||
@@ -3,12 +3,17 @@ use super::{
|
||||
RpcRequest, WebviewBuilderExt, WebviewBuilderExtPrivate, WebviewRpcHandler, WindowConfig,
|
||||
};
|
||||
|
||||
use crate::plugin::PluginStore;
|
||||
use once_cell::sync::Lazy;
|
||||
|
||||
use crate::plugin::PluginStore;
|
||||
#[cfg(target_os = "windows")]
|
||||
use std::fs::create_dir_all;
|
||||
#[cfg(target_os = "windows")]
|
||||
use tauri_api::path::{resolve_path, BaseDirectory};
|
||||
|
||||
use std::{
|
||||
convert::{TryFrom, TryInto},
|
||||
path::PathBuf,
|
||||
sync::{Arc, Mutex},
|
||||
};
|
||||
|
||||
@@ -65,6 +70,30 @@ impl From<WindowConfig> for wry::Attributes {
|
||||
if let Some(y) = window_config.0.y {
|
||||
webview = webview.y(y);
|
||||
}
|
||||
|
||||
// If we are on windows use App Data Local as user_data
|
||||
// to prevent any bundled application to failed.
|
||||
|
||||
// Should fix:
|
||||
// https://github.com/tauri-apps/tauri/issues/1365
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
{
|
||||
//todo(lemarier): we should replace with AppName from the context
|
||||
// will be available when updater will merge
|
||||
|
||||
// https://docs.rs/dirs-next/2.0.0/dirs_next/fn.data_local_dir.html
|
||||
|
||||
let local_app_data = resolve_path("Tauri", Some(BaseDirectory::LocalData));
|
||||
|
||||
if let Ok(user_data_dir) = local_app_data {
|
||||
// Make sure the directory exist without panic
|
||||
if let Ok(()) = create_dir_all(&user_data_dir) {
|
||||
webview = webview.user_data_path(Some(user_data_dir));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
webview
|
||||
}
|
||||
}
|
||||
@@ -172,6 +201,11 @@ impl WebviewBuilderExt for wry::Attributes {
|
||||
self.icon.is_some()
|
||||
}
|
||||
|
||||
fn user_data_path(mut self, user_data_path: Option<PathBuf>) -> Self {
|
||||
self.user_data_path = user_data_path;
|
||||
self
|
||||
}
|
||||
|
||||
fn finish(self) -> crate::Result<Self::Webview> {
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user