chore: small fixes

This commit is contained in:
2025-03-12 16:44:44 +07:00
parent 8156d9d046
commit 0a7f0475a4
8 changed files with 217 additions and 81 deletions

View File

@@ -39,7 +39,6 @@ pub enum DeviceState {
impl DeviceState {
pub fn subscribe(&self, window: &mut Window, cx: &mut Context<Self>) {
log::info!("Device State: {:?}", self);
match self {
Self::Master => {
let client = get_client();
@@ -156,25 +155,7 @@ pub fn init(window: &mut Window, cx: &App) {
cx.update(|cx| {
let state = cx.new(|_| DeviceState::None);
window_handle
.update(cx, |_, window, cx| {
// Open the onboarding view
Root::update(window, cx, |this, window, cx| {
this.replace_view(onboarding::init(window, cx).into());
cx.notify();
});
window
.observe(&state, cx, |this, window, cx| {
this.update(cx, |this, cx| {
this.subscribe(window, cx);
});
})
.detach();
})
.ok();
let weak_state = state.downgrade();
let requesters = cx.new(|_| HashSet::new());
let entity = cx.new(|_| Device {
profile: None,
@@ -192,6 +173,18 @@ pub fn init(window: &mut Window, cx: &App) {
cx.notify();
});
// Observe the DeviceState changes
if let Some(state) = weak_state.upgrade() {
window
.observe(&state, cx, |this, window, cx| {
this.update(cx, |this, cx| {
this.subscribe(window, cx);
});
})
.detach();
};
// Observe the Device changes
window
.observe(&entity, cx, |this, window, cx| {
this.update(cx, |this, cx| {

View File

@@ -24,12 +24,12 @@ use nostr_sdk::{
};
use smol::Timer;
use std::{collections::HashSet, mem, sync::Arc, time::Duration};
use ui::Root;
use ui::{theme::Theme, Root};
use views::startup;
mod asset;
mod device;
mod views;
pub(crate) mod asset;
pub(crate) mod device;
pub(crate) mod views;
actions!(coop, [Quit]);
@@ -245,6 +245,13 @@ fn main() {
// Open a window with default options
cx.open_window(opts, |window, cx| {
// Automatically sync theme with system appearance
window
.observe_window_appearance(|window, cx| {
Theme::sync_system_appearance(Some(window), cx);
})
.detach();
// Initialize components
ui::init(cx);

View File

@@ -71,7 +71,7 @@ impl Relays {
if let Ok(relays) = task.await {
_ = cx.update(|cx| {
_ = this.update(cx, |this: &mut Vec<RelayUrl>, cx| {
this.extend(relays);
*this = relays;
cx.notify();
});
});