chore: clean up

This commit is contained in:
2024-10-23 10:43:39 +07:00
parent 172566028b
commit c032dbea1a
10 changed files with 195 additions and 270 deletions

73
src-tauri/Cargo.lock generated
View File

@@ -17,7 +17,6 @@ dependencies = [
"keyring", "keyring",
"keyring-search", "keyring-search",
"linkify", "linkify",
"log",
"nostr-sdk", "nostr-sdk",
"regex", "regex",
"reqwest", "reqwest",
@@ -45,7 +44,6 @@ dependencies = [
"tauri-plugin-window-state", "tauri-plugin-window-state",
"tauri-specta", "tauri-specta",
"tokio", "tokio",
"tracing-subscriber",
"url", "url",
] ]
@@ -3082,7 +3080,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4979f22fdb869068da03c9f7528f8297c6fd2606bc3a4affe42e6a823fdb8da4" checksum = "4979f22fdb869068da03c9f7528f8297c6fd2606bc3a4affe42e6a823fdb8da4"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"windows-targets 0.48.5", "windows-targets 0.52.6",
] ]
[[package]] [[package]]
@@ -3609,16 +3607,6 @@ dependencies = [
"zbus 4.4.0", "zbus 4.4.0",
] ]
[[package]]
name = "nu-ansi-term"
version = "0.46.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84"
dependencies = [
"overload",
"winapi",
]
[[package]] [[package]]
name = "num" name = "num"
version = "0.4.3" version = "0.4.3"
@@ -4005,12 +3993,6 @@ dependencies = [
"windows-sys 0.59.0", "windows-sys 0.59.0",
] ]
[[package]]
name = "overload"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39"
[[package]] [[package]]
name = "page_size" name = "page_size"
version = "0.6.0" version = "0.6.0"
@@ -5334,15 +5316,6 @@ dependencies = [
"digest", "digest",
] ]
[[package]]
name = "sharded-slab"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6"
dependencies = [
"lazy_static",
]
[[package]] [[package]]
name = "share-picker" name = "share-picker"
version = "0.1.0" version = "0.1.0"
@@ -6358,16 +6331,6 @@ dependencies = [
"syn 2.0.79", "syn 2.0.79",
] ]
[[package]]
name = "thread_local"
version = "1.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b9ef9bad013ada3808854ceac7b46812a6465ba368859a37e2100283d2d719c"
dependencies = [
"cfg-if",
"once_cell",
]
[[package]] [[package]]
name = "tiff" name = "tiff"
version = "0.9.1" version = "0.9.1"
@@ -6643,32 +6606,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54"
dependencies = [ dependencies = [
"once_cell", "once_cell",
"valuable",
]
[[package]]
name = "tracing-log"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3"
dependencies = [
"log",
"once_cell",
"tracing-core",
]
[[package]]
name = "tracing-subscriber"
version = "0.3.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ad0f048c97dbd9faa9b7df56362b8ebcaa52adb06b498c050d2f4e32f90a7a8b"
dependencies = [
"nu-ansi-term",
"sharded-slab",
"smallvec",
"thread_local",
"tracing-core",
"tracing-log",
] ]
[[package]] [[package]]
@@ -6876,12 +6813,6 @@ dependencies = [
"wasm-bindgen", "wasm-bindgen",
] ]
[[package]]
name = "valuable"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d"
[[package]] [[package]]
name = "vcpkg" name = "vcpkg"
version = "0.2.15" version = "0.2.15"
@@ -7224,7 +7155,7 @@ version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb"
dependencies = [ dependencies = [
"windows-sys 0.48.0", "windows-sys 0.59.0",
] ]
[[package]] [[package]]

View File

@@ -48,8 +48,6 @@ linkify = "0.10.0"
regex = "1.10.4" regex = "1.10.4"
keyring = { version = "3", features = ["apple-native", "windows-native"] } keyring = { version = "3", features = ["apple-native", "windows-native"] }
keyring-search = "1.2.0" keyring-search = "1.2.0"
tracing-subscriber = "0.3.18"
log = "^0.4"
[target.'cfg(target_os = "macos")'.dependencies] [target.'cfg(target_os = "macos")'.dependencies]
border = { git = "https://github.com/ahkohd/tauri-toolkit", branch = "v2" } border = { git = "https://github.com/ahkohd/tauri-toolkit", branch = "v2" }

View File

@@ -14,7 +14,6 @@ use commands::{
window::*, window::*,
}; };
use common::{get_all_accounts, parse_event}; use common::{get_all_accounts, parse_event};
use log::info;
use nostr_sdk::prelude::{Profile as DatabaseProfile, *}; use nostr_sdk::prelude::{Profile as DatabaseProfile, *};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use specta::Type; use specta::Type;
@@ -169,8 +168,8 @@ fn main() {
.export(Typescript::default(), "../src/commands.gen.ts") .export(Typescript::default(), "../src/commands.gen.ts")
.expect("Failed to export typescript bindings"); .expect("Failed to export typescript bindings");
let mut ctx = tauri::generate_context!();
let tauri_builder = tauri::Builder::default(); let tauri_builder = tauri::Builder::default();
let mut ctx = tauri::generate_context!();
tauri_builder tauri_builder
.invoke_handler(builder.invoke_handler()) .invoke_handler(builder.invoke_handler())
@@ -440,7 +439,6 @@ fn main() {
while let Ok(notification) = notifications.recv().await { while let Ok(notification) = notifications.recv().await {
match notification { match notification {
RelayPoolNotification::Message { relay_url, message } => { RelayPoolNotification::Message { relay_url, message } => {
info!(target: "relay_events", "message: {}", message.as_pretty_json());
if let RelayMessage::Auth { challenge } = message { if let RelayMessage::Auth { challenge } = message {
match client.auth(challenge, relay_url.clone()).await { match client.auth(challenge, relay_url.clone()).await {
Ok(..) => { Ok(..) => {

View File

@@ -2,15 +2,14 @@ import { experimental_createPersister } from "@tanstack/query-persist-client-cor
import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { RouterProvider, createRouter } from "@tanstack/react-router"; import { RouterProvider, createRouter } from "@tanstack/react-router";
import { type } from "@tauri-apps/plugin-os"; import { type } from "@tauri-apps/plugin-os";
import { createStore } from "@tauri-apps/plugin-store";
import { StrictMode } from "react"; import { StrictMode } from "react";
import ReactDOM from "react-dom/client"; import ReactDOM from "react-dom/client";
import { newQueryStorage } from "./commons"; import { newQueryStorage } from "./commons";
import type { LumeEvent } from "./system"; import type { LumeEvent } from "./system";
import "./app.css"; // global styles
import { createStore } from "@tauri-apps/plugin-store";
import { routeTree } from "./routes.gen"; // auto generated file import { routeTree } from "./routes.gen"; // auto generated file
import "./app.css"; // global styles
const platform = type(); const platform = type();
// @ts-expect-error, required: https://github.com/tauri-apps/plugins-workspace/pull/1860 // @ts-expect-error, required: https://github.com/tauri-apps/plugins-workspace/pull/1860

View File

@@ -1,5 +1,5 @@
import type { Metadata } from "@/types";
import { useProfile } from "@/system"; import { useProfile } from "@/system";
import type { Metadata } from "@/types";
import { type ReactNode, createContext, useContext } from "react"; import { type ReactNode, createContext, useContext } from "react";
const UserContext = createContext<{ const UserContext = createContext<{

View File

@@ -9,7 +9,7 @@ import { useEffect } from "react";
interface RouterContext { interface RouterContext {
queryClient: QueryClient; queryClient: QueryClient;
platform: OsType; platform: OsType;
accounts: string[]; accounts?: string[];
} }
export const Route = createRootRouteWithContext<RouterContext>()({ export const Route = createRootRouteWithContext<RouterContext>()({

View File

@@ -1,3 +1,3 @@
import { createFileRoute } from '@tanstack/react-router' import { createFileRoute } from "@tanstack/react-router";
export const Route = createFileRoute('/_layout/')() export const Route = createFileRoute("/_layout/")();

View File

@@ -1,189 +1,189 @@
import { commands } from '@/commands.gen' import { commands } from "@/commands.gen";
import { appSettings } from '@/commons' import { appSettings } from "@/commons";
import { Spinner } from '@/components' import { Spinner } from "@/components";
import * as Switch from '@radix-ui/react-switch' import * as Switch from "@radix-ui/react-switch";
import { createLazyFileRoute } from '@tanstack/react-router' import { createLazyFileRoute } from "@tanstack/react-router";
import { useStore } from '@tanstack/react-store' import { useStore } from "@tanstack/react-store";
import { invoke } from '@tauri-apps/api/core' import { invoke } from "@tauri-apps/api/core";
import { message } from '@tauri-apps/plugin-dialog' import { message } from "@tauri-apps/plugin-dialog";
import { useCallback, useEffect, useState, useTransition } from 'react' import { useCallback, useEffect, useState, useTransition } from "react";
type Theme = 'auto' | 'light' | 'dark' type Theme = "auto" | "light" | "dark";
export const Route = createLazyFileRoute('/settings/$id/general')({ export const Route = createLazyFileRoute("/settings/$id/general")({
component: Screen, component: Screen,
}) });
function Screen() { function Screen() {
const [theme, setTheme] = useState<Theme>(null) const [theme, setTheme] = useState<Theme>(null);
const [isPending, startTransition] = useTransition() const [isPending, startTransition] = useTransition();
const changeTheme = useCallback(async (theme: string) => { const changeTheme = useCallback(async (theme: string) => {
if (theme === 'auto' || theme === 'light' || theme === 'dark') { if (theme === "auto" || theme === "light" || theme === "dark") {
invoke('plugin:theme|set_theme', { invoke("plugin:theme|set_theme", {
theme: theme, theme: theme,
}).then(() => setTheme(theme)) }).then(() => setTheme(theme));
} }
}, []) }, []);
const updateSettings = () => { const updateSettings = () => {
startTransition(async () => { startTransition(async () => {
const newSettings = JSON.stringify(appSettings.state) const newSettings = JSON.stringify(appSettings.state);
const res = await commands.setUserSettings(newSettings) const res = await commands.setUserSettings(newSettings);
if (res.status === 'error') { if (res.status === "error") {
await message(res.error, { kind: 'error' }) await message(res.error, { kind: "error" });
} }
return return;
}) });
} };
useEffect(() => { useEffect(() => {
invoke('plugin:theme|get_theme').then((data) => setTheme(data as Theme)) invoke("plugin:theme|get_theme").then((data) => setTheme(data as Theme));
}, []) }, []);
return ( return (
<div className="relative w-full"> <div className="relative w-full">
<div className="flex flex-col gap-6 px-3 pb-3"> <div className="flex flex-col gap-6 px-3 pb-3">
<div className="flex flex-col gap-2"> <div className="flex flex-col gap-2">
<h2 className="text-sm font-semibold text-neutral-700 dark:text-neutral-300"> <h2 className="text-sm font-semibold text-neutral-700 dark:text-neutral-300">
General General
</h2> </h2>
<div className="flex flex-col px-3 divide-y divide-black/10 dark:divide-white/10 bg-black/5 dark:bg-white/5 rounded-xl"> <div className="flex flex-col px-3 divide-y divide-black/10 dark:divide-white/10 bg-black/5 dark:bg-white/5 rounded-xl">
<Setting <Setting
name="Relay Hint" name="Relay Hint"
description="Use the relay hint if necessary." description="Use the relay hint if necessary."
label="use_relay_hint" label="use_relay_hint"
/> />
<Setting <Setting
name="Content Warning" name="Content Warning"
description="Shows a warning for notes that have a content warning." description="Shows a warning for notes that have a content warning."
label="content_warning" label="content_warning"
/> />
<Setting <Setting
name="Trusted Only" name="Trusted Only"
description="Only shows note's replies from your inner circle." description="Only shows note's replies from your inner circle."
label="trusted_only" label="trusted_only"
/> />
</div> </div>
</div> </div>
<div className="flex flex-col gap-2"> <div className="flex flex-col gap-2">
<h2 className="text-sm font-semibold text-neutral-700 dark:text-neutral-300"> <h2 className="text-sm font-semibold text-neutral-700 dark:text-neutral-300">
Appearance Appearance
</h2> </h2>
<div className="flex flex-col px-3 divide-y divide-black/10 dark:divide-white/10 bg-black/5 dark:bg-white/5 rounded-xl"> <div className="flex flex-col px-3 divide-y divide-black/10 dark:divide-white/10 bg-black/5 dark:bg-white/5 rounded-xl">
<div className="flex items-start justify-between w-full gap-4 py-3"> <div className="flex items-start justify-between w-full gap-4 py-3">
<div className="flex-1"> <div className="flex-1">
<h3 className="font-medium">Appearance</h3> <h3 className="font-medium">Appearance</h3>
<p className="text-sm text-neutral-700 dark:text-neutral-300"> <p className="text-sm text-neutral-700 dark:text-neutral-300">
Change app theme Change app theme
</p> </p>
</div> </div>
<div className="flex justify-end w-36 shrink-0"> <div className="flex justify-end w-36 shrink-0">
<select <select
name="theme" name="theme"
className="w-24 py-1 bg-transparent rounded-lg shadow-none outline-none border-1 border-black/10 dark:border-white/10" className="w-24 py-1 bg-transparent rounded-lg shadow-none outline-none border-1 border-black/10 dark:border-white/10"
defaultValue={theme} defaultValue={theme}
onChange={(e) => changeTheme(e.target.value)} onChange={(e) => changeTheme(e.target.value)}
> >
<option value="auto">Auto</option> <option value="auto">Auto</option>
<option value="light">Light</option> <option value="light">Light</option>
<option value="dark">Dark</option> <option value="dark">Dark</option>
</select> </select>
</div> </div>
</div> </div>
<Setting <Setting
name="Transparent Effect" name="Transparent Effect"
description="Use native window transparent effect." description="Use native window transparent effect."
label="transparent" label="transparent"
/> />
<Setting <Setting
name="Show Zap Button" name="Show Zap Button"
description="Shows the Zap button when viewing a note." description="Shows the Zap button when viewing a note."
label="display_zap_button" label="display_zap_button"
/> />
<Setting <Setting
name="Show Repost Button" name="Show Repost Button"
description="Shows the Repost button when viewing a note." description="Shows the Repost button when viewing a note."
label="display_repost_button" label="display_repost_button"
/> />
</div> </div>
</div> </div>
<div className="flex flex-col gap-2"> <div className="flex flex-col gap-2">
<h2 className="text-sm font-semibold text-neutral-700 dark:text-neutral-300"> <h2 className="text-sm font-semibold text-neutral-700 dark:text-neutral-300">
Privacy & Performance Privacy & Performance
</h2> </h2>
<div className="flex flex-col px-3 divide-y divide-black/10 dark:divide-white/10 bg-black/5 dark:bg-white/5 rounded-xl"> <div className="flex flex-col px-3 divide-y divide-black/10 dark:divide-white/10 bg-black/5 dark:bg-white/5 rounded-xl">
<Setting <Setting
name="Proxy" name="Proxy"
description="Set proxy address." description="Set proxy address."
label="proxy" label="proxy"
/> />
<Setting <Setting
name="Image Resize Service" name="Image Resize Service"
description="Use weserv/images for resize image on-the-fly." description="Use weserv/images for resize image on-the-fly."
label="image_resize_service" label="image_resize_service"
/> />
<Setting <Setting
name="Load Remote Media" name="Load Remote Media"
description="View the remote media directly." description="View the remote media directly."
label="display_media" label="display_media"
/> />
</div> </div>
</div> </div>
</div> </div>
<div className="sticky bottom-0 left-0 w-full h-16 flex items-center justify-end px-3"> <div className="sticky bottom-0 left-0 w-full h-16 flex items-center justify-end px-3">
<div className="absolute left-0 bottom-0 w-full h-11 gradient-mask-t-0 bg-neutral-100 dark:bg-neutral-900" /> <div className="absolute left-0 bottom-0 w-full h-11 gradient-mask-t-0 bg-neutral-100 dark:bg-neutral-900" />
<button <button
type="button" type="button"
onClick={() => updateSettings()} onClick={() => updateSettings()}
className="relative z-10 inline-flex items-center justify-center w-20 rounded-md shadow h-8 bg-blue-500 hover:bg-blue-600 text-white text-sm font-medium" className="relative z-10 inline-flex items-center justify-center w-20 rounded-md shadow h-8 bg-blue-500 hover:bg-blue-600 text-white text-sm font-medium"
> >
{isPending ? <Spinner className="size-4" /> : 'Update'} {isPending ? <Spinner className="size-4" /> : "Update"}
</button> </button>
</div> </div>
</div> </div>
) );
} }
function Setting({ function Setting({
label, label,
name, name,
description, description,
}: { }: {
label: string label: string;
name: string name: string;
description: string description: string;
}) { }) {
const state = useStore(appSettings, (state) => state[label]) const state = useStore(appSettings, (state) => state[label]);
const toggle = useCallback(() => { const toggle = useCallback(() => {
appSettings.setState((state) => { appSettings.setState((state) => {
return { return {
...state, ...state,
[label]: !state[label], [label]: !state[label],
} };
}) });
}, []) }, []);
return ( return (
<div className="flex items-start justify-between w-full gap-4 py-3"> <div className="flex items-start justify-between w-full gap-4 py-3">
<div className="flex-1"> <div className="flex-1">
<h3 className="font-medium">{name}</h3> <h3 className="font-medium">{name}</h3>
<p className="text-sm text-neutral-700 dark:text-neutral-300"> <p className="text-sm text-neutral-700 dark:text-neutral-300">
{description} {description}
</p> </p>
</div> </div>
<div className="flex justify-end w-36 shrink-0"> <div className="flex justify-end w-36 shrink-0">
<Switch.Root <Switch.Root
checked={state} checked={state}
onClick={() => toggle()} onClick={() => toggle()}
className="relative h-7 w-12 shrink-0 cursor-default rounded-full bg-black/10 outline-none data-[state=checked]:bg-blue-500 dark:bg-white/10" className="relative h-7 w-12 shrink-0 cursor-default rounded-full bg-black/10 outline-none data-[state=checked]:bg-blue-500 dark:bg-white/10"
> >
<Switch.Thumb className="block size-6 translate-x-0.5 rounded-full bg-white transition-transform duration-100 will-change-transform data-[state=checked]:translate-x-[19px]" /> <Switch.Thumb className="block size-6 translate-x-0.5 rounded-full bg-white transition-transform duration-100 will-change-transform data-[state=checked]:translate-x-[19px]" />
</Switch.Root> </Switch.Root>
</div> </div>
</div> </div>
) );
} }

View File

@@ -1,17 +1,17 @@
import { commands } from '@/commands.gen' import { commands } from "@/commands.gen";
import { appSettings } from '@/commons' import { appSettings } from "@/commons";
import { createFileRoute } from '@tanstack/react-router' import { createFileRoute } from "@tanstack/react-router";
export const Route = createFileRoute('/settings/$id/general')({ export const Route = createFileRoute("/settings/$id/general")({
beforeLoad: async () => { beforeLoad: async () => {
const res = await commands.getUserSettings() const res = await commands.getUserSettings();
if (res.status === 'ok') { if (res.status === "ok") {
appSettings.setState((state) => { appSettings.setState((state) => {
return { ...state, ...res.data } return { ...state, ...res.data };
}) });
} else { } else {
throw new Error(res.error) throw new Error(res.error);
} }
}, },
}) });

View File

@@ -27,7 +27,6 @@
"noImplicitAny": false, "noImplicitAny": false,
"noUnusedParameters": true, "noUnusedParameters": true,
"noFallthroughCasesInSwitch": true, "noFallthroughCasesInSwitch": true,
"strictNullChecks": false
}, },
"include": [ "include": [
"src" "src"