chore: clean up

This commit is contained in:
2024-02-25 15:52:47 +07:00
parent 2c8dd71792
commit 63db8b1423
39 changed files with 88 additions and 2501 deletions

View File

@@ -35,6 +35,7 @@
"webview:allow-create-webview",
"dialog:allow-open",
"fs:allow-read-file",
"shell:allow-open",
{
"identifier": "http:default",
"allow": [

View File

@@ -1 +1 @@
{"desktop-capability":{"identifier":"desktop-capability","description":"Capability for the desktop","remote":null,"local":true,"windows":["main","splash","editor","settings","event-*","user-*","column-*"],"permissions":["path:default","event:default","window:default","app:default","resources:default","menu:default","tray:default","notification:allow-is-permission-granted","notification:allow-request-permission","notification:default","os:allow-locale","os:allow-platform","updater:allow-check","updater:default","window:allow-start-dragging","store:allow-get","clipboard-manager:allow-write","clipboard-manager:allow-read","webview:allow-create-webview-window","webview:allow-create-webview","dialog:allow-open","fs:allow-read-file",{"identifier":"http:default","allow":[{"url":"http://**/"},{"url":"https://**/"}]},{"identifier":"fs:allow-read-text-file","allow":[{"path":"$RESOURCE/locales/*"}]}],"platforms":["linux","macOS","windows"]}}
{"desktop-capability":{"identifier":"desktop-capability","description":"Capability for the desktop","remote":null,"local":true,"windows":["main","splash","editor","settings","event-*","user-*","column-*"],"permissions":["path:default","event:default","window:default","app:default","resources:default","menu:default","tray:default","notification:allow-is-permission-granted","notification:allow-request-permission","notification:default","os:allow-locale","os:allow-platform","updater:allow-check","updater:default","window:allow-start-dragging","store:allow-get","clipboard-manager:allow-write","clipboard-manager:allow-read","webview:allow-create-webview-window","webview:allow-create-webview","dialog:allow-open","fs:allow-read-file","shell:allow-open",{"identifier":"http:default","allow":[{"url":"http://**/"},{"url":"https://**/"}]},{"identifier":"fs:allow-read-text-file","allow":[{"path":"$RESOURCE/locales/*"}]}],"platforms":["linux","macOS","windows"]}}

View File

@@ -12,11 +12,9 @@ use keyring::Entry;
use nostr_sdk::prelude::*;
use tauri::Manager;
use tauri_plugin_autostart::MacosLauncher;
use tokio::sync::Mutex;
pub struct Nostr {
client: Client,
contact_list: Mutex<Option<Vec<PublicKey>>>,
}
fn main() {
@@ -68,7 +66,6 @@ fn main() {
// Update global state
handle.manage(Nostr {
client: client.into(),
contact_list: Mutex::new(None),
})
});

View File

@@ -50,9 +50,15 @@ pub async fn get_local_events(
None => Timestamp::now(),
};
let contact_list = state.contact_list.lock().await;
let contact_list = client
.get_contact_list_public_keys(Some(Duration::from_secs(10)))
.await;
if let Ok(authors) = contact_list {
if authors.len() == 0 {
return Err("Get text event failed".into());
}
if let Some(authors) = contact_list.clone() {
let filter = Filter::new()
.kinds(vec![Kind::TextNote, Kind::Repost])
.authors(authors)
@@ -68,7 +74,7 @@ pub async fn get_local_events(
Err("Get text event failed".into())
}
} else {
Err("Contact list not found".into())
Err("Get contact list failed".into())
}
}

View File

@@ -3,7 +3,6 @@ use keyring::Entry;
use nostr_sdk::prelude::*;
use std::io::{BufReader, Read};
use std::iter;
use std::time::Duration;
use std::{fs::File, io::Write, str::FromStr};
use tauri::{Manager, State};
@@ -42,15 +41,6 @@ pub async fn save_key(
let client = &state.client;
client.set_signer(Some(signer)).await;
// Update contact list
let mut contact_list = state.contact_list.lock().await;
if let Ok(list) = client
.get_contact_list_public_keys(Some(Duration::from_secs(10)))
.await
{
*contact_list = Some(list);
}
let keyring_entry = Entry::new("Lume Secret Storage", "AppKey").unwrap();
let secret_key = keyring_entry.get_password().unwrap();
let app_key = age::x25519::Identity::from_str(&secret_key).unwrap();
@@ -154,15 +144,6 @@ pub async fn load_selected_account(
// Update signer
client.set_signer(Some(signer)).await;
// Update contact list
let mut contact_list = state.contact_list.lock().await;
if let Ok(list) = client
.get_contact_list_public_keys(Some(Duration::from_secs(10)))
.await
{
*contact_list = Some(list);
}
Ok(true)
} else {
Ok(false)