feat: setup packager and auto-updater

This commit is contained in:
2025-02-11 09:13:08 +07:00
parent 1bb9729e75
commit f5f9b66df5
16 changed files with 76 additions and 67 deletions

1
.gitignore vendored
View File

@@ -2,6 +2,7 @@
# will have compiled files and executables
debug/
target/
dist/
# These are backup files generated by rustfmt
**/*.rs.bk

54
Cargo.lock generated
View File

@@ -693,9 +693,9 @@ dependencies = [
[[package]]
name = "built"
version = "0.7.5"
version = "0.7.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c360505aed52b7ec96a3636c3f039d99103c37d1d9b4f7a8c743d3ea9ffcd03b"
checksum = "73848a43c5d63a1251d17adf6c2bf78aa94830e60a335a95eeea45d6ba9e1e4d"
[[package]]
name = "bumpalo"
@@ -1063,7 +1063,7 @@ dependencies = [
[[package]]
name = "collections"
version = "0.1.0"
source = "git+https://github.com/zed-industries/zed#4207b194e35e87edc56a8d045aa5711b29ab8859"
source = "git+https://github.com/zed-industries/zed#c1f162abc6cb41a0c765aa76c3af3e83a994ce18"
dependencies = [
"indexmap",
"rustc-hash 2.1.1",
@@ -1345,9 +1345,9 @@ dependencies = [
[[package]]
name = "data-encoding"
version = "2.7.0"
version = "2.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0e60eed09d8c01d3cee5b7d30acb059b76614c918fa0f992e0dd6eeb10daad6f"
checksum = "575f75dfd25738df5b91b8e43e14d44bda14637a58fae779fd2b064f8bf3e010"
[[package]]
name = "data-url"
@@ -1380,7 +1380,7 @@ dependencies = [
[[package]]
name = "derive_refineable"
version = "0.1.0"
source = "git+https://github.com/zed-industries/zed#4207b194e35e87edc56a8d045aa5711b29ab8859"
source = "git+https://github.com/zed-industries/zed#c1f162abc6cb41a0c765aa76c3af3e83a994ce18"
dependencies = [
"proc-macro2",
"quote",
@@ -2105,7 +2105,7 @@ dependencies = [
[[package]]
name = "gpui"
version = "0.1.0"
source = "git+https://github.com/zed-industries/zed#4207b194e35e87edc56a8d045aa5711b29ab8859"
source = "git+https://github.com/zed-industries/zed#c1f162abc6cb41a0c765aa76c3af3e83a994ce18"
dependencies = [
"anyhow",
"as-raw-xcb-connection",
@@ -2192,7 +2192,7 @@ dependencies = [
[[package]]
name = "gpui_macros"
version = "0.1.0"
source = "git+https://github.com/zed-industries/zed#4207b194e35e87edc56a8d045aa5711b29ab8859"
source = "git+https://github.com/zed-industries/zed#c1f162abc6cb41a0c765aa76c3af3e83a994ce18"
dependencies = [
"proc-macro2",
"quote",
@@ -2202,7 +2202,7 @@ dependencies = [
[[package]]
name = "gpui_tokio"
version = "0.1.0"
source = "git+https://github.com/zed-industries/zed#4207b194e35e87edc56a8d045aa5711b29ab8859"
source = "git+https://github.com/zed-industries/zed#c1f162abc6cb41a0c765aa76c3af3e83a994ce18"
dependencies = [
"gpui",
"tokio",
@@ -2416,7 +2416,7 @@ dependencies = [
[[package]]
name = "http_client"
version = "0.1.0"
source = "git+https://github.com/zed-industries/zed#4207b194e35e87edc56a8d045aa5711b29ab8859"
source = "git+https://github.com/zed-industries/zed#c1f162abc6cb41a0c765aa76c3af3e83a994ce18"
dependencies = [
"anyhow",
"bytes",
@@ -3074,7 +3074,7 @@ dependencies = [
[[package]]
name = "media"
version = "0.1.0"
source = "git+https://github.com/zed-industries/zed#4207b194e35e87edc56a8d045aa5711b29ab8859"
source = "git+https://github.com/zed-industries/zed#c1f162abc6cb41a0c765aa76c3af3e83a994ce18"
dependencies = [
"anyhow",
"bindgen",
@@ -3259,7 +3259,7 @@ checksum = "0676bb32a98c1a483ce53e500a81ad9c3d5b3f7c920c28c24e9cb0980d0b5bc8"
[[package]]
name = "nostr"
version = "0.39.0"
source = "git+https://github.com/rust-nostr/nostr#6e790f0fdb5a11a463ace78e37c31c4818fe4199"
source = "git+https://github.com/rust-nostr/nostr#6caf231eca951f2c6909382c46f43edffbd6e730"
dependencies = [
"aes",
"base64",
@@ -3287,7 +3287,7 @@ dependencies = [
[[package]]
name = "nostr-connect"
version = "0.39.0"
source = "git+https://github.com/rust-nostr/nostr#6e790f0fdb5a11a463ace78e37c31c4818fe4199"
source = "git+https://github.com/rust-nostr/nostr#6caf231eca951f2c6909382c46f43edffbd6e730"
dependencies = [
"async-utility",
"nostr",
@@ -3299,7 +3299,7 @@ dependencies = [
[[package]]
name = "nostr-database"
version = "0.39.0"
source = "git+https://github.com/rust-nostr/nostr#6e790f0fdb5a11a463ace78e37c31c4818fe4199"
source = "git+https://github.com/rust-nostr/nostr#6caf231eca951f2c6909382c46f43edffbd6e730"
dependencies = [
"flatbuffers",
"lru",
@@ -3310,18 +3310,20 @@ dependencies = [
[[package]]
name = "nostr-lmdb"
version = "0.39.0"
source = "git+https://github.com/rust-nostr/nostr#6e790f0fdb5a11a463ace78e37c31c4818fe4199"
source = "git+https://github.com/rust-nostr/nostr#6caf231eca951f2c6909382c46f43edffbd6e730"
dependencies = [
"async-utility",
"heed",
"nostr",
"nostr-database",
"tokio",
"tracing",
]
[[package]]
name = "nostr-relay-pool"
version = "0.39.0"
source = "git+https://github.com/rust-nostr/nostr#6e790f0fdb5a11a463ace78e37c31c4818fe4199"
source = "git+https://github.com/rust-nostr/nostr#6caf231eca951f2c6909382c46f43edffbd6e730"
dependencies = [
"async-utility",
"async-wsocket",
@@ -3338,7 +3340,7 @@ dependencies = [
[[package]]
name = "nostr-sdk"
version = "0.39.0"
source = "git+https://github.com/rust-nostr/nostr#6e790f0fdb5a11a463ace78e37c31c4818fe4199"
source = "git+https://github.com/rust-nostr/nostr#6caf231eca951f2c6909382c46f43edffbd6e730"
dependencies = [
"async-utility",
"nostr",
@@ -4375,7 +4377,7 @@ dependencies = [
[[package]]
name = "refineable"
version = "0.1.0"
source = "git+https://github.com/zed-industries/zed#4207b194e35e87edc56a8d045aa5711b29ab8859"
source = "git+https://github.com/zed-industries/zed#c1f162abc6cb41a0c765aa76c3af3e83a994ce18"
dependencies = [
"derive_refineable",
]
@@ -4508,7 +4510,7 @@ dependencies = [
[[package]]
name = "reqwest_client"
version = "0.1.0"
source = "git+https://github.com/zed-industries/zed#4207b194e35e87edc56a8d045aa5711b29ab8859"
source = "git+https://github.com/zed-industries/zed#c1f162abc6cb41a0c765aa76c3af3e83a994ce18"
dependencies = [
"anyhow",
"bytes",
@@ -4858,7 +4860,7 @@ checksum = "c2fdfc24bc566f839a2da4c4295b82db7d25a24253867d5c64355abb5799bdbe"
[[package]]
name = "semantic_version"
version = "0.1.0"
source = "git+https://github.com/zed-industries/zed#4207b194e35e87edc56a8d045aa5711b29ab8859"
source = "git+https://github.com/zed-industries/zed#c1f162abc6cb41a0c765aa76c3af3e83a994ce18"
dependencies = [
"anyhow",
"serde",
@@ -5183,7 +5185,7 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292"
[[package]]
name = "sum_tree"
version = "0.1.0"
source = "git+https://github.com/zed-industries/zed#4207b194e35e87edc56a8d045aa5711b29ab8859"
source = "git+https://github.com/zed-industries/zed#c1f162abc6cb41a0c765aa76c3af3e83a994ce18"
dependencies = [
"arrayvec",
"log",
@@ -5725,9 +5727,9 @@ dependencies = [
[[package]]
name = "toml_edit"
version = "0.22.23"
version = "0.22.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "02a8b472d1a3d7c18e2d61a489aee3453fd9031c33e4f55bd533f4a7adca1bee"
checksum = "17b4795ff5edd201c7cd6dca065ae59972ce77d1b80fa0a84d94950ece7d1474"
dependencies = [
"indexmap",
"serde",
@@ -6053,7 +6055,7 @@ checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
[[package]]
name = "util"
version = "0.1.0"
source = "git+https://github.com/zed-industries/zed#4207b194e35e87edc56a8d045aa5711b29ab8859"
source = "git+https://github.com/zed-industries/zed#c1f162abc6cb41a0c765aa76c3af3e83a994ce18"
dependencies = [
"anyhow",
"async-fs",
@@ -6681,9 +6683,9 @@ checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
[[package]]
name = "winnow"
version = "0.7.1"
version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "86e376c75f4f43f44db463cf729e0d3acbf954d13e22c51e26e4c264b4ab545f"
checksum = "59690dea168f2198d1a3b0cac23b8063efcd11012f10ae4698f284808c8ef603"
dependencies = [
"memchr",
]

View File

@@ -37,6 +37,8 @@ log = "0.4"
before-packaging-command = "cargo build --release"
product-name = "Coop"
identifier = "su.reya.coop"
version = "0.1.0"
out-dir = "../../dist"
resources = ["src", "icons/*", "Cargo.toml", "../../README.md"]
icons = [
"icons/32x32.png",

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

BIN
crates/app/icons/32x32.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

BIN
crates/app/icons/icon.icns Normal file

Binary file not shown.

BIN
crates/app/icons/icon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

BIN
crates/app/icons/icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 70 KiB

View File

@@ -1,9 +1,14 @@
use cargo_packager_updater::{check_update, semver::Version, url::Url};
use chat_state::registry::ChatRegistry;
use common::profile::NostrProfile;
use common::{
constants::{UPDATER_PUBKEY, UPDATER_URL},
profile::NostrProfile,
};
use gpui::{
actions, div, img, impl_internal_actions, px, App, AppContext, Axis, Context, Entity,
InteractiveElement, IntoElement, ObjectFit, ParentElement, Render, Styled, StyledImage, Window,
};
use log::info;
use nostr_sdk::prelude::*;
use serde::Deserialize;
use state::get_client;
@@ -56,9 +61,14 @@ pub struct AppView {
impl AppView {
pub fn new(account: NostrProfile, window: &mut Window, cx: &mut App) -> Entity<Self> {
// Initialize dock layout
let dock = cx.new(|cx| DockArea::new(window, cx));
let weak_dock = dock.downgrade();
// Initialize left dock
let left_panel = DockItem::panel(Arc::new(sidebar::init(window, cx)));
// Initial central dock
let center_panel = DockItem::split_with_sizes(
Axis::Vertical,
vec![DockItem::tabs(
@@ -74,7 +84,7 @@ impl AppView {
cx,
);
// Set default dock layout
// Set default dock layout with left and central docks
_ = weak_dock.update(cx, |view, cx| {
view.set_left_dock(left_panel, Some(px(240.)), true, window, cx);
view.set_center(center_panel, window, cx);
@@ -83,7 +93,27 @@ impl AppView {
let public_key = account.public_key();
let window_handle = window.window_handle();
// Check user's inbox relays and determine user is ready for NIP17 or not.
// Check and auto update to the latest version
cx.background_spawn(async move {
// Set auto updater config
let config = cargo_packager_updater::Config {
endpoints: vec![Url::parse(UPDATER_URL).expect("Failed to parse UPDATER URL")],
pubkey: String::from(UPDATER_PUBKEY),
..Default::default()
};
// Run auto updater
if let Ok(current_version) = Version::parse(env!("CARGO_PKG_VERSION")) {
if let Ok(Some(update)) = check_update(current_version, config) {
if update.download_and_install().is_ok() {
info!("Update installed")
}
}
}
})
.detach();
// Check user's messaging relays and determine user is ready for NIP17 or not.
// If not, show the setup modal and instruct user setup inbox relays
cx.spawn(|mut cx| async move {
let (tx, rx) = oneshot::channel::<bool>();
@@ -118,7 +148,7 @@ impl AppView {
this.keyboard(false)
.closable(false)
.width(px(420.))
.title("Your Inbox is not configured")
.title("Your Messaging Relays is not configured")
.child(relays.clone())
.footer(
div()

View File

@@ -136,7 +136,7 @@ impl Relays {
impl Render for Relays {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let msg = "In order to receive messages from others, you need to setup Inbox Relays. You can use the recommend relays or add more.";
let msg = "In order to receive messages from others, you need to setup Messaging Relays. You can use the recommend relays or add more.";
div()
.track_focus(&self.focus_handle)

View File

@@ -155,16 +155,14 @@ impl ChatRegistry {
let this = room.downgrade();
cx.spawn(|mut cx| async move {
if let Err(e) = cx.update_window(window_handle, |_, _, cx| {
_ = cx.update_window(window_handle, |_, _, cx| {
_ = this.update(cx, |this, cx| {
this.last_seen.set(event.created_at);
this.new_messages.push(event);
cx.notify();
});
}) {
println!("Error: {}", e)
}
});
})
.detach();
} else {

View File

@@ -13,3 +13,9 @@ pub const IMAGE_SERVICE: &str = "https://wsrv.nl";
/// NIP96 Media Server
pub const NIP96_SERVER: &str = "https://nostrmedia.com";
/// Updater Public Key
pub const UPDATER_PUBKEY: &str = "dW50cnVzdGVkIGNvbW1lbnQ6IG1pbmlzaWduIHB1YmxpYyBrZXk6IDkxM0EzQTQyRTBBMENENTYKUldSV3phRGdRam82a1dtU0JqYll4VnBaVUpSWUxCWlVQbnRkUnNERS96MzFMWDhqNW5zOXplMEwK";
/// Updater Server URL
pub const UPDATER_URL: &str =
"https://cdn.crabnebula.app/update/lume/coop/{{target}}-{{arch}}/{{current_version}}";

View File

@@ -256,8 +256,6 @@ impl StackPanel {
cx.emit(PanelEvent::LayoutChanged);
self.remove_self_if_empty(window, cx);
} else {
println!("Panel not found in stack panel.");
}
}

View File

@@ -299,31 +299,6 @@ impl IntoElement for TextElement {
}
}
/// A debug function to print points as SVG path.
#[allow(unused)]
fn print_points_as_svg_path(line_corners: &Vec<Corners<Point<Pixels>>>, points: &[Point<Pixels>]) {
for corners in line_corners {
println!(
"tl: ({}, {}), tr: ({}, {}), bl: ({}, {}), br: ({}, {})",
corners.top_left.x.0 as i32,
corners.top_left.y.0 as i32,
corners.top_right.x.0 as i32,
corners.top_right.y.0 as i32,
corners.bottom_left.x.0 as i32,
corners.bottom_left.y.0 as i32,
corners.bottom_right.x.0 as i32,
corners.bottom_right.y.0 as i32,
);
}
if !points.is_empty() {
println!("M{},{}", points[0].x.0 as i32, points[0].y.0 as i32);
for p in points.iter().skip(1) {
println!("L{},{}", p.x.0 as i32, p.y.0 as i32);
}
}
}
impl Element for TextElement {
type RequestLayoutState = ();
type PrepaintState = PrepaintState;

View File

@@ -340,12 +340,9 @@ impl NotificationList {
// Sleep for 3 seconds to autohide the notification
cx.spawn_in(window, |_, mut cx| async move {
Timer::after(Duration::from_secs(3)).await;
if let Err(err) = notification.update_in(&mut cx, |note, window, cx| {
_ = notification.update_in(&mut cx, |note, window, cx| {
note.dismiss(&ClickEvent::default(), window, cx)
}) {
println!("failed to auto hide notification: {:?}", err);
}
});
})
.detach();
}