Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add-linux-support #41

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@ 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"

[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"]
3 changes: 2 additions & 1 deletion src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
7 changes: 5 additions & 2 deletions src-tauri/src/util/calculator.rs
Original file line number Diff line number Diff line change
@@ -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::<Tz>() {
Ok(tz) => {
Expand Down
7 changes: 4 additions & 3 deletions src-tauri/src/util/icons.rs
Original file line number Diff line number Diff line change
@@ -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::{
Expand All @@ -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");
Expand Down
46 changes: 38 additions & 8 deletions src-tauri/src/util/preferences.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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)"),
Expand All @@ -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,
Expand All @@ -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();
}
Expand Down
21 changes: 11 additions & 10 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -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({
Expand Down Expand Up @@ -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();
Expand Down
3 changes: 2 additions & 1 deletion src/routes/App/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down