Skip to content

Commit

Permalink
精简Linux平台代码
Browse files Browse the repository at this point in the history
  • Loading branch information
Tlntin committed Dec 10, 2022
1 parent 3e42727 commit 4ae7d7b
Showing 1 changed file with 24 additions and 28 deletions.
52 changes: 24 additions & 28 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,35 +169,31 @@ fn main() -> wry::Result<()> {
// 自定义cookie文件夹,仅用于Linux
// Custom Cookie folder, only for Linux
#[cfg(target_os = "linux")]
let user = std::env::var_os("USER");
#[cfg(target_os = "linux")]
let config_path = match user {
Some(v) => format!(
"/home/{}/.config/{}",
v.into_string().unwrap(),
package_name,
),
None => panic!("can't found any user"),
let webview = {
let user = std::env::var_os("USER");
let config_path = match user {
Some(v) => format!(
"/home/{}/.config/{}",
v.into_string().unwrap(),
package_name,
),
None => panic!("can't found any user"),
};
let data_path = std::path::PathBuf::from(&config_path);
if !std::path::Path::new(&data_path).exists() {
std::fs::create_dir(&data_path)
.unwrap_or_else(|_| panic!("can't create dir {}", &config_path));
}
let mut web_content = WebContext::new(Some(data_path));
WebViewBuilder::new(window)?
// .with_user_agent(user_agent_string)
.with_url(&url.to_string())?
.with_devtools(cfg!(feature = "devtools"))
.with_initialization_script(include_str!("pake.js"))
.with_ipc_handler(handler)
.with_web_context(&mut web_content)
.build()?
};
#[cfg(target_os = "linux")]
let data_path = std::path::PathBuf::from(&config_path);
#[cfg(target_os = "linux")]
if !std::path::Path::new(&data_path).exists() {
std::fs::create_dir(&data_path)
.unwrap_or_else(|_| panic!("can't create dir {}", &config_path));
}
#[cfg(target_os = "linux")]
let mut web_content = WebContext::new(Some(data_path));
#[cfg(target_os = "linux")]
let webview = WebViewBuilder::new(window)?
// .with_user_agent(user_agent_string)
.with_url(&url.to_string())?
.with_devtools(cfg!(feature = "devtools"))
.with_initialization_script(include_str!("pake.js"))
.with_ipc_handler(handler)
.with_web_context(&mut web_content)
.build()?;

#[cfg(feature = "devtools")]
{
webview.open_devtools();
Expand Down

0 comments on commit 4ae7d7b

Please sign in to comment.