Skip to content

Commit

Permalink
format: format code
Browse files Browse the repository at this point in the history
  • Loading branch information
jeasonnow committed Jul 30, 2024
1 parent 5752996 commit d738c1a
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src-tauri/src/app/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub struct PakeConfig {
pub user_agent: UserAgent,
pub system_tray: FunctionON,
pub system_tray_path: String,
pub proxy_url: String
pub proxy_url: String,
}

impl PakeConfig {
Expand Down
7 changes: 4 additions & 3 deletions src-tauri/src/app/invoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ pub async fn download_file(app: AppHandle, params: DownloadFileParams) -> Result
let client = ClientBuilder::new().build().unwrap();

let response = client
.execute(
Request::new(Method::GET, Url::from_str(&params.url).unwrap())
)
.execute(Request::new(
Method::GET,
Url::from_str(&params.url).unwrap(),
))
.await;

match response {
Expand Down
20 changes: 12 additions & 8 deletions src-tauri/src/app/menu.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use tauri::{

Check warning on line 1 in src-tauri/src/app/menu.rs

View workflow job for this annotation

GitHub Actions / Enforce codebase style (cargo fmt)

Diff in /home/runner/work/Pake/Pake/src-tauri/src/app/menu.rs
image::Image, include_image, menu::{ContextMenu, MenuBuilder, MenuItemBuilder}, tray::{MouseButton, MouseButtonState, TrayIcon, TrayIconBuilder, TrayIconEvent}, AppHandle, Config, Manager
image::Image,
menu::{MenuBuilder, MenuItemBuilder},
tray::{MouseButtonState, TrayIconBuilder, TrayIconEvent, MouseButton},
AppHandle, Manager,
};
use tauri_plugin_window_state::{AppHandleExt, StateFlags};

Expand All @@ -9,22 +12,24 @@ pub fn set_system_tray(app: &AppHandle, pake_config: &PakeConfig) -> tauri::Resu
let hide_app = MenuItemBuilder::with_id("hide_app", "Hide").build(app)?;
let show_app = MenuItemBuilder::with_id("show_app", "Show").build(app)?;
let quit = MenuItemBuilder::with_id("quit", "Quit").build(app)?;
let menu = MenuBuilder::new(app).items(&[&hide_app, &show_app, &quit]).build()?;
let menu = MenuBuilder::new(app)
.items(&[&hide_app, &show_app, &quit])
.build()?;
app.app_handle().remove_tray_by_id("pake-tray");
let tray = TrayIconBuilder::new()
.icon(Image::from_path(pake_config.system_tray_path.as_str())?)
.menu(&menu)
.on_tray_icon_event(move |tray, event| {
if let TrayIconEvent::Click {
button: MouseButton::Left,
button_state: MouseButtonState::Up,
..
} = event {
button: MouseButton::Left,
button_state: MouseButtonState::Up,
..
} = event
{
println!("click");

let app = tray.app_handle();


#[cfg(not(target_os = "macos"))]
{
if let Some(webview_window) = app.get_webview_window("pake") {
Expand All @@ -37,7 +42,6 @@ pub fn set_system_tray(app: &AppHandle, pake_config: &PakeConfig) -> tauri::Resu
tauri::AppHandle::show(&app.app_handle()).unwrap();
}
}

})
.on_menu_event(move |app, event| match event.id().as_ref() {
"hide_app" => {
Expand Down
3 changes: 2 additions & 1 deletion src-tauri/src/app/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ pub fn get_window(app: &mut App, config: &PakeConfig, _data_dir: PathBuf) -> Web

if config.proxy_url != "" {
println!("{}", &config.proxy_url);
window_builder = window_builder.proxy_url(Url::from_str(&config.proxy_url.as_str()).unwrap());
window_builder =
window_builder.proxy_url(Url::from_str(&config.proxy_url.as_str()).unwrap());
}

#[cfg(target_os = "macos")]
Expand Down
8 changes: 4 additions & 4 deletions src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use std::str::FromStr;
use app::{invoke, menu::set_system_tray, window};
use invoke::{download_file, download_file_by_binary};
use tauri::Manager;
use tauri_plugin_window_state::Builder as windowStatePlugin;
use tauri_plugin_global_shortcut::{GlobalShortcutExt, Shortcut};
use tauri_plugin_window_state::Builder as windowStatePlugin;
use util::{get_data_dir, get_pake_config};
use window::get_window;

Expand Down Expand Up @@ -51,7 +51,6 @@ pub fn run_app() {
.plugin(
tauri_plugin_global_shortcut::Builder::new()
.with_handler(move |app, event, _shortcut| {

if shortcut_hotkey.eq(event) {
let window = app.get_webview_window("pake").unwrap();
match window.is_visible().unwrap() {
Expand All @@ -62,8 +61,9 @@ pub fn run_app() {
}
}
}
}
).build())
})
.build(),
)
.expect("Error registering global evoke shortcuts!");

app.global_shortcut().register(shortcut_hotkey)?;
Expand Down
9 changes: 5 additions & 4 deletions src-tauri/src/util.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use crate::app::config::PakeConfig;
use std::env;
use std::path::PathBuf;
use tauri::{App, AppHandle, Config, Manager, WebviewWindow};

use tauri::{AppHandle, Config, Manager, WebviewWindow};

pub fn get_pake_config() -> (PakeConfig, Config) {
#[cfg(feature = "cli-build")]
Expand All @@ -24,10 +23,12 @@ pub fn get_pake_config() -> (PakeConfig, Config) {
(pake_config, tauri_config)
}

pub fn get_data_dir(app: &AppHandle, _tauri_config: Config, ) -> PathBuf {
pub fn get_data_dir(app: &AppHandle, _tauri_config: Config) -> PathBuf {
{
let package_name = _tauri_config.product_name.unwrap();
let data_dir = app.path().config_dir()
let data_dir = app
.path()
.config_dir()
.expect("Failed to get data dirname")
.join(package_name);

Expand Down

0 comments on commit d738c1a

Please sign in to comment.