.
Some checks failed
Rust / build (ubuntu-latest, stable) (push) Failing after 1m40s
Rust / build (ubuntu-latest, stable) (pull_request) Failing after 1m50s

This commit is contained in:
2026-02-06 13:25:34 +07:00
parent fce4c1bbcd
commit 253d04f988
17 changed files with 1081 additions and 872 deletions

View File

@@ -1,6 +1,6 @@
use std::collections::{HashMap, HashSet};
use anyhow::{anyhow, Error};
use anyhow::{anyhow, Context as AnyhowContext, Error};
use gpui::{App, AppContext, Context, Entity, Global, Subscription, Task};
use nostr_sdk::prelude::*;
use serde::{Deserialize, Serialize};
@@ -121,7 +121,7 @@ pub struct AppSettings {
_subscriptions: SmallVec<[Subscription; 1]>,
/// Background tasks
_tasks: SmallVec<[Task<()>; 1]>,
tasks: SmallVec<[Task<()>; 1]>,
}
impl AppSettings {
@@ -163,8 +163,8 @@ impl AppSettings {
Self {
values: Settings::default(),
tasks,
_subscriptions: subscriptions,
_tasks: tasks,
}
}
@@ -172,7 +172,6 @@ impl AppSettings {
fn get_from_database(cx: &App) -> Task<Result<Settings, Error>> {
let nostr = NostrRegistry::global(cx);
let client = nostr.read(cx).client();
let current_user = nostr.read(cx).identity().read(cx).public_key;
cx.background_spawn(async move {
// Construct a filter to get the latest settings
@@ -181,9 +180,12 @@ impl AppSettings {
.identifier(SETTINGS_IDENTIFIER)
.limit(1);
if let Some(public_key) = current_user {
// Push author to the filter
filter = filter.author(public_key);
// If the signer is available, get settings belonging to the current user
if let Some(signer) = client.signer() {
if let Ok(public_key) = signer.get_public_key().await {
// Push author to the filter
filter = filter.author(public_key);
}
}
if let Some(event) = client.database().query(filter).await?.first_owned() {
@@ -198,7 +200,7 @@ impl AppSettings {
pub fn load(&mut self, cx: &mut Context<Self>) {
let task = Self::get_from_database(cx);
self._tasks.push(
self.tasks.push(
// Run task in the background
cx.spawn(async move |this, cx| {
if let Ok(settings) = task.await {
@@ -216,10 +218,12 @@ impl AppSettings {
pub fn save(&mut self, cx: &mut Context<Self>) {
let nostr = NostrRegistry::global(cx);
let client = nostr.read(cx).client();
let public_key = nostr.read(cx).identity().read(cx).public_key();
if let Ok(content) = serde_json::to_string(&self.values) {
let task: Task<Result<(), Error>> = cx.background_spawn(async move {
let signer = client.signer().context("Signer not found")?;
let public_key = signer.get_public_key().await?;
let event = EventBuilder::new(Kind::ApplicationSpecificData, content)
.tag(Tag::identifier(SETTINGS_IDENTIFIER))
.build(public_key)