fix config dir

This commit is contained in:
Tim-Paik 2022-02-05 18:05:04 +08:00
parent a242b1b12d
commit f965abf581
Signed by: Tim-Paik
GPG Key ID: DC36A050DB42566D
4 changed files with 32 additions and 16 deletions

View File

@ -238,7 +238,7 @@ impl Default for Config {
max_inner_size: None, max_inner_size: None,
resizable: true, resizable: true,
fullscreen: false, fullscreen: false,
title: "".to_string(), title: "".into(),
maximized: false, maximized: false,
visible: true, visible: true,
transparent: false, transparent: false,
@ -246,9 +246,9 @@ impl Default for Config {
always_on_top: false, always_on_top: false,
window_icon: None, window_icon: None,
spa: false, spa: false,
url: Some("/index.html".to_string()), url: Some("/index.html".into()),
html: None, html: None,
initialization_script: Some("".to_string()), initialization_script: Some("".into()),
} }
} }
} }

View File

@ -30,7 +30,7 @@ fn options() -> fs::OpenOptions {
fn main() -> wry::Result<()> { fn main() -> wry::Result<()> {
let arg = std::env::args() let arg = std::env::args()
.nth(1) .nth(1)
.unwrap_or_else(|| "neutauri.toml".to_string()); .unwrap_or_else(|| "neutauri.toml".into());
if arg == "--help" || arg == "-h" { if arg == "--help" || arg == "-h" {
println!("Usage: neutauri_bundler [neutauri.toml]"); println!("Usage: neutauri_bundler [neutauri.toml]");
return Ok(()); return Ok(());

View File

@ -206,7 +206,7 @@ impl Default for Config {
max_inner_size: None, max_inner_size: None,
resizable: true, resizable: true,
fullscreen: false, fullscreen: false,
title: "".to_string(), title: "".into(),
maximized: false, maximized: false,
visible: true, visible: true,
transparent: false, transparent: false,
@ -214,9 +214,9 @@ impl Default for Config {
always_on_top: false, always_on_top: false,
window_icon: None, window_icon: None,
spa: false, spa: false,
url: Some("/index.html".to_string()), url: Some("/index.html".into()),
html: None, html: None,
initialization_script: Some("".to_string()), initialization_script: Some("".into()),
} }
} }
} }

View File

@ -1,15 +1,15 @@
#![windows_subsystem = "windows"] #![windows_subsystem = "windows"]
use std::path; use std::path::PathBuf;
use wry::{ use wry::{
application::{ application::{
dpi::{PhysicalSize, Size}, dpi::{PhysicalSize, Size},
event::{Event, WindowEvent, StartCause}, event::{Event, StartCause, WindowEvent},
event_loop::{ControlFlow, EventLoop}, event_loop::{ControlFlow, EventLoop},
window::{Fullscreen, Icon, Window, WindowBuilder}, window::{Fullscreen, Icon, Window, WindowBuilder},
}, },
webview::{RpcRequest, WebViewBuilder, WebContext}, webview::{RpcRequest, WebContext, WebViewBuilder},
}; };
mod data; mod data;
@ -114,13 +114,29 @@ fn main() -> wry::Result<()> {
}; };
let path = std::env::current_exe()?; let path = std::env::current_exe()?;
let path = path.file_stem().unwrap_or_else(|| "neutauri_app".as_ref()); let path = path.file_stem().unwrap_or_else(|| "neutauri_app".as_ref());
let mut web_context = if cfg!(windows) { let mut web_context = if cfg!(target_os = "windows") {
let config_path = std::env::var("APPDATA").unwrap_or_else(|_| ".".into()); let config_path = match std::env::var("APPDATA") {
let config_path = path::Path::new(&config_path).join(path); Ok(dir) => PathBuf::from(dir),
Err(_) => PathBuf::from("."),
}
.join(path);
WebContext::new(Some(config_path)) WebContext::new(Some(config_path))
} else if cfg!(linux) { } else if cfg!(target_os = "linux") {
let config_path = std::env::var("HOME").unwrap_or_else(|_| ".".into()); let config_path = match std::env::var("XDG_CONFIG_DIR") {
let config_path = path::Path::new(&config_path).join(".local/share/").join(path); Ok(dir) => PathBuf::from(dir),
Err(_) => match std::env::var("HOME") {
Ok(dir) => PathBuf::from(dir).join(".config"),
Err(_) => PathBuf::from("."),
},
}
.join(path);
WebContext::new(Some(config_path))
} else if cfg!(target_os = "macos") {
let config_path = match std::env::var("HOME") {
Ok(dir) => PathBuf::from(dir).join("Library/Application Support/"),
Err(_) => PathBuf::from("."),
}
.join(path);
WebContext::new(Some(config_path)) WebContext::new(Some(config_path))
} else { } else {
WebContext::new(None) WebContext::new(None)