Skip to content

Commit

Permalink
合并重复代码
Browse files Browse the repository at this point in the history
  • Loading branch information
Tlntin committed Dec 10, 2022
1 parent 4f8d4d2 commit 4834f89
Showing 1 changed file with 26 additions and 46 deletions.
72 changes: 26 additions & 46 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,34 @@
#![windows_subsystem = "windows"]
extern crate image;
use tauri_utils::config::{Config, WindowConfig};
#[cfg(target_os = "macos")]
use wry::application::platform::macos::WindowBuilderExtMacOS;

#[cfg(target_os = "macos")]
use wry::{
application::{
accelerator::{Accelerator, SysMods},
event::{Event, StartCause, WindowEvent},
event_loop::{ControlFlow, EventLoop},
keyboard::KeyCode,
menu::{MenuBar as Menu, MenuItem, MenuItemAttributes, MenuType},
menu::MenuType,
window::{Fullscreen, Window, WindowBuilder},
},
webview::WebViewBuilder,
};

#[cfg(target_os = "windows")]

#[cfg(target_os = "macos")]
use wry::{
application::{
event::{Event, StartCause, WindowEvent},
event_loop::{ControlFlow, EventLoop},
menu::MenuType,
window::{Fullscreen, Icon, Window, WindowBuilder},
accelerator::{Accelerator, SysMods},
keyboard::KeyCode,
menu::{MenuBar as Menu, MenuItem, MenuItemAttributes},
platform::macos::WindowBuilderExtMacOS,
},
webview::WebViewBuilder,
};

#[cfg(target_os = "windows")]
use wry::window::Icon;

#[cfg(target_os = "linux")]
use wry::{
application::{
event::{Event, StartCause, WindowEvent},
event_loop::{ControlFlow, EventLoop},
menu::MenuType,
window::{Fullscreen, Window, WindowBuilder},
},
webview::{WebContext, WebViewBuilder},
};
use wry::webview::WebContext;



fn main() -> wry::Result<()> {
#[cfg(target_os = "macos")]
Expand Down Expand Up @@ -79,24 +70,14 @@ fn main() -> wry::Result<()> {

#[cfg(target_os = "macos")]
menu_bar_menu.add_submenu("App", true, first_menu);
#[cfg(target_os = "linux")]
#[cfg(any(target_os = "linux", target_os = "windows"))]
let (package_name, windows_config) = get_windows_config();
#[cfg(any(target_os = "linux", target_os = "windows"))]
let package_name = package_name
.expect("can't get package name in config file")
.to_lowercase();

#[cfg(target_os = "linux")]
let package_name = package_name.expect("can't get package name in config file");

#[cfg(target_os = "linux")]
let WindowConfig {
url,
width,
height,
resizable,
fullscreen,
..
} = windows_config.unwrap_or_default();
#[cfg(target_os = "windows")]
let (package_name, windows_config) = get_windows_config();
#[cfg(target_os = "windows")]
#[cfg(any(target_os = "linux", target_os = "windows"))]
let WindowConfig {
url,
width,
Expand All @@ -105,6 +86,7 @@ fn main() -> wry::Result<()> {
fullscreen,
..
} = windows_config.unwrap_or_default();

#[cfg(target_os = "macos")]
let WindowConfig {
url,
Expand All @@ -127,10 +109,6 @@ fn main() -> wry::Result<()> {
})
.with_inner_size(wry::application::dpi::LogicalSize::new(width, height));
#[cfg(target_os = "windows")]
let package_name = package_name
.expect("can't get package name in config file")
.to_lowercase();
#[cfg(target_os = "windows")]
let icon_path = format!("png/{}_32.ico", package_name);
#[cfg(target_os = "windows")]
let icon = load_icon(std::path::Path::new(&icon_path));
Expand All @@ -142,7 +120,9 @@ fn main() -> wry::Result<()> {
.unwrap();

#[cfg(target_os = "linux")]
let window = common_window.build(&event_loop).unwrap();
let window = common_window
.build(&event_loop)
.unwrap();

#[cfg(target_os = "macos")]
let window = common_window
Expand Down Expand Up @@ -195,14 +175,14 @@ fn main() -> wry::Result<()> {
.build()?;
// 自定义cookie文件夹,仅用于Linux
// Custom Cookie folder, only for Linux
// #[cfg(target_os = "linux")]
// let config_path = format!("/home/{}/.config/{}", env!("USER"), package_name);
#[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
"/home/{}/.config/{}",
v.into_string().unwrap(),
package_name,
),
None => panic!("can't found any user")
};
Expand Down

0 comments on commit 4834f89

Please sign in to comment.