feat: add editor screen
This commit is contained in:
@@ -3,7 +3,15 @@
|
||||
"identifier": "desktop-capability",
|
||||
"description": "Capability for the desktop",
|
||||
"platforms": ["linux", "macOS", "windows"],
|
||||
"windows": ["main", "splash", "settings", "event-*", "user-*", "column-*"],
|
||||
"windows": [
|
||||
"main",
|
||||
"splash",
|
||||
"editor",
|
||||
"settings",
|
||||
"event-*",
|
||||
"user-*",
|
||||
"column-*"
|
||||
],
|
||||
"permissions": [
|
||||
"path:default",
|
||||
"event:default",
|
||||
@@ -27,6 +35,8 @@
|
||||
"clipboard-manager:allow-read",
|
||||
"webview:allow-create-webview-window",
|
||||
"webview:allow-create-webview",
|
||||
"dialog:allow-open",
|
||||
"fs:allow-read-file",
|
||||
{
|
||||
"identifier": "http:default",
|
||||
"allow": [
|
||||
|
||||
@@ -1 +1 @@
|
||||
{"desktop-capability":{"identifier":"desktop-capability","description":"Capability for the desktop","context":"local","windows":["main","splash","settings","event-*","user-*","column-*"],"permissions":["path:default","event:default","window:default","app:default","resources:default","menu:default","tray:default","theme:allow-set-theme","theme:allow-get-theme","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",{"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","context":"local","windows":["main","splash","editor","settings","event-*","user-*","column-*"],"permissions":["path:default","event:default","window:default","app:default","resources:default","menu:default","tray:default","theme:allow-set-theme","theme:allow-get-theme","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"]}}
|
||||
@@ -14,7 +14,7 @@ use tauri_plugin_autostart::MacosLauncher;
|
||||
use tokio::sync::Mutex;
|
||||
|
||||
pub struct Nostr {
|
||||
client: Mutex<Client>,
|
||||
client: Client,
|
||||
contact_list: Mutex<Option<Vec<PublicKey>>>,
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ fn main() {
|
||||
|
||||
// Update global state
|
||||
handle.manage(Nostr {
|
||||
client: Mutex::new(client),
|
||||
client: client.into(),
|
||||
contact_list: Mutex::new(None),
|
||||
})
|
||||
});
|
||||
|
||||
@@ -5,7 +5,7 @@ use tauri::State;
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn get_event(id: &str, state: State<'_, Nostr>) -> Result<String, String> {
|
||||
let client = state.client.lock().await;
|
||||
let client = &state.client;
|
||||
let event_id: Option<EventId> = match Nip19::from_bech32(id) {
|
||||
Ok(val) => match val {
|
||||
Nip19::EventId(id) => Some(id),
|
||||
@@ -44,7 +44,7 @@ pub async fn get_local_events(
|
||||
until: Option<&str>,
|
||||
state: State<'_, Nostr>,
|
||||
) -> Result<Vec<Event>, String> {
|
||||
let client = state.client.lock().await;
|
||||
let client = &state.client;
|
||||
let f_until = match until {
|
||||
Some(until) => Timestamp::from_str(until).unwrap(),
|
||||
None => Timestamp::now(),
|
||||
@@ -78,7 +78,7 @@ pub async fn get_global_events(
|
||||
until: Option<&str>,
|
||||
state: State<'_, Nostr>,
|
||||
) -> Result<Vec<Event>, String> {
|
||||
let client = state.client.lock().await;
|
||||
let client = &state.client;
|
||||
let f_until = match until {
|
||||
Some(until) => Timestamp::from_str(until).unwrap(),
|
||||
None => Timestamp::now(),
|
||||
@@ -101,7 +101,7 @@ pub async fn get_global_events(
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn get_event_thread(id: &str, state: State<'_, Nostr>) -> Result<Vec<Event>, ()> {
|
||||
let client = state.client.lock().await;
|
||||
let client = &state.client;
|
||||
let event_id = EventId::from_hex(id).unwrap();
|
||||
let filter = Filter::new().kinds(vec![Kind::TextNote]).event(event_id);
|
||||
|
||||
@@ -116,14 +116,19 @@ pub async fn get_event_thread(id: &str, state: State<'_, Nostr>) -> Result<Vec<E
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn publish(content: &str, state: State<'_, Nostr>) -> Result<EventId, ()> {
|
||||
let client = state.client.lock().await;
|
||||
let event = client
|
||||
.publish_text_note(content, [])
|
||||
.await
|
||||
.expect("Publish new text note failed");
|
||||
pub async fn publish(
|
||||
content: &str,
|
||||
tags: Vec<Vec<String>>,
|
||||
state: State<'_, Nostr>,
|
||||
) -> Result<String, String> {
|
||||
let client = &state.client;
|
||||
let final_tags = tags.into_iter().map(|val| Tag::parse(val).unwrap());
|
||||
|
||||
Ok(event)
|
||||
if let Ok(event_id) = client.publish_text_note(content, final_tags).await {
|
||||
Ok(event_id.to_bech32().unwrap())
|
||||
} else {
|
||||
Err("Publish text note failed".into())
|
||||
}
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
@@ -132,7 +137,7 @@ pub async fn reply_to(
|
||||
tags: Vec<String>,
|
||||
state: State<'_, Nostr>,
|
||||
) -> Result<EventId, String> {
|
||||
let client = state.client.lock().await;
|
||||
let client = &state.client;
|
||||
if let Ok(event_tags) = Tag::parse(tags) {
|
||||
let event = client
|
||||
.publish_text_note(content, vec![event_tags])
|
||||
@@ -147,7 +152,7 @@ pub async fn reply_to(
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn repost(id: &str, pubkey: &str, state: State<'_, Nostr>) -> Result<EventId, ()> {
|
||||
let client = state.client.lock().await;
|
||||
let client = &state.client;
|
||||
let public_key = PublicKey::from_str(pubkey).unwrap();
|
||||
let event_id = EventId::from_hex(id).unwrap();
|
||||
|
||||
@@ -161,7 +166,7 @@ pub async fn repost(id: &str, pubkey: &str, state: State<'_, Nostr>) -> Result<E
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn upvote(id: &str, pubkey: &str, state: State<'_, Nostr>) -> Result<EventId, ()> {
|
||||
let client = state.client.lock().await;
|
||||
let client = &state.client;
|
||||
let public_key = PublicKey::from_str(pubkey).unwrap();
|
||||
let event_id = EventId::from_hex(id).unwrap();
|
||||
|
||||
@@ -175,7 +180,7 @@ pub async fn upvote(id: &str, pubkey: &str, state: State<'_, Nostr>) -> Result<E
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn downvote(id: &str, pubkey: &str, state: State<'_, Nostr>) -> Result<EventId, ()> {
|
||||
let client = state.client.lock().await;
|
||||
let client = &state.client;
|
||||
let public_key = PublicKey::from_str(pubkey).unwrap();
|
||||
let event_id = EventId::from_hex(id).unwrap();
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ pub async fn save_key(
|
||||
let signer = NostrSigner::Keys(nostr_keys);
|
||||
|
||||
// Update client's signer
|
||||
let client = state.client.lock().await;
|
||||
let client = &state.client;
|
||||
client.set_signer(Some(signer)).await;
|
||||
|
||||
// Update contact list
|
||||
@@ -91,7 +91,7 @@ pub fn get_public_key(nsec: &str) -> Result<String, ()> {
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn update_signer(nsec: &str, state: State<'_, Nostr>) -> Result<(), ()> {
|
||||
let client = state.client.lock().await;
|
||||
let client = &state.client;
|
||||
let secret_key = SecretKey::from_bech32(nsec).unwrap();
|
||||
let keys = Keys::new(secret_key);
|
||||
let signer = NostrSigner::Keys(keys);
|
||||
@@ -103,7 +103,7 @@ pub async fn update_signer(nsec: &str, state: State<'_, Nostr>) -> Result<(), ()
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn verify_signer(state: State<'_, Nostr>) -> Result<bool, ()> {
|
||||
let client = state.client.lock().await;
|
||||
let client = &state.client;
|
||||
|
||||
if let Ok(_) = client.signer().await {
|
||||
Ok(true)
|
||||
@@ -118,7 +118,7 @@ pub async fn load_selected_account(
|
||||
app_handle: tauri::AppHandle,
|
||||
state: State<'_, Nostr>,
|
||||
) -> Result<bool, String> {
|
||||
let client = state.client.lock().await;
|
||||
let client = &state.client;
|
||||
let config_dir = app_handle.path().app_config_dir().unwrap();
|
||||
let keyring_entry = Entry::new("Lume Secret Storage", "AppKey").unwrap();
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ use tauri::State;
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn get_profile(id: &str, state: State<'_, Nostr>) -> Result<Metadata, String> {
|
||||
let client = state.client.lock().await;
|
||||
let client = &state.client;
|
||||
let public_key: Option<PublicKey> = match Nip19::from_bech32(id) {
|
||||
Ok(val) => match val {
|
||||
Nip19::Pubkey(pubkey) => Some(pubkey),
|
||||
@@ -42,7 +42,7 @@ pub async fn get_profile(id: &str, state: State<'_, Nostr>) -> Result<Metadata,
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn get_contact_list(state: State<'_, Nostr>) -> Result<Vec<String>, String> {
|
||||
let client = state.client.lock().await;
|
||||
let client = &state.client;
|
||||
let contact_list = client.get_contact_list(Some(Duration::from_secs(10))).await;
|
||||
|
||||
if let Ok(list) = contact_list {
|
||||
@@ -65,7 +65,7 @@ pub async fn create_profile(
|
||||
website: &str,
|
||||
state: State<'_, Nostr>,
|
||||
) -> Result<EventId, ()> {
|
||||
let client = state.client.lock().await;
|
||||
let client = &state.client;
|
||||
let metadata = Metadata::new()
|
||||
.name(name)
|
||||
.display_name(display_name)
|
||||
@@ -89,7 +89,7 @@ pub async fn follow(
|
||||
alias: Option<&str>,
|
||||
state: State<'_, Nostr>,
|
||||
) -> Result<EventId, String> {
|
||||
let client = state.client.lock().await;
|
||||
let client = &state.client;
|
||||
let public_key = PublicKey::from_str(id).unwrap();
|
||||
let contact = Contact::new(public_key, None, alias);
|
||||
let contact_list = client.get_contact_list(Some(Duration::from_secs(10))).await;
|
||||
@@ -110,7 +110,7 @@ pub async fn follow(
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn unfollow(id: &str, state: State<'_, Nostr>) -> Result<EventId, String> {
|
||||
let client = state.client.lock().await;
|
||||
let client = &state.client;
|
||||
let public_key = PublicKey::from_str(id).unwrap();
|
||||
let contact_list = client.get_contact_list(Some(Duration::from_secs(10))).await;
|
||||
|
||||
@@ -135,7 +135,7 @@ pub async fn unfollow(id: &str, state: State<'_, Nostr>) -> Result<EventId, Stri
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn set_interest(content: &str, state: State<'_, Nostr>) -> Result<EventId, String> {
|
||||
let client = state.client.lock().await;
|
||||
let client = &state.client;
|
||||
let tag = Tag::Identifier("lume_user_interest".into());
|
||||
let builder = EventBuilder::new(Kind::ApplicationSpecificData, content, vec![tag]);
|
||||
|
||||
@@ -148,7 +148,7 @@ pub async fn set_interest(content: &str, state: State<'_, Nostr>) -> Result<Even
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn get_interest(id: &str, state: State<'_, Nostr>) -> Result<String, String> {
|
||||
let client = state.client.lock().await;
|
||||
let client = &state.client;
|
||||
let public_key: Option<PublicKey> = match Nip19::from_bech32(id) {
|
||||
Ok(val) => match val {
|
||||
Nip19::Pubkey(pubkey) => Some(pubkey),
|
||||
@@ -188,7 +188,7 @@ pub async fn get_interest(id: &str, state: State<'_, Nostr>) -> Result<String, S
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn set_settings(content: &str, state: State<'_, Nostr>) -> Result<EventId, String> {
|
||||
let client = state.client.lock().await;
|
||||
let client = &state.client;
|
||||
let tag = Tag::Identifier("lume_user_settings".into());
|
||||
let builder = EventBuilder::new(Kind::ApplicationSpecificData, content, vec![tag]);
|
||||
|
||||
@@ -201,7 +201,7 @@ pub async fn set_settings(content: &str, state: State<'_, Nostr>) -> Result<Even
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn get_settings(id: &str, state: State<'_, Nostr>) -> Result<String, String> {
|
||||
let client = state.client.lock().await;
|
||||
let client = &state.client;
|
||||
let public_key: Option<PublicKey> = match Nip19::from_bech32(id) {
|
||||
Ok(val) => match val {
|
||||
Nip19::Pubkey(pubkey) => Some(pubkey),
|
||||
|
||||
@@ -4,7 +4,7 @@ use tauri::State;
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn list_connected_relays(state: State<'_, Nostr>) -> Result<Vec<Url>, ()> {
|
||||
let client = state.client.lock().await;
|
||||
let client = &state.client;
|
||||
let relays = client.relays().await;
|
||||
let list: Vec<Url> = relays.into_keys().collect();
|
||||
|
||||
@@ -13,7 +13,7 @@ pub async fn list_connected_relays(state: State<'_, Nostr>) -> Result<Vec<Url>,
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn connect_relay(relay: &str, state: State<'_, Nostr>) -> Result<bool, ()> {
|
||||
let client = state.client.lock().await;
|
||||
let client = &state.client;
|
||||
if let Ok(_) = client.add_relay(relay).await {
|
||||
Ok(true)
|
||||
} else {
|
||||
@@ -23,7 +23,7 @@ pub async fn connect_relay(relay: &str, state: State<'_, Nostr>) -> Result<bool,
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn remove_relay(relay: &str, state: State<'_, Nostr>) -> Result<bool, ()> {
|
||||
let client = state.client.lock().await;
|
||||
let client = &state.client;
|
||||
if let Ok(_) = client.remove_relay(relay).await {
|
||||
Ok(true)
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user