diff --git a/package.json b/package.json index 42b9b30e..d7ee0b64 100644 --- a/package.json +++ b/package.json @@ -35,6 +35,7 @@ "@tanstack/react-query": "^5.8.4", "@tauri-apps/api": "2.0.0-alpha.11", "@tauri-apps/cli": "2.0.0-alpha.17", + "@tauri-apps/plugin-autostart": "2.0.0-alpha.3", "@tauri-apps/plugin-clipboard-manager": "2.0.0-alpha.3", "@tauri-apps/plugin-dialog": "2.0.0-alpha.3", "@tauri-apps/plugin-fs": "2.0.0-alpha.3", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 4e1bea0c..5eda04c0 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -56,6 +56,9 @@ dependencies: '@tauri-apps/cli': specifier: 2.0.0-alpha.17 version: 2.0.0-alpha.17 + '@tauri-apps/plugin-autostart': + specifier: 2.0.0-alpha.3 + version: 2.0.0-alpha.3 '@tauri-apps/plugin-clipboard-manager': specifier: 2.0.0-alpha.3 version: 2.0.0-alpha.3 @@ -2145,6 +2148,12 @@ packages: '@tauri-apps/cli-win32-x64-msvc': 2.0.0-alpha.17 dev: false + /@tauri-apps/plugin-autostart@2.0.0-alpha.3: + resolution: {integrity: sha512-FWXMun68YPs+czGj063B/R2ItK0lFAHz08GCY8Ez1v5qGfq48MqBVF6EB5AHqQ73Wyq3+RGgDTyxuRFzBnXr6A==} + dependencies: + '@tauri-apps/api': 2.0.0-alpha.11 + dev: false + /@tauri-apps/plugin-clipboard-manager@2.0.0-alpha.3: resolution: {integrity: sha512-Lo30EM8VRo9bYMeRHhZT65OUgajbxaK1A9UhD7/9VZIFoWGbzKU/jrP78mcJ77lc+RrcCcSJvkAgOaLtuOlhxw==} dependencies: diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index ca452531..ed827dec 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -2633,6 +2633,7 @@ dependencies = [ "tauri-plugin-single-instance", "tauri-plugin-sql", "tauri-plugin-store", + "tauri-plugin-theme", "tauri-plugin-updater", "tauri-plugin-upload", "tauri-plugin-window-state", @@ -5172,6 +5173,21 @@ dependencies = [ "thiserror", ] +[[package]] +name = "tauri-plugin-theme" +version = "0.2.0" +source = "git+https://github.com/reyamir/tauri-plugin-theme?branch=tauri-v2#73e8fc84cb4fb8363fee4edcbbab82c98c1874cc" +dependencies = [ + "cocoa 0.25.0", + "futures-lite", + "gtk", + "once_cell", + "serde", + "tauri", + "tintanum", + "tokio", +] + [[package]] name = "tauri-plugin-updater" version = "2.0.0-alpha.4" @@ -5417,6 +5433,16 @@ dependencies = [ "time-core", ] +[[package]] +name = "tintanum" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7abbcf9173afc80733c20b7e27a30bc9284d6535bdbde2a70904032de63e16e8" +dependencies = [ + "futures-lite", + "zbus", +] + [[package]] name = "tinyvec" version = "1.6.0" diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 15bced4e..bef4bbe7 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -33,6 +33,7 @@ tauri-plugin-autostart = { git = "https://github.com/tauri-apps/plugins-workspac tauri-plugin-store = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v2" } tauri-plugin-upload = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v2" } tauri-plugin-window-state = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v2" } +tauri-plugin-theme = { git = "https://github.com/reyamir/tauri-plugin-theme", branch = "tauri-v2" } tauri-plugin-sql = { git = "hhttps://github.com/tauri-apps/plugins-workspace", branch = "v2", features = [ "sqlite", ] } diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 8de740b8..7a2b646f 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -7,6 +7,7 @@ use keyring::Entry; use std::time::Duration; use tauri_plugin_autostart::MacosLauncher; use tauri_plugin_sql::{Migration, MigrationKind}; +use tauri_plugin_theme::ThemePlugin; use webpage::{Webpage, WebpageOptions}; #[derive(Clone, serde::Serialize)] @@ -105,6 +106,7 @@ fn secure_remove(key: String) -> Result<(), ()> { } fn main() { + let mut ctx = tauri::generate_context!(); tauri::Builder::default() .setup(|app| { #[cfg(desktop)] @@ -113,6 +115,7 @@ fn main() { .plugin(tauri_plugin_updater::Builder::new().build())?; Ok(()) }) + .plugin(ThemePlugin::init(ctx.config_mut())) .plugin( tauri_plugin_sql::Builder::default() .add_migrations( @@ -134,10 +137,6 @@ fn main() { ) .build(), ) - .plugin(tauri_plugin_autostart::init( - MacosLauncher::LaunchAgent, - Some(vec!["--flag1", "--flag2"]), - )) .plugin(tauri_plugin_clipboard_manager::init()) .plugin(tauri_plugin_dialog::init()) .plugin(tauri_plugin_fs::init()) @@ -148,12 +147,16 @@ fn main() { .plugin(tauri_plugin_shell::init()) .plugin(tauri_plugin_upload::init()) .plugin(tauri_plugin_window_state::Builder::default().build()) + .plugin(tauri_plugin_autostart::init( + MacosLauncher::LaunchAgent, + Some(vec![]), + )) .invoke_handler(tauri::generate_handler![ opengraph, secure_save, secure_load, secure_remove ]) - .run(tauri::generate_context!()) + .run(ctx) .expect("error while running tauri application"); } diff --git a/src/app/settings/about.tsx b/src/app/settings/about.tsx index 8bbbe597..91e1fe28 100644 --- a/src/app/settings/about.tsx +++ b/src/app/settings/about.tsx @@ -1,5 +1,6 @@ import { getVersion } from '@tauri-apps/api/app'; import { useEffect, useState } from 'react'; +import { Link } from 'react-router-dom'; export function AboutScreen() { const [version, setVersion] = useState(''); @@ -22,6 +23,20 @@ export function AboutScreen() {

Version {version}

+
+ + Website + + + Report a issue + +
); } diff --git a/src/app/settings/advanced.tsx b/src/app/settings/advanced.tsx index 8a5f8660..456c7056 100644 --- a/src/app/settings/advanced.tsx +++ b/src/app/settings/advanced.tsx @@ -1,21 +1,24 @@ +import { useStorage } from '@libs/storage/provider'; + export function AdvancedSettingScreen() { + const { db } = useStorage(); + + const clearCache = async () => { + await db.clearCache(); + }; + return (
-
Event Caches
+
+
Caches
+
Use for boost up NDK
+
-
-
-
User Caches
- diff --git a/src/app/settings/backup.tsx b/src/app/settings/backup.tsx index c0748879..abf3d77f 100644 --- a/src/app/settings/backup.tsx +++ b/src/app/settings/backup.tsx @@ -1,10 +1,19 @@ +import { nip19 } from 'nostr-tools'; import { useEffect, useState } from 'react'; import { useStorage } from '@libs/storage/provider'; +import { EyeOffIcon } from '@shared/icons'; + export function BackupSettingScreen() { const { db } = useStorage(); + const [privkey, setPrivkey] = useState(null); + const [showPassword, setShowPassword] = useState(false); + + const removePrivkey = async () => { + await db.secureRemove(db.account.pubkey); + }; useEffect(() => { async function loadPrivkey() { @@ -24,12 +33,30 @@ export function BackupSettingScreen() { You've stored private key on Lume
) : ( - + <> +
+ + +
+ + )}
diff --git a/src/app/settings/general.tsx b/src/app/settings/general.tsx index 0decafaf..e4cd86e0 100644 --- a/src/app/settings/general.tsx +++ b/src/app/settings/general.tsx @@ -1,5 +1,10 @@ import * as Switch from '@radix-ui/react-switch'; +import { invoke } from '@tauri-apps/api/primitives'; +import { getCurrent } from '@tauri-apps/api/window'; +import { disable, enable, isEnabled } from '@tauri-apps/plugin-autostart'; +import { isPermissionGranted, requestPermission } from '@tauri-apps/plugin-notification'; import { useEffect, useState } from 'react'; +import { twMerge } from 'tailwind-merge'; import { useStorage } from '@libs/storage/provider'; @@ -16,46 +21,89 @@ export function GeneralSettingScreen() { appearance: 'system', }); + const changeTheme = async (theme: 'light' | 'dark' | 'auto') => { + await invoke('plugin:theme|set_theme', { theme }); + // update state + setSettings((prev) => ({ ...prev, appearance: theme })); + }; + + const toggleAutolaunch = async () => { + if (!settings.autolaunch) { + await enable(); + // update state + setSettings((prev) => ({ ...prev, autolaunch: true })); + } else { + await disable(); + // update state + setSettings((prev) => ({ ...prev, autolaunch: false })); + } + }; + + const toggleOutbox = async () => { + await db.createSetting('outbox', String(+!settings.outbox)); + // update state + setSettings((prev) => ({ ...prev, outbox: !settings.outbox })); + }; + + const toggleMedia = async () => { + await db.createSetting('media', String(+!settings.media)); + db.settings.media = !settings.media; + // update state + setSettings((prev) => ({ ...prev, media: !settings.media })); + }; + + const toggleHashtag = async () => { + await db.createSetting('hashtag', String(+!settings.hashtag)); + db.settings.hashtag = !settings.hashtag; + // update state + setSettings((prev) => ({ ...prev, hashtag: !settings.hashtag })); + }; + + const toggleNofitication = async () => { + if (settings.notification) return; + + await requestPermission(); + // update state + setSettings((prev) => ({ ...prev, notification: !settings.notification })); + }; + useEffect(() => { async function loadSettings() { + const theme = await getCurrent().theme(); + setSettings((prev) => ({ ...prev, appearance: theme })); + + const autostart = await isEnabled(); + setSettings((prev) => ({ ...prev, autolaunch: autostart })); + + const permissionGranted = await isPermissionGranted(); + setSettings((prev) => ({ ...prev, notification: permissionGranted })); + const data = await db.getAllSettings(); if (!data) return; data.forEach((item) => { - if (item.key === 'autolaunch') - setSettings((prev) => ({ - ...prev, - autolaunch: item.value === '1' ? true : false, - })); - if (item.key === 'outbox') setSettings((prev) => ({ ...prev, - outbox: item.value === '1' ? true : false, + outbox: !!parseInt(item.value), })); if (item.key === 'media') setSettings((prev) => ({ ...prev, - media: item.value === '1' ? true : false, + media: !!parseInt(item.value), })); if (item.key === 'hashtag') setSettings((prev) => ({ ...prev, - hashtag: item.value === '1' ? true : false, + hashtag: !!parseInt(item.value), })); if (item.key === 'notification') setSettings((prev) => ({ ...prev, - notification: item.value === '1' ? true : false, - })); - - if (item.key === 'appearance') - setSettings((prev) => ({ - ...prev, - appearance: item.value, + notification: !!parseInt(item.value), })); }); } @@ -73,6 +121,7 @@ export function GeneralSettingScreen() { toggleAutolaunch()} className="relative h-7 w-12 cursor-default rounded-full bg-neutral-200 outline-none data-[state=checked]:bg-blue-500 dark:bg-neutral-800" > @@ -85,6 +134,7 @@ export function GeneralSettingScreen() { toggleOutbox()} className="relative h-7 w-12 cursor-default rounded-full bg-neutral-200 outline-none data-[state=checked]:bg-blue-500 dark:bg-neutral-800" > @@ -97,6 +147,7 @@ export function GeneralSettingScreen() { toggleMedia()} className="relative h-7 w-12 cursor-default rounded-full bg-neutral-200 outline-none data-[state=checked]:bg-blue-500 dark:bg-neutral-800" > @@ -109,6 +160,7 @@ export function GeneralSettingScreen() { toggleHashtag()} className="relative h-7 w-12 cursor-default rounded-full bg-neutral-200 outline-none data-[state=checked]:bg-blue-500 dark:bg-neutral-800" > @@ -123,6 +175,8 @@ export function GeneralSettingScreen() { toggleNofitication()} className="relative h-7 w-12 cursor-default rounded-full bg-neutral-200 outline-none data-[state=checked]:bg-blue-500 dark:bg-neutral-800" > @@ -133,9 +187,17 @@ export function GeneralSettingScreen() {