Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose the data directory in the desktop config #905

Merged
merged 1 commit into from
Mar 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions packages/desktop/src/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub struct Config {
pub(crate) pre_rendered: Option<String>,
pub(crate) disable_context_menu: bool,
pub(crate) resource_dir: Option<PathBuf>,
pub(crate) data_dir: Option<PathBuf>,
pub(crate) custom_head: Option<String>,
pub(crate) custom_index: Option<String>,
pub(crate) root_name: String,
Expand All @@ -44,6 +45,7 @@ impl Config {
pre_rendered: None,
disable_context_menu: !cfg!(debug_assertions),
resource_dir: None,
data_dir: None,
custom_head: None,
custom_index: None,
root_name: "main".to_string(),
Expand All @@ -56,6 +58,14 @@ impl Config {
self
}

/// set the directory where data will be stored in release mode.
///
/// > Note: This **must** be set when bundling on Windows.
pub fn with_data_directory(mut self, path: impl Into<PathBuf>) -> Self {
self.data_dir = Some(path.into());
self
}

/// Set whether or not the right-click context menu should be disabled.
pub fn with_disable_context_menu(mut self, disable: bool) -> Self {
self.disable_context_menu = disable;
Expand Down
7 changes: 5 additions & 2 deletions packages/desktop/src/webview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use tao::event_loop::{EventLoopProxy, EventLoopWindowTarget};
pub use wry;
pub use wry::application as tao;
use wry::application::window::Window;
use wry::webview::{WebView, WebViewBuilder};
use wry::webview::{WebContext, WebView, WebViewBuilder};

pub fn build(
cfg: &mut Config,
Expand All @@ -33,6 +33,8 @@ pub fn build(
));
}

let mut web_context = WebContext::new(cfg.data_dir.clone());

let mut webview = WebViewBuilder::new(window)
.unwrap()
.with_transparent(cfg.window.window.transparent)
Expand All @@ -52,7 +54,8 @@ pub fn build(
.as_ref()
.map(|handler| handler(window, evet))
.unwrap_or_default()
});
})
.with_web_context(&mut web_context);

for (name, handler) in cfg.protocols.drain(..) {
webview = webview.with_custom_protocol(name, handler)
Expand Down