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

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();
}