Skip to content

Commit

Permalink
fix toggle in front end
Browse files Browse the repository at this point in the history
  • Loading branch information
0-don committed Dec 21, 2024
1 parent afb40f0 commit 0a77026
Show file tree
Hide file tree
Showing 39 changed files with 333 additions and 183 deletions.
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
node_modules
dist
clippy.sqlite
*.sqlite
yarn.lock
package-lock.json
pnpm-lock.yamlor.log
Expand All @@ -15,4 +15,5 @@ bun.lockb
# will have compiled files and executables
target/
context.txt
sea_orm_*.txt
sea_orm_*.txt
config.json
2 changes: 1 addition & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
node_modules
dist
clippy.sqlite
*.sqlite
yarn.lock
package-lock.json
pnpm-lock.yaml
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"dev": "vite",
"build": "vite build",
"tauri": "cross-env NO_STRIP=true tauri",
"d": "tauri dev",
"d": "cross-env COLORBT_SHOW_HIDDEN=1 tauri dev",
"gen": "sea-orm-cli migrate refresh -v -d src-tauri/migration && sea-orm-cli generate entity -l -o src-tauri/entity/src --expanded-format --with-serde both",
"icon": "tauri icon"
},
Expand Down
20 changes: 20 additions & 0 deletions src-tauri/Cargo.lock

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

2 changes: 2 additions & 0 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ infer = "0"
mime_guess = "2"
tree_magic_mini = "3"

color-backtrace = "0"

[profile.release]
# panic = "abort"
# codegen-units = 1
Expand Down
5 changes: 4 additions & 1 deletion src-tauri/common/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@ pub static GLOBAL_EVENTS: LazyLock<Vec<String>> = LazyLock::new(|| {
]
});

pub static DB_NAME: &str = "clippy.sqlite";
pub static CONFIG_NAME: &str = "config.json";

pub static MAIN_WINDOW_X: i32 = 375;
pub static MAIN_WINDOW_Y: i32 = 600;

pub static ABOUT_WINDOW_X: i32 = 375;
pub static ABOUT_WINDOW_Y: i32 = 600;

pub static SETTINGS_WINDOW_X: i32 = 500;
pub static SETTINGS_WINDOW_Y: i32 = 450;
pub static SETTINGS_WINDOW_Y: i32 = 550;

pub static MAX_IMAGE_DIMENSIONS: u32 = 1280;
pub static MAX_TEXT_PREVIEW: usize = 500; // Adjust preview length as needed
Expand Down
3 changes: 0 additions & 3 deletions src-tauri/entity/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ pub struct Model {
pub id: i32,
pub language: String,
pub startup: bool,
pub notification: bool,
pub synchronize: bool,
pub dark_mode: bool,
pub display_scale: f32,
Expand All @@ -33,7 +32,6 @@ pub enum Column {
Id,
Language,
Startup,
Notification,
Synchronize,
DarkMode,
DisplayScale,
Expand Down Expand Up @@ -66,7 +64,6 @@ impl ColumnTrait for Column {
Self::Id => ColumnType::Integer.def(),
Self::Language => ColumnType::String(StringLen::N(2u32)).def(),
Self::Startup => ColumnType::Boolean.def(),
Self::Notification => ColumnType::Boolean.def(),
Self::Synchronize => ColumnType::Boolean.def(),
Self::DarkMode => ColumnType::Boolean.def(),
Self::DisplayScale => ColumnType::Float.def(),
Expand Down
4 changes: 1 addition & 3 deletions src-tauri/migration/src/m000007_create_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use common::{
};
use sea_orm_migration::{
prelude::*,
schema::{boolean, float, integer, pk_auto, string},
schema::{boolean, float, integer, pk_auto, string},
};

#[derive(Iden)]
Expand All @@ -19,7 +19,6 @@ enum Settings {
Language,
//
Startup,
Notification,
Synchronize,
DarkMode,
DisplayScale,
Expand Down Expand Up @@ -49,7 +48,6 @@ impl MigrationTrait for Migration {
.default(get_system_language().to_string()),
)
.col(boolean(Settings::Startup).default(true))
.col(boolean(Settings::Notification).default(false))
.col(boolean(Settings::Synchronize).default(false))
.col(boolean(Settings::DarkMode).default(true))
.col(
Expand Down
4 changes: 2 additions & 2 deletions src-tauri/src/connection.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::prelude::*;
use crate::service::settings::get_data_path;
use common::types::types::Config;
use common::{constants::DB_NAME, types::types::Config};
use migration::{DbErr, Migrator, MigratorTrait};
use std::sync::Once;

Expand All @@ -9,7 +9,7 @@ static INIT: Once = Once::new();

pub async fn db() -> Result<DbConn, DbErr> {
let database_url = if cfg!(debug_assertions) {
String::from("sqlite://../clippy.sqlite?mode=rwc")
format!("sqlite://../{}?mode=rwc", DB_NAME)
} else {
get_prod_database_url()
};
Expand Down
2 changes: 2 additions & 0 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#[tokio::main]
async fn main() {
color_backtrace::install();

#[cfg(target_os = "linux")]
{
// See: https://github.com/spacedriveapp/spacedrive/issues/1512#issuecomment-1758550164
Expand Down
15 changes: 10 additions & 5 deletions src-tauri/src/service/hotkey.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::global::{get_app_window, get_main_window};
use super::global::{get_app, get_main_window};
use crate::prelude::*;
use crate::{
connection,
Expand All @@ -8,7 +8,7 @@ use common::types::enums::{ListenEvent, WebWindow};
use core::future::Future;
use entity::hotkey::{self, ActiveModel, Model};
use sea_orm::{ActiveModelTrait, EntityTrait};
use tauri::Emitter;
use tauri::{Emitter, Manager};

pub async fn get_all_hotkeys_db() -> Result<Vec<Model>, DbErr> {
let db: DatabaseConnection = connection::db().await?;
Expand Down Expand Up @@ -45,9 +45,14 @@ where
get_main_window()
.emit(ListenEvent::Init.to_string().as_str(), ())
.expect("Failed to emit init event");
get_app_window(WebWindow::Settings)
.emit(ListenEvent::Init.to_string().as_str(), ())
.expect("Failed to emit init event");

if let Some(settings_window) =
get_app().get_webview_window(WebWindow::Settings.to_string().as_str())
{
settings_window
.emit(ListenEvent::Init.to_string().as_str(), ())
.expect("Failed to emit init event");
}

result
}
39 changes: 28 additions & 11 deletions src-tauri/src/service/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use crate::connection;
use crate::prelude::*;
use crate::service::window::get_monitor_scale_factor;
use crate::{commands::settings::get_settings, service::hotkey::with_hotkeys};
use common::constants::CONFIG_NAME;
use common::constants::DB_NAME;
use common::language::get_system_language;
use common::types::types::Config;
use common::types::types::DataPath;
Expand Down Expand Up @@ -73,23 +75,34 @@ pub fn init_settings() {
}

pub fn get_data_path() -> DataPath {
let config_path = get_app()
.path()
.app_data_dir()
.expect("Failed to get app data dir")
.to_string_lossy()
.to_string();
let config_path = if cfg!(debug_assertions) {
// Get absolute project root directory
let current_dir = std::env::current_dir()
.expect("Failed to get current directory")
.parent()
.expect("Failed to get parent directory")
.to_path_buf();

current_dir.to_string_lossy().to_string()
} else {
// Use app data dir in production
get_app()
.path()
.app_data_dir()
.expect("Failed to get app data dir")
.to_string_lossy()
.to_string()
};

fs::create_dir_all(&config_path).expect("Failed to create config directory");

// let config_file = Path::new(&config_dir).join("config.json");
let config_file_path = [&config_path, "config.json"]
let config_file_path = [&config_path, CONFIG_NAME]
.iter()
.collect::<PathBuf>()
.to_string_lossy()
.to_string();

let db_file_path = [&config_path, "clippy.sqlite"]
let db_file_path = [&config_path, DB_NAME]
.iter()
.collect::<PathBuf>()
.to_string_lossy()
Expand Down Expand Up @@ -122,11 +135,14 @@ pub async fn sync_clipboard_history_enable() {
let dir = dir.to_string();
let dir_file = format!("{}/clippy.sqlite", &dir);

println!("selected dir: {}", dir);

// check if backup file exists
if !Path::new(&dir_file).exists() {
// copy current database to backup location
printlog!(
"copying database to backup location {} {}",
&config.db,
&dir_file
);
fs::copy(&config.db, &dir_file).expect("Failed to copy database");
}

Expand Down Expand Up @@ -169,6 +185,7 @@ pub async fn sync_clipboard_history_disable() {
pub async fn sync_clipboard_history_toggle() {
let settings = get_settings().await.expect("Failed to get settings");

printlog!("synchronize: {}", settings.synchronize);
with_hotkeys(false, async move {
if settings.synchronize {
sync_clipboard_history_disable().await;
Expand Down
13 changes: 11 additions & 2 deletions src-tauri/src/service/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ pub fn toggle_main_window() {
get_main_window().hide().expect("Failed to hide window");
unregister_hotkeys(false);
get_main_window()
.emit(ListenEvent::EnableGlobalHotkeyEvent.to_string().as_str(), false)
.emit(
ListenEvent::EnableGlobalHotkeyEvent.to_string().as_str(),
false,
)
.expect("Failed to emit set global hotkey event");
} else {
position_window_near_cursor();
Expand All @@ -63,7 +66,10 @@ pub fn toggle_main_window() {

register_hotkeys(true);
get_main_window()
.emit(ListenEvent::EnableGlobalHotkeyEvent.to_string().as_str(), true)
.emit(
ListenEvent::EnableGlobalHotkeyEvent.to_string().as_str(),
true,
)
.expect("Failed to emit set global hotkey event");

get_app()
Expand Down Expand Up @@ -166,7 +172,9 @@ pub async fn create_about_window() {

// Close existing window if it exists
if let Some(window) = app.get_webview_window(WebWindow::About.to_string().as_str()) {
printlog!("closing existing about window");
window.close().expect("Failed to close window");
tokio::time::sleep(std::time::Duration::from_millis(100)).await;
}

let window = WebviewWindowBuilder::new(
Expand All @@ -191,6 +199,7 @@ pub async fn create_settings_window() {
// Close existing window if it exists
if let Some(window) = app.get_webview_window(WebWindow::Settings.to_string().as_str()) {
window.close().expect("Failed to close window");
tokio::time::sleep(std::time::Duration::from_millis(100)).await;
}

let window = WebviewWindowBuilder::new(
Expand Down
12 changes: 6 additions & 6 deletions src/components/elements/dropdown.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { VsArrowSwap } from "solid-icons/vs";
import { Component, createSignal } from "solid-js";
import { GlobalShortcutKeys } from "../../utils/constants";

interface DropdownProps {
items: string[];
className?: string;
items: { value: string; label: string }[];
value: string;
onChange: (value: GlobalShortcutKeys | (string & {})) => void;
onChange: (value: string) => void;
}

export const Dropdown: Component<DropdownProps> = (props) => {
Expand All @@ -14,7 +14,7 @@ export const Dropdown: Component<DropdownProps> = (props) => {
return (
<div
onClick={() => ref()?.dispatchEvent(new MouseEvent("mousedown"))}
class="group flex items-center rounded-md border border-gray-300 p-1 text-sm focus:outline-none focus:ring-0 dark:border-dark-light dark:bg-dark-light dark:text-white"
class={`${props.className ? props.className : ""} group flex items-center justify-between rounded-md border border-gray-300 p-1 px-1.5 text-sm focus:outline-none focus:ring-0 dark:border-dark-light dark:bg-dark-light dark:text-white`}
>
<select
ref={setRef}
Expand All @@ -23,8 +23,8 @@ export const Dropdown: Component<DropdownProps> = (props) => {
class="appearance-none bg-transparent text-sm focus:outline-none focus:ring-0"
>
{props.items.map((item) => (
<option value={item} selected={item === props.value} class="!text-red-500 dark:!text-red-600">
{item}
<option value={item.value} selected={item.value === props.value} class="!text-red-500 dark:!text-red-600">
{item.label}
</option>
))}
</select>
Expand Down
27 changes: 27 additions & 0 deletions src/components/elements/input.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Component } from "solid-js";

interface InputProps {
className?: string;
value: string;
onChange: (value: string) => void;
placeholder?: string;
type?: string;
}

export const Input: Component<InputProps> = (props) => {
return (
<div
class={`${
props.className ? props.className : ""
} group flex items-center justify-between rounded-md border border-gray-300 p-1 px-1.5 text-sm focus-within:border-indigo-500 dark:border-dark-light dark:bg-dark-light`}
>
<input
type={props.type || "text"}
value={props.value}
onChange={(e) => props.onChange(e.currentTarget.value)}
placeholder={props.placeholder}
class="w-full appearance-none bg-transparent text-sm focus:outline-none focus:ring-0 dark:text-white"
/>
</div>
);
};
Loading

0 comments on commit 0a77026

Please sign in to comment.