use instant

This commit is contained in:
2026-07-28 16:39:09 +07:00
parent 5ddae637f6
commit 0faa8694f8
38 changed files with 72 additions and 71 deletions

17
Cargo.lock generated
View File

@@ -542,6 +542,7 @@ dependencies = [
"anyhow",
"common",
"gpui",
"instant",
"log",
"semver",
"serde",
@@ -1058,6 +1059,7 @@ dependencies = [
"futures",
"fuzzy-matcher",
"gpui",
"instant",
"itertools 0.13.0",
"log",
"nostr-sdk",
@@ -1259,6 +1261,7 @@ dependencies = [
"dirs 5.0.1",
"futures",
"gpui",
"instant",
"itertools 0.13.0",
"log",
"nostr",
@@ -1725,6 +1728,7 @@ dependencies = [
"common",
"flume 0.11.1",
"gpui",
"instant",
"log",
"nostr-sdk",
"person",
@@ -3491,6 +3495,15 @@ dependencies = [
"hybrid-array",
]
[[package]]
name = "instant"
version = "0.1.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e0242819d153cba4b4b05a5a8f2a7e9bbf97b6055b2a002b395c96b5ff3c0222"
dependencies = [
"cfg-if",
]
[[package]]
name = "interpolate_name"
version = "0.2.4"
@@ -4919,6 +4932,7 @@ dependencies = [
"common",
"flume 0.11.1",
"gpui",
"instant",
"log",
"nostr-sdk",
"smallvec",
@@ -6663,6 +6677,7 @@ dependencies = [
"futures",
"gpui",
"gpui_tokio",
"instant",
"log",
"mime_guess",
"nostr",
@@ -7551,6 +7566,7 @@ dependencies = [
"anyhow",
"common",
"gpui",
"instant",
"itertools 0.13.0",
"log",
"lsp-types",
@@ -8993,6 +9009,7 @@ dependencies = [
"common",
"device",
"gpui",
"instant",
"log",
"nostr-connect",
"nostr-sdk",

View File

@@ -44,6 +44,7 @@ smol = "2"
webbrowser = "1.0.4"
tracing-subscriber = { version = "0.3.18", features = ["fmt", "env-filter"] }
errno = { version = "0.3.14", default-features = false }
instant = "0.1"
[patch.crates-io]
# Use stacker's psm version which may have better WASM support

View File

@@ -8,6 +8,7 @@ publish.workspace = true
common = { path = "../common" }
gpui.workspace = true
instant.workspace = true
anyhow.workspace = true
log.workspace = true
smallvec.workspace = true

View File

@@ -3,7 +3,6 @@
use std::ffi::OsString;
use std::path::{Path, PathBuf};
use std::sync::Arc;
use std::time::Duration;
use anyhow::{Context as AnyhowContext, Error, anyhow};
use gpui::http_client::{AsyncBody, HttpClient};
@@ -11,6 +10,7 @@ use gpui::{
App, AppContext, AsyncApp, BackgroundExecutor, Context, Entity, Global, Subscription, Task,
Window,
};
use instant::Duration;
use semver::Version;
use serde::Deserialize;
use smallvec::{SmallVec, smallvec};

View File

@@ -13,6 +13,7 @@ settings = { path = "../settings" }
gpui.workspace = true
nostr-sdk.workspace = true
instant.workspace = true
anyhow.workspace = true
itertools.workspace = true

View File

@@ -2,7 +2,7 @@ use std::cmp::Reverse;
use std::collections::{BTreeSet, HashMap, HashSet};
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::{Arc, LazyLock, RwLock};
use std::time::Duration;
use instant::Duration;
use anyhow::{Error, anyhow};
use common::EventExt;

View File

@@ -1,6 +1,6 @@
use std::cmp::Ordering;
use std::hash::{Hash, Hasher};
use std::time::Duration;
use instant::Duration;
use anyhow::{Error, anyhow};
use common::EventExt;

View File

@@ -7,6 +7,7 @@ publish.workspace = true
[dependencies]
gpui.workspace = true
nostr.workspace = true
instant.workspace = true
nostr-sdk.workspace = true
itertools.workspace = true

View File

@@ -1,5 +1,5 @@
use std::marker::PhantomData;
use std::time::Duration;
use instant::Duration;
use futures::channel::oneshot;
use futures::FutureExt;

View File

@@ -14,6 +14,7 @@ settings = { path = "../settings" }
gpui.workspace = true
nostr-sdk.workspace = true
instant.workspace = true
anyhow.workspace = true
smallvec.workspace = true
log.workspace = true

View File

@@ -4,7 +4,7 @@ use std::path::PathBuf;
use std::rc::Rc;
use std::sync::Arc;
use std::sync::atomic::{AtomicBool, Ordering};
use std::time::Duration;
use instant::Duration;
use anyhow::{Context as AnyhowContext, Error, anyhow};
use gpui::{

View File

@@ -10,6 +10,7 @@ state = { path = "../state" }
gpui.workspace = true
nostr-sdk.workspace = true
instant.workspace = true
anyhow.workspace = true
smallvec.workspace = true
flume.workspace = true

View File

@@ -1,6 +1,6 @@
use std::collections::{HashMap, HashSet};
use std::sync::RwLock;
use std::time::Duration;
use instant::Duration;
use anyhow::{Error, anyhow};
use common::EventExt;

View File

@@ -14,6 +14,7 @@ nostr-blossom.workspace = true
nostr-connect.workspace = true
gpui.workspace = true
instant.workspace = true
flume.workspace = true
futures.workspace = true
log.workspace = true

View File

@@ -1,5 +1,5 @@
use std::collections::HashMap;
use std::time::Duration;
use instant::Duration;
use anyhow::{Error, anyhow};
use common::config_dir;

View File

@@ -9,6 +9,7 @@ common = { path = "../common" }
theme = { path = "../theme" }
gpui.workspace = true
instant.workspace = true
serde.workspace = true
smallvec.workspace = true
anyhow.workspace = true

View File

@@ -1,5 +1,5 @@
use std::rc::Rc;
use std::time::Duration;
use instant::Duration;
use gpui::prelude::FluentBuilder as _;
use gpui::{

View File

@@ -1,5 +1,5 @@
use std::fmt::Debug;
use std::time::{Duration, Instant};
use instant::{Duration, Instant};
/// A HistoryItem represents a single change in the history.
/// It must implement Clone and PartialEq to be used in the History.

View File

@@ -1,4 +1,4 @@
use std::time::Duration;
use instant::Duration;
use gpui::prelude::FluentBuilder as _;
use gpui::{

View File

@@ -1,4 +1,4 @@
use std::time::Duration;
use instant::Duration;
use gpui::{Context, Pixels, Task, px};

View File

@@ -383,7 +383,7 @@ impl InputState {
pub fn new(window: &mut Window, cx: &mut Context<Self>) -> Self {
let focus_handle = cx.focus_handle().tab_stop(true);
let blink_cursor = cx.new(|_| BlinkCursor::new());
let history = History::new().group_interval(std::time::Duration::from_secs(1));
let history = History::new().group_interval(instant::Duration::from_secs(1));
let _subscriptions = vec![
// Observe the blink cursor to repaint the view when it changes.

View File

@@ -1,5 +1,4 @@
use std::ops::Range;
use std::time::Duration;
use gpui::prelude::FluentBuilder;
use gpui::{
@@ -9,6 +8,7 @@ use gpui::{
SharedString, StatefulInteractiveElement, StyleRefinement, Styled, Subscription, Task,
UniformListScrollHandle, Window, div, px, size, uniform_list,
};
use instant::Duration;
use theme::ActiveTheme;
use crate::actions::{Cancel, Confirm, SelectDown, SelectUp};

View File

@@ -1,5 +1,5 @@
use std::rc::Rc;
use std::time::Duration;
use instant::Duration;
use gpui::prelude::FluentBuilder;
use gpui::{

View File

@@ -1,7 +1,7 @@
use std::any::TypeId;
use std::collections::{HashMap, VecDeque};
use std::rc::Rc;
use std::time::Duration;
use instant::Duration;
use gpui::prelude::FluentBuilder;
use gpui::{

View File

@@ -2,7 +2,6 @@ use std::cell::Cell;
use std::ops::Deref;
use std::panic::Location;
use std::rc::Rc;
use std::time::{Duration, Instant};
use gpui::{
Anchor, App, Axis, BorderStyle, Bounds, ContentMask, CursorStyle, Edges, Element, ElementId,
@@ -11,6 +10,7 @@ use gpui::{
Position, ScrollHandle, ScrollWheelEvent, Size, Style, UniformListScrollHandle, Window, fill,
point, px, relative, size,
};
use instant::{Duration, Instant};
use theme::{ActiveTheme, AxisExt, ScrollbarMode};
/// The width of the scrollbar (THUMB_ACTIVE_INSET * 2 + THUMB_ACTIVE_WIDTH)
@@ -157,7 +157,7 @@ impl ScrollbarStateInner {
let mut state = *self;
state.hovered_axis = axis;
if axis.is_some() {
state.last_scroll_time = Some(std::time::Instant::now());
state.last_scroll_time = Some(instant::Instant::now());
}
state
}
@@ -166,7 +166,7 @@ impl ScrollbarStateInner {
let mut state = *self;
state.hovered_on_thumb = axis;
if self.is_scrollbar_visible() && axis.is_some() {
state.last_scroll_time = Some(std::time::Instant::now());
state.last_scroll_time = Some(instant::Instant::now());
}
state
}

View File

@@ -1,4 +1,4 @@
use std::time::Duration;
use instant::Duration;
use gpui::{
bounce, div, ease_in_out, Animation, AnimationExt, IntoElement, RenderOnce, StyleRefinement,

View File

@@ -1,6 +1,6 @@
use std::cell::RefCell;
use std::rc::Rc;
use std::time::Duration;
use instant::Duration;
use gpui::prelude::FluentBuilder as _;
use gpui::{

View File

@@ -17,6 +17,7 @@ person = { path = "../person" }
gpui.workspace = true
nostr-sdk.workspace = true
instant.workspace = true
nostr-connect.workspace = true
anyhow.workspace = true

View File

@@ -1,4 +1,4 @@
use std::time::Duration;
use instant::Duration;
use anyhow::{Error, anyhow};
use gpui::prelude::FluentBuilder;

View File

@@ -1,4 +1,4 @@
use std::time::Duration;
use instant::Duration;
use anyhow::Error;
use device::DeviceRegistry;

View File

@@ -1,5 +1,4 @@
use std::collections::HashMap;
use std::time::Duration;
use anyhow::Error;
use common::TimestampExt;
@@ -8,6 +7,7 @@ use gpui::{
App, AppContext, Context, Div, Entity, InteractiveElement, IntoElement, ParentElement, Render,
SharedString, Styled, Subscription, Task, Window, div, px, relative, uniform_list,
};
use instant::Duration;
use nostr_sdk::prelude::*;
use person::{Person, PersonRegistry, shorten_pubkey};
use smallvec::{SmallVec, smallvec};

View File

@@ -79,20 +79,16 @@ impl Workspace {
let device = DeviceRegistry::global(cx);
let nostr = NostrRegistry::global(cx);
let dock = cx.new(|cx| DockArea::new(window, cx));
let dock = cx.new(|cx| {
let mut this = DockArea::new(window, cx);
let left = DockItem::panel(Arc::new(sidebar::init(window, cx)));
this.set_left_dock(left, Some(SIDEBAR_WIDTH), true, window, cx);
this
});
let image_cache = CoopImageCache::new(IMAGE_CACHE_SIZE, cx);
let mut subscriptions = smallvec![];
subscriptions.push(
// Observe sign in state changes
cx.observe_in(&nostr, window, move |this, nostr, window, cx| {
if nostr.read(cx).current_user().is_some() {
this.set_center_layout(window, cx);
}
}),
);
subscriptions.push(
// Observe system appearance and update theme
cx.observe_window_appearance(window, |_this, window, cx| {
@@ -105,11 +101,7 @@ impl Workspace {
cx.subscribe_in(&nostr, window, move |this, _state, event, window, cx| {
match event {
StateEvent::SignerChanged => {
this.set_center_layout(window, cx);
cx.defer_in(window, |_this, window, cx| {
window.close_all_modals(cx);
});
window.close_all_modals(cx);
}
StateEvent::NoSigner => {
this.import_identity(window, cx);
@@ -241,9 +233,15 @@ impl Workspace {
}),
);
// Set the layout at the end of cycle
cx.defer_in(window, |this, window, cx| {
this.set_layout(window, cx);
let dock = this.dock.downgrade();
let greeter = Arc::new(greeter::init(window, cx));
let tabs = DockItem::tabs(vec![greeter], None, &dock, window, cx);
let center = DockItem::split(Axis::Vertical, vec![tabs], &dock, window, cx);
this.dock.update(cx, |this, cx| {
this.set_center(center, window, cx);
});
});
Self {
@@ -281,29 +279,6 @@ impl Workspace {
.collect()
}
/// Set the dock layout
fn set_layout(&mut self, window: &mut Window, cx: &mut Context<Self>) {
let left = DockItem::panel(Arc::new(sidebar::init(window, cx)));
// Update the dock layout with sidebar on the left
self.dock.update(cx, |this, cx| {
this.set_left_dock(left, Some(SIDEBAR_WIDTH), true, window, cx);
});
}
/// Set the center dock layout
fn set_center_layout(&mut self, window: &mut Window, cx: &mut Context<Self>) {
let dock = self.dock.downgrade();
let greeter = Arc::new(greeter::init(window, cx));
let tabs = DockItem::tabs(vec![greeter], None, &dock, window, cx);
let center = DockItem::split(Axis::Vertical, vec![tabs], &dock, window, cx);
// Update the layout with center dock
self.dock.update(cx, |this, cx| {
this.set_center(center, window, cx);
});
}
/// Handle command events
fn on_command(&mut self, command: &Command, window: &mut Window, cx: &mut Context<Self>) {
match command {
@@ -834,7 +809,7 @@ impl Render for Workspace {
let notification_layer = Root::render_notification_layer(window, cx);
div()
.id(SharedString::from("workspace"))
.id("workspace")
.on_action(cx.listener(Self::on_command))
.relative()
.size_full()

View File

@@ -1,4 +1,4 @@
use std::time::Duration;
use instant::Duration;
use anyhow::Error;
use gpui::{

View File

@@ -1,5 +1,5 @@
use std::collections::HashSet;
use std::time::Duration;
use instant::Duration;
use anyhow::Error;
use gpui::prelude::FluentBuilder;

View File

@@ -1,5 +1,5 @@
use std::collections::HashSet;
use std::time::Duration;
use instant::Duration;
use anyhow::{Error, anyhow};
use gpui::prelude::FluentBuilder;

View File

@@ -1,5 +1,4 @@
use std::str::FromStr;
use std::time::Duration;
use anyhow::{Context as AnyhowContext, Error};
use gpui::{
@@ -7,6 +6,7 @@ use gpui::{
Focusable, IntoElement, ParentElement, PathPromptOptions, Render, SharedString, Styled, Task,
Window, div,
};
use instant::Duration;
use nostr_sdk::prelude::*;
use person::{Person, PersonRegistry, shorten_pubkey};
use settings::AppSettings;

View File

@@ -1,5 +1,5 @@
use std::collections::HashSet;
use std::time::Duration;
use instant::Duration;
use anyhow::{Error, anyhow};
use gpui::prelude::FluentBuilder;

View File

@@ -1,6 +1,6 @@
use std::collections::HashSet;
use std::ops::Range;
use std::time::Duration;
use instant::Duration;
use anyhow::Error;
use chat::{ChatEvent, ChatRegistry, Room, RoomKind};