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,47 +1,47 @@
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">
@@ -140,11 +140,11 @@ function Screen() {
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({
@@ -152,20 +152,20 @@ function Setting({
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">
@@ -185,5 +185,5 @@ function Setting({
</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"