chore: clean up tauri commands

This commit is contained in:
reya 2024-05-18 14:59:34 +07:00
parent 99d9c70826
commit ca06f2b6ed
11 changed files with 21 additions and 388 deletions

View File

@ -411,17 +411,20 @@ export class Ark {
}
}
public get_thread(tags: string[][]) {
public get_thread(tags: string[][], gossip: boolean = false) {
let root: string = null;
let reply: string = null;
// Get all event references from tags, ignore mention
const events = tags.filter((el) => el[0] === "e" && el[3] !== "mention");
const relays = tags.filter((el) => el[0] === "e" && el[2].length);
if (relays.length >= 1) {
for (const relay of relays) {
if (relay[2]?.length) this.add_relay(relay[2]);
if (gossip) {
const relays = tags.filter((el) => el[0] === "e" && el[2]?.length);
if (relays.length >= 1) {
for (const relay of relays) {
if (relay[2]?.length) this.add_relay(relay[2]);
}
}
}

170
src-tauri/Cargo.lock generated
View File

@ -107,55 +107,6 @@ dependencies = [
"libc",
]
[[package]]
name = "anstream"
version = "0.6.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "418c75fa768af9c03be99d17643f93f79bbba589895012a80e3452a19ddda15b"
dependencies = [
"anstyle",
"anstyle-parse",
"anstyle-query",
"anstyle-wincon",
"colorchoice",
"is_terminal_polyfill",
"utf8parse",
]
[[package]]
name = "anstyle"
version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "038dfcf04a5feb68e9c60b21c9625a54c2c0616e79b72b0fd87075a056ae1d1b"
[[package]]
name = "anstyle-parse"
version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c03a11a9034d92058ceb6ee011ce58af4a9bf61491aa7e1e59ecd24bd40d22d4"
dependencies = [
"utf8parse",
]
[[package]]
name = "anstyle-query"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a64c907d4e79225ac72e2a354c9ce84d50ebb4586dee56c82b3ee73004f537f5"
dependencies = [
"windows-sys 0.52.0",
]
[[package]]
name = "anstyle-wincon"
version = "3.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "61a38449feb7068f52bb06c12759005cf459ee52bb4adc1d5a7c4322d716fb19"
dependencies = [
"anstyle",
"windows-sys 0.52.0",
]
[[package]]
name = "anyhow"
version = "1.0.85"
@ -488,17 +439,6 @@ version = "1.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0"
[[package]]
name = "auto-launch"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1f012b8cc0c850f34117ec8252a44418f2e34a2cf501de89e29b241ae5f79471"
dependencies = [
"dirs",
"thiserror",
"winreg 0.10.1",
]
[[package]]
name = "autocfg"
version = "1.3.0"
@ -932,33 +872,6 @@ dependencies = [
"zeroize",
]
[[package]]
name = "clap"
version = "4.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "90bc066a67923782aa8515dbaea16946c5bcc5addbd668bb80af688e53e548a0"
dependencies = [
"clap_builder",
]
[[package]]
name = "clap_builder"
version = "4.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ae129e2e766ae0ec03484e609954119f123cc1fe650337e155d03b022f24f7b4"
dependencies = [
"anstream",
"anstyle",
"clap_lex",
"strsim",
]
[[package]]
name = "clap_lex"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce"
[[package]]
name = "clipboard-win"
version = "5.3.1"
@ -1004,12 +917,6 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b"
[[package]]
name = "colorchoice"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b6a852b24ab71dffc585bcb46eaf7959d175cb865a7152e35b348d1b2960422"
[[package]]
name = "combine"
version = "4.6.7"
@ -1350,15 +1257,6 @@ dependencies = [
"subtle",
]
[[package]]
name = "dirs"
version = "4.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca3aa72a6f96ea37bbc5aa912f6788242832f75369bdfdadcb0e38423f100059"
dependencies = [
"dirs-sys",
]
[[package]]
name = "dirs-next"
version = "2.0.0"
@ -1369,17 +1267,6 @@ dependencies = [
"dirs-sys-next",
]
[[package]]
name = "dirs-sys"
version = "0.3.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1b1d1d91c932ef41c0f2663aa8b0ca0342d444d842c06914aa0a7e352d0bada6"
dependencies = [
"libc",
"redox_users",
"winapi",
]
[[package]]
name = "dirs-sys-next"
version = "0.1.2"
@ -1482,7 +1369,7 @@ dependencies = [
"rustc_version",
"toml 0.8.2",
"vswhom",
"winreg 0.52.0",
"winreg",
]
[[package]]
@ -2660,12 +2547,6 @@ dependencies = [
"once_cell",
]
[[package]]
name = "is_terminal_polyfill"
version = "1.70.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8478577c03552c21db0e2724ffb8986a5ce7af88107e6be5d2ee6e158c12800"
[[package]]
name = "itoa"
version = "0.4.8"
@ -2987,8 +2868,6 @@ dependencies = [
"serde_json",
"tauri",
"tauri-build",
"tauri-plugin-autostart",
"tauri-plugin-cli",
"tauri-plugin-clipboard-manager",
"tauri-plugin-dialog",
"tauri-plugin-fs",
@ -4455,7 +4334,7 @@ dependencies = [
"wasm-streams",
"web-sys",
"webpki-roots",
"winreg 0.52.0",
"winreg",
]
[[package]]
@ -5410,36 +5289,6 @@ dependencies = [
"walkdir",
]
[[package]]
name = "tauri-plugin-autostart"
version = "2.0.0-beta.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8c96bf3c316939431e021b48622f15e0e1126376e43f1c35a29e7d24c5760209"
dependencies = [
"auto-launch",
"log",
"serde",
"serde_json",
"tauri",
"tauri-plugin",
"thiserror",
]
[[package]]
name = "tauri-plugin-cli"
version = "2.0.0-beta.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "379e72dd4771d4d4f42c2ea8682f1ad4657fa5a042c3739a5e35300acc694c0c"
dependencies = [
"clap",
"log",
"serde",
"serde_json",
"tauri",
"tauri-plugin",
"thiserror",
]
[[package]]
name = "tauri-plugin-clipboard-manager"
version = "2.1.0-beta.2"
@ -6283,12 +6132,6 @@ version = "0.7.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9"
[[package]]
name = "utf8parse"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a"
[[package]]
name = "uuid"
version = "1.8.0"
@ -6943,15 +6786,6 @@ dependencies = [
"memchr",
]
[[package]]
name = "winreg"
version = "0.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "80d0f4e272c85def139476380b12f9ac60926689dd2e01d4923222f40580869d"
dependencies = [
"winapi",
]
[[package]]
name = "winreg"
version = "0.52.0"

View File

@ -22,7 +22,6 @@ tauri = { version = "2.0.0-beta", features = [
"native-tls-vendored",
"protocol-asset",
] }
tauri-plugin-cli = "2.0.0-beta"
tauri-plugin-clipboard-manager = "2.1.0-beta"
tauri-plugin-dialog = "2.0.0-beta"
tauri-plugin-fs = "2.0.0-beta"
@ -32,7 +31,6 @@ tauri-plugin-os = "2.0.0-beta"
tauri-plugin-process = "2.0.0-beta"
tauri-plugin-shell = "2.0.0-beta"
tauri-plugin-updater = "2.0.0-beta"
tauri-plugin-autostart = "2.0.0-beta"
tauri-plugin-upload = "2.0.0-beta"
tauri-plugin-window-state = "2.0.0-beta"
webpage = { version = "2.0", features = ["serde"] }

File diff suppressed because one or more lines are too long

View File

@ -2545,75 +2545,6 @@
"app:deny-version"
]
},
{
"type": "string",
"enum": [
"autostart:default"
]
},
{
"description": "autostart:allow-disable -> Enables the disable command without any pre-configured scope.",
"type": "string",
"enum": [
"autostart:allow-disable"
]
},
{
"description": "autostart:allow-enable -> Enables the enable command without any pre-configured scope.",
"type": "string",
"enum": [
"autostart:allow-enable"
]
},
{
"description": "autostart:allow-is-enabled -> Enables the is_enabled command without any pre-configured scope.",
"type": "string",
"enum": [
"autostart:allow-is-enabled"
]
},
{
"description": "autostart:deny-disable -> Denies the disable command without any pre-configured scope.",
"type": "string",
"enum": [
"autostart:deny-disable"
]
},
{
"description": "autostart:deny-enable -> Denies the enable command without any pre-configured scope.",
"type": "string",
"enum": [
"autostart:deny-enable"
]
},
{
"description": "autostart:deny-is-enabled -> Denies the is_enabled command without any pre-configured scope.",
"type": "string",
"enum": [
"autostart:deny-is-enabled"
]
},
{
"description": "cli:default -> Allows reading the CLI matches",
"type": "string",
"enum": [
"cli:default"
]
},
{
"description": "cli:allow-cli-matches -> Enables the cli_matches command without any pre-configured scope.",
"type": "string",
"enum": [
"cli:allow-cli-matches"
]
},
{
"description": "cli:deny-cli-matches -> Denies the cli_matches command without any pre-configured scope.",
"type": "string",
"enum": [
"cli:deny-cli-matches"
]
},
{
"type": "string",
"enum": [

View File

@ -2545,75 +2545,6 @@
"app:deny-version"
]
},
{
"type": "string",
"enum": [
"autostart:default"
]
},
{
"description": "autostart:allow-disable -> Enables the disable command without any pre-configured scope.",
"type": "string",
"enum": [
"autostart:allow-disable"
]
},
{
"description": "autostart:allow-enable -> Enables the enable command without any pre-configured scope.",
"type": "string",
"enum": [
"autostart:allow-enable"
]
},
{
"description": "autostart:allow-is-enabled -> Enables the is_enabled command without any pre-configured scope.",
"type": "string",
"enum": [
"autostart:allow-is-enabled"
]
},
{
"description": "autostart:deny-disable -> Denies the disable command without any pre-configured scope.",
"type": "string",
"enum": [
"autostart:deny-disable"
]
},
{
"description": "autostart:deny-enable -> Denies the enable command without any pre-configured scope.",
"type": "string",
"enum": [
"autostart:deny-enable"
]
},
{
"description": "autostart:deny-is-enabled -> Denies the is_enabled command without any pre-configured scope.",
"type": "string",
"enum": [
"autostart:deny-is-enabled"
]
},
{
"description": "cli:default -> Allows reading the CLI matches",
"type": "string",
"enum": [
"cli:default"
]
},
{
"description": "cli:allow-cli-matches -> Enables the cli_matches command without any pre-configured scope.",
"type": "string",
"enum": [
"cli:allow-cli-matches"
]
},
{
"description": "cli:deny-cli-matches -> Denies the cli_matches command without any pre-configured scope.",
"type": "string",
"enum": [
"cli:deny-cli-matches"
]
},
{
"type": "string",
"enum": [

View File

@ -4,7 +4,6 @@ use std::path::PathBuf;
use tauri::utils::config::WindowEffectsConfig;
use tauri::window::Effect;
use tauri::TitleBarStyle;
use tauri::Url;
use tauri::WebviewWindowBuilder;
use tauri::{LogicalPosition, LogicalSize, Manager, WebviewUrl};
@ -57,22 +56,6 @@ pub fn close_column(label: &str, app_handle: tauri::AppHandle) -> Result<bool, (
}
}
#[tauri::command]
pub fn navigate(label: &str, url: &str, app_handle: tauri::AppHandle) -> Result<(), String> {
match app_handle.get_webview(label) {
Some(mut webview) => {
if let Ok(new_url) = Url::parse(url) {
println!("navigate to: {}", new_url);
webview.navigate(new_url);
Ok(())
} else {
Err("URL is not valid".into())
}
}
None => Err("Webview not found".into()),
}
}
#[tauri::command]
pub fn reposition_column(
label: &str,

View File

@ -18,7 +18,6 @@ extern crate objc;
use nostr_sdk::prelude::*;
use std::fs;
use tauri::Manager;
use tauri_plugin_autostart::MacosLauncher;
#[cfg(target_os = "macos")]
use traffic_light::setup_traffic_light_positioner;
@ -93,13 +92,8 @@ fn main() {
.plugin(tauri_plugin_shell::init())
.plugin(tauri_plugin_upload::init())
.plugin(tauri_plugin_updater::Builder::new().build())
.plugin(tauri_plugin_autostart::init(
MacosLauncher::LaunchAgent,
Some(vec![]),
))
.invoke_handler(tauri::generate_handler![
nostr::relay::get_relays,
nostr::relay::list_connected_relays,
nostr::relay::connect_relay,
nostr::relay::remove_relay,
nostr::keys::create_keys,
@ -107,7 +101,6 @@ fn main() {
nostr::keys::get_encrypted_key,
nostr::keys::get_stored_nsec,
nostr::keys::nostr_connect,
nostr::keys::verify_signer,
nostr::keys::load_selected_account,
nostr::keys::event_to_bech32,
nostr::keys::user_to_bech32,
@ -136,17 +129,15 @@ fn main() {
nostr::event::get_event_thread,
nostr::event::publish,
nostr::event::repost,
nostr::event::search,
commands::folder::show_in_folder,
commands::folder::get_accounts,
commands::opg::fetch_opg,
commands::window::create_column,
commands::window::close_column,
commands::window::reposition_column,
commands::window::resize_column,
commands::window::open_window,
commands::window::navigate,
commands::window::set_badge
commands::window::set_badge,
commands::opg::fetch_opg,
])
.run(tauri::generate_context!())
.expect("error while running tauri application")

View File

@ -216,24 +216,3 @@ pub async fn repost(raw: &str, state: State<'_, Nostr>) -> Result<EventId, Strin
Err("Repost failed".into())
}
}
#[tauri::command]
pub async fn search(
content: &str,
limit: usize,
state: State<'_, Nostr>,
) -> Result<Vec<Event>, String> {
let client = &state.client;
let filter = Filter::new()
.kinds(vec![Kind::TextNote, Kind::Metadata])
.search(content)
.limit(limit);
match client
.get_events_of(vec![filter], Some(Duration::from_secs(15)))
.await
{
Ok(events) => Ok(events),
Err(err) => Err(err.to_string()),
}
}

View File

@ -107,17 +107,6 @@ pub async fn nostr_connect(
}
}
#[tauri::command]
pub async fn verify_signer(state: State<'_, Nostr>) -> Result<bool, ()> {
let client = &state.client;
if (client.signer().await).is_ok() {
Ok(true)
} else {
Ok(false)
}
}
#[tauri::command(async)]
pub fn get_encrypted_key(npub: &str, password: &str) -> Result<String, String> {
let keyring = Entry::new("Lume Secret Storage", npub).unwrap();
@ -249,9 +238,12 @@ pub fn to_npub(hex: &str) -> Result<String, ()> {
}
#[tauri::command]
pub async fn verify_nip05(key: &str, nip05: &str) -> Result<bool, ()> {
let public_key = PublicKey::from_str(key).unwrap();
let status = nip05::verify(&public_key, nip05, None).await;
Ok(status.is_ok())
pub async fn verify_nip05(key: &str, nip05: &str) -> Result<bool, String> {
match PublicKey::from_str(key) {
Ok(public_key) => {
let status = nip05::verify(&public_key, nip05, None).await;
Ok(status.is_ok())
}
Err(err) => Err(err.to_string()),
}
}

View File

@ -72,15 +72,6 @@ pub async fn get_relays(state: State<'_, Nostr>) -> Result<Relays, ()> {
}
}
#[tauri::command]
pub async fn list_connected_relays(state: State<'_, Nostr>) -> Result<Vec<Url>, ()> {
let client = &state.client;
let connected_relays = client.relays().await;
let list = connected_relays.into_keys().collect();
Ok(list)
}
#[tauri::command]
pub async fn connect_relay(relay: &str, state: State<'_, Nostr>) -> Result<bool, ()> {
let client = &state.client;