diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index cd80d4a..c5c624c 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -2660,6 +2660,19 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "sys-locale" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3358acbb4acd4146138b9bda219e904a6bb5aaaa237f8eed06f4d6bc1580ecee" +dependencies = [ + "js-sys", + "libc", + "wasm-bindgen", + "web-sys", + "winapi", +] + [[package]] name = "system-deps" version = "5.0.0" @@ -3256,6 +3269,7 @@ dependencies = [ "serde_json", "smartcalc", "strsim", + "sys-locale", "tauri", "tauri-build", "window-vibrancy", @@ -3344,6 +3358,16 @@ version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1c38c045535d93ec4f0b4defec448e4291638ee608530863b1e2ba115d4fff7f" +[[package]] +name = "web-sys" +version = "0.3.60" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bcda906d8be16e728fd5adc5b729afad4e444e106ab28cd1c7256e54fa61510f" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + [[package]] name = "webkit2gtk" version = "0.18.2" diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index d8ae3bc..610a5ca 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -27,6 +27,7 @@ smartcalc = { git = "https://github.com/ParthJadhav/smartcalc", branch = "stable chrono-tz = { version = "0.6.1", default-features = false } num-format = { version = "0.4", features = ["with-system-locale"] } localzone = "0.2.0" +sys-locale = "0.2.3" [dependencies.chrono] version = "0.4" @@ -34,7 +35,7 @@ version = "0.4" [features] # by default Tauri runs in production mode # when `tauri dev` runs it is executed with `cargo run --no-default-features` if `devPath` is an URL -default = [ "custom-protocol" ] +default = ["custom-protocol"] # this feature is used used for production builds where `devPath` points to the filesystem # DO NOT remove this -custom-protocol = [ "tauri/custom-protocol" ] +custom-protocol = ["tauri/custom-protocol"] diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 92b069b..054e114 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -39,12 +39,13 @@ fn main() { launch_on_login ]) .setup(|app| { + #[cfg(target_os = "macos")] app.set_activation_policy(tauri::ActivationPolicy::Accessory); let window = app.get_window("main").unwrap(); #[cfg(target_os = "macos")] apply_vibrancy(&window, NSVisualEffectMaterial::HudWindow, None, Some(10.0)) .expect("Unsupported platform! 'apply_vibrancy' is only supported on macOS"); - window.hide().unwrap(); + // window.hide().unwrap(); Ok(()) }) .system_tray(create_system_tray()) diff --git a/src-tauri/src/util/calculator.rs b/src-tauri/src/util/calculator.rs index 428886b..bcad228 100644 --- a/src-tauri/src/util/calculator.rs +++ b/src-tauri/src/util/calculator.rs @@ -1,11 +1,14 @@ use chrono::{Local, TimeZone}; use chrono_tz::{OffsetName, Tz}; -use num_format::SystemLocale; +use num_format::Locale; use smartcalc::SmartCalc; +use sys_locale::get_locale; + pub fn calculate(input: &str) -> String { - let locale = SystemLocale::default().unwrap(); + let locale = get_locale().unwrap_or_else(|| String::from("en-US")); + let locale = Locale::from_name(&locale).unwrap_or_else(|_| Locale::en); let timezone = match localzone::get_local_zone() { Some(tz) => match tz.parse::() { Ok(tz) => { diff --git a/src-tauri/src/util/icons.rs b/src-tauri/src/util/icons.rs index f19b03b..70ecee6 100644 --- a/src-tauri/src/util/icons.rs +++ b/src-tauri/src/util/icons.rs @@ -1,4 +1,5 @@ -use directories::ProjectDirs; +use tauri::api::path::app_data_dir; +use tauri::Config; use plist::Value; use rust_search::SearchBuilder; use std::{ @@ -8,8 +9,8 @@ use std::{ }; fn convert_and_store_icons(icns_path: &str, app_name: &str) { - if let Some(proj_dirs) = ProjectDirs::from("com", "parth jadhav", "verve") { - let icon_dir = proj_dirs.config_dir().join("appIcons"); + if let Some(proj_dirs) = app_data_dir(&Config::default()) { + let icon_dir = proj_dirs.join("com.parth-jadhav.verve/appIcons"); if fs::create_dir_all(&icon_dir).is_ok() { let icns_path = Path::new(icns_path); let png_path = icon_dir.join(app_name.to_owned() + &".png"); diff --git a/src-tauri/src/util/preferences.rs b/src-tauri/src/util/preferences.rs index e84db76..db148f6 100644 --- a/src-tauri/src/util/preferences.rs +++ b/src-tauri/src/util/preferences.rs @@ -1,6 +1,8 @@ -use directories::ProjectDirs; use serde::{Deserialize, Serialize}; use std::fs; +use std::fs::create_dir_all; +use tauri::api::path::app_data_dir; +use tauri::Config; #[derive(Serialize, Deserialize)] struct Theme { @@ -14,8 +16,16 @@ struct Theme { dark_overlay: String, } -impl Default for Theme { - fn default() -> Self { +trait Linux { + fn get_theme_linux() -> Theme; +} + +trait MacOS { + fn get_theme_mac_os() -> Theme; +} + +impl MacOS for Theme { + fn get_theme_mac_os() -> Self { Self { primary_bg_color: String::from("rgba(20, 20, 30, 0.6)"), secondary_bg_color: String::from("rgba(84, 101, 115, 0.6)"), @@ -29,6 +39,21 @@ impl Default for Theme { } } +impl Linux for Theme { + fn get_theme_linux() -> Theme { + Self { + primary_bg_color: String::from("rgba(20, 20, 30, 1)"), + secondary_bg_color: String::from("rgba(84, 101, 115, 1)"), + primary_text_color: String::from("#FFFFFF"), + secondary_text_color: String::from("#878787"), + primary_accent_color: String::from("#556CE5"), + secondary_accent_color: String::from("#48A5FF"), + highlight_overlay: String::from("rgba(255, 255, 255, 0.1)"), + dark_overlay: String::from("rgba(0, 0, 0, 0.1)"), + } + } +} + #[derive(Serialize, Deserialize)] struct Preferences { shortcut: String, @@ -37,20 +62,25 @@ struct Preferences { } pub fn create_preferences_if_missing() { - if let Some(proj_dirs) = ProjectDirs::from("com", "parth jadhav", "verve") { - let preferences_path = proj_dirs.config_dir().join("preferences.json"); - let theme_path = proj_dirs.config_dir().join("theme.json"); + if let Some(proj_dirs) = app_data_dir(&Config::default()) { + let preferences_path = proj_dirs.join("com.parth-jadhav.verve/preferences.json"); + let theme_path = proj_dirs.join("com.parth-jadhav.verve/theme.json"); + println!("{:?}", preferences_path); if !preferences_path.exists() { let preference = Preferences { - shortcut: String::from("Command+Shift+G"), + shortcut: String::from("CTRL+Shift+G"), launch_on_login: true, menu_bar_icon: true, }; + create_dir_all(&preferences_path.parent().unwrap()).unwrap(); let preference_text = serde_json::to_string(&preference).unwrap(); fs::write(preferences_path, &preference_text).unwrap(); } if !theme_path.exists() { - let theme = Theme::default(); + #[cfg(target_os = "macos")] + let theme = Theme::get_theme_mac_os(); + #[cfg(target_os = "linux")] + let theme = Theme::get_theme_linux(); let theme_text = serde_json::to_string(&theme).unwrap(); fs::write(theme_path, &theme_text).unwrap(); } diff --git a/src/main.ts b/src/main.ts index f412a33..0894f97 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,13 +1,14 @@ import './style.css'; // @ts-ignore -import App from './routes/App/App.svelte'; -import { appWindow } from '@tauri-apps/api/window'; -import { register } from '@tauri-apps/api/globalShortcut'; -import { appDataDir, join, resolveResource } from '@tauri-apps/api/path'; -import { readTextFile } from '@tauri-apps/api/fs'; -import { invoke } from '@tauri-apps/api/tauri'; -import { preferences, paths } from './cache'; -import { listen } from '@tauri-apps/api/event'; + +import App from "./routes/App/App.svelte"; +import { appWindow } from "@tauri-apps/api/window"; +import { register } from '@tauri-apps/api/globalShortcut' +import { appDataDir, join } from "@tauri-apps/api/path"; +import { readTextFile } from "@tauri-apps/api/fs"; +import { invoke } from "@tauri-apps/api/tauri"; +import { preferences, paths } from "./cache"; +import { listen } from '@tauri-apps/api/event' // Create the app const app = new App({ @@ -68,8 +69,8 @@ const reloadTheme = async () => { export async function listenForHotkey(shortcut: string) { await register(shortcut, async () => { - if (document.hasFocus()) { - await appWindow.hide(); + if (await appWindow.isVisible()) { + await appWindow.hide() } else { await appWindow.show(); await appWindow.center(); diff --git a/src/routes/App/App.svelte b/src/routes/App/App.svelte index 9fb4495..edb700d 100644 --- a/src/routes/App/App.svelte +++ b/src/routes/App/App.svelte @@ -16,7 +16,8 @@ let footerText: string = 'verve.app'; document.onkeyup = function (event) { - if (event.metaKey && event.key === ',') { + if ((event.ctrlKey || event.metaKey) && event.key === ",") { + console.log("meta + ,"); appState.app = false; appState.settings = true; }