notedeck

One damus client to rule them all
git clone git://jb55.com/notedeck
Log | Files | Refs | README | LICENSE

commit 74c5f0c748026d4b5f5cd5f2a76439fc5be5bc0d
parent 10cbdf15f068df71bb11deaf8a1d0a1b32b0a94b
Author: William Casarin <jb55@jb55.com>
Date:   Wed, 11 Dec 2024 02:53:05 -0800

split notedeck into crates

This splits notedeck into crates, separating the browser chrome and
individual apps:

* notedeck: binary file, browser chrome
* notedeck_columns: our columns app
* enostr: same as before

We still need to do more work to cleanly separate the chrome apis
from the app apis. Soon I will create notedeck-notebook to see what
makes sense to be shared between the apps.

Some obvious ones that come to mind:

1. ImageCache

We will likely want to move this to the notedeck crate, as most apps
will want some kind of image cache. In web browsers, web pages do not
need to worry about this, so we will likely have to do something similar

2. Ndb

Since NdbRef is threadsafe and Ndb is an Arc<NdbRef>, it can be safely
copied to each app. This will simplify things. In the future we might
want to create an abstraction over this? Maybe each app shouldn't have
access to the same database... we assume the data in DBs are all public
anyways, but if we have unwrapped giftwraps that could be a problem.

3. RelayPool / Subscription Manager

The browser should probably maintain these. Then apps can use ken's
high level subscription manager api and not have to worry about
connection pool details

4. Accounts

Accounts and key management should be handled by the chrome. Apps should
only have a simple signer interface.

That's all for now, just something to think about!

Signed-off-by: William Casarin <jb55@jb55.com>

Diffstat:
MCargo.lock | 132+++++++++----------------------------------------------------------------------
MCargo.toml | 147++++++++++++++++++-------------------------------------------------------------
Renostr/Cargo.lock -> crates/enostr/Cargo.lock | 0
Acrates/enostr/Cargo.toml | 17+++++++++++++++++
Renostr/src/client/message.rs -> crates/enostr/src/client/message.rs | 0
Renostr/src/client/mod.rs -> crates/enostr/src/client/mod.rs | 0
Renostr/src/error.rs -> crates/enostr/src/error.rs | 0
Renostr/src/filter.rs -> crates/enostr/src/filter.rs | 0
Renostr/src/keypair.rs -> crates/enostr/src/keypair.rs | 0
Renostr/src/lib.rs -> crates/enostr/src/lib.rs | 0
Renostr/src/note.rs -> crates/enostr/src/note.rs | 0
Renostr/src/profile.rs -> crates/enostr/src/profile.rs | 0
Renostr/src/pubkey.rs -> crates/enostr/src/pubkey.rs | 0
Acrates/enostr/src/relay/message.rs | 281+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Renostr/src/relay/mod.rs -> crates/enostr/src/relay/mod.rs | 0
Renostr/src/relay/pool.rs -> crates/enostr/src/relay/pool.rs | 0
Acrates/notedeck/Cargo.toml | 71+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Acrates/notedeck/src/notedeck.rs | 105+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Acrates/notedeck/src/preview.rs | 114+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Acrates/notedeck_columns/Cargo.toml | 58++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Rassets/Logo-Gradient-2x.png -> crates/notedeck_columns/assets/Logo-Gradient-2x.png | 0
Rassets/Welcome to Nostrdeck 2x.png -> crates/notedeck_columns/assets/Welcome to Nostrdeck 2x.png | 0
Rassets/app_icon.icns -> crates/notedeck_columns/assets/app_icon.icns | 0
Rassets/damus-app-icon.png -> crates/notedeck_columns/assets/damus-app-icon.png | 0
Rassets/damus-app-icon.svg -> crates/notedeck_columns/assets/damus-app-icon.svg | 0
Rassets/damus.ico -> crates/notedeck_columns/assets/damus.ico | 0
Rassets/damus.svg -> crates/notedeck_columns/assets/damus.svg | 0
Rassets/damus_rounded.svg -> crates/notedeck_columns/assets/damus_rounded.svg | 0
Rassets/damus_rounded_80.png -> crates/notedeck_columns/assets/damus_rounded_80.png | 0
Rassets/favicon.ico -> crates/notedeck_columns/assets/favicon.ico | 0
Rassets/fonts/DejaVuSans-Bold-SansEmoji.ttf -> crates/notedeck_columns/assets/fonts/DejaVuSans-Bold-SansEmoji.ttf | 0
Rassets/fonts/DejaVuSans-Bold.ttf -> crates/notedeck_columns/assets/fonts/DejaVuSans-Bold.ttf | 0
Rassets/fonts/DejaVuSans.ttf -> crates/notedeck_columns/assets/fonts/DejaVuSans.ttf | 0
Rassets/fonts/DejaVuSansSansEmoji.ttf -> crates/notedeck_columns/assets/fonts/DejaVuSansSansEmoji.ttf | 0
Rassets/fonts/Inconsolata-Regular.ttf -> crates/notedeck_columns/assets/fonts/Inconsolata-Regular.ttf | 0
Rassets/fonts/NotoEmoji-Regular.ttf -> crates/notedeck_columns/assets/fonts/NotoEmoji-Regular.ttf | 0
Rassets/fonts/NotoSansCJK-Regular.ttc -> crates/notedeck_columns/assets/fonts/NotoSansCJK-Regular.ttc | 0
Rassets/fonts/NotoSansThai-Regular.ttf -> crates/notedeck_columns/assets/fonts/NotoSansThai-Regular.ttf | 0
Rassets/fonts/ark/ark-pixel-10px-proportional-latin.ttf -> crates/notedeck_columns/assets/fonts/ark/ark-pixel-10px-proportional-latin.ttf | 0
Rassets/fonts/onest/OnestBlack1602-hint.ttf -> crates/notedeck_columns/assets/fonts/onest/OnestBlack1602-hint.ttf | 0
Rassets/fonts/onest/OnestBold1602-hint.ttf -> crates/notedeck_columns/assets/fonts/onest/OnestBold1602-hint.ttf | 0
Rassets/fonts/onest/OnestExtraBold1602-hint.ttf -> crates/notedeck_columns/assets/fonts/onest/OnestExtraBold1602-hint.ttf | 0
Rassets/fonts/onest/OnestLight1602-hint.ttf -> crates/notedeck_columns/assets/fonts/onest/OnestLight1602-hint.ttf | 0
Rassets/fonts/onest/OnestMedium1602-hint.ttf -> crates/notedeck_columns/assets/fonts/onest/OnestMedium1602-hint.ttf | 0
Rassets/fonts/onest/OnestRegular1602-hint.ttf -> crates/notedeck_columns/assets/fonts/onest/OnestRegular1602-hint.ttf | 0
Rassets/fonts/onest/OnestThin1602-hint.ttf -> crates/notedeck_columns/assets/fonts/onest/OnestThin1602-hint.ttf | 0
Rassets/fonts/pressstart/PressStart2P.ttf -> crates/notedeck_columns/assets/fonts/pressstart/PressStart2P.ttf | 0
Rassets/icons/add_account_icon_4x.png -> crates/notedeck_columns/assets/icons/add_account_icon_4x.png | 0
Rassets/icons/add_column_dark_4x.png -> crates/notedeck_columns/assets/icons/add_column_dark_4x.png | 0
Rassets/icons/add_column_light_4x.png -> crates/notedeck_columns/assets/icons/add_column_light_4x.png | 0
Rassets/icons/column_delete_icon_4x.png -> crates/notedeck_columns/assets/icons/column_delete_icon_4x.png | 0
Rassets/icons/column_delete_icon_light_4x.png -> crates/notedeck_columns/assets/icons/column_delete_icon_light_4x.png | 0
Rassets/icons/connected_icon_4x.png -> crates/notedeck_columns/assets/icons/connected_icon_4x.png | 0
Rassets/icons/connecting_icon_4x.png -> crates/notedeck_columns/assets/icons/connecting_icon_4x.png | 0
Rassets/icons/delete_icon_4x.png -> crates/notedeck_columns/assets/icons/delete_icon_4x.png | 0
Rassets/icons/disconnected_icon_4x.png -> crates/notedeck_columns/assets/icons/disconnected_icon_4x.png | 0
Rassets/icons/help_icon_dark_4x.png -> crates/notedeck_columns/assets/icons/help_icon_dark_4x.png | 0
Rassets/icons/help_icon_inverted_4x.png -> crates/notedeck_columns/assets/icons/help_icon_inverted_4x.png | 0
Rassets/icons/home_icon_dark_4x.png -> crates/notedeck_columns/assets/icons/home_icon_dark_4x.png | 0
Rassets/icons/new_deck_icon_4x_dark.png -> crates/notedeck_columns/assets/icons/new_deck_icon_4x_dark.png | 0
Rassets/icons/notifications_icon_dark_4x.png -> crates/notedeck_columns/assets/icons/notifications_icon_dark_4x.png | 0
Rassets/icons/plus_icon_4x.png -> crates/notedeck_columns/assets/icons/plus_icon_4x.png | 0
Rassets/icons/reply-dark.png -> crates/notedeck_columns/assets/icons/reply-dark.png | 0
Rassets/icons/reply.png -> crates/notedeck_columns/assets/icons/reply.png | 0
Rassets/icons/reply.svg -> crates/notedeck_columns/assets/icons/reply.svg | 0
Rassets/icons/repost_icon_4x.png -> crates/notedeck_columns/assets/icons/repost_icon_4x.png | 0
Rassets/icons/repost_light_4x.png -> crates/notedeck_columns/assets/icons/repost_light_4x.png | 0
Rassets/icons/select_icon_3x.png -> crates/notedeck_columns/assets/icons/select_icon_3x.png | 0
Rassets/icons/settings_dark_4x.png -> crates/notedeck_columns/assets/icons/settings_dark_4x.png | 0
Rassets/icons/settings_light_4x.png -> crates/notedeck_columns/assets/icons/settings_light_4x.png | 0
Rassets/icons/signout_icon_4x.png -> crates/notedeck_columns/assets/icons/signout_icon_4x.png | 0
Rassets/icons/universe_icon_dark_4x.png -> crates/notedeck_columns/assets/icons/universe_icon_dark_4x.png | 0
Rassets/manifest.json -> crates/notedeck_columns/assets/manifest.json | 0
Rassets/sw.js -> crates/notedeck_columns/assets/sw.js | 0
Rbuild.rs -> crates/notedeck_columns/build.rs | 0
Rsrc/abbrev.rs -> crates/notedeck_columns/src/abbrev.rs | 0
Rsrc/accounts/mod.rs -> crates/notedeck_columns/src/accounts/mod.rs | 0
Rsrc/accounts/route.rs -> crates/notedeck_columns/src/accounts/route.rs | 0
Rsrc/actionbar.rs -> crates/notedeck_columns/src/actionbar.rs | 0
Rsrc/app.rs -> crates/notedeck_columns/src/app.rs | 0
Rsrc/app_creation.rs -> crates/notedeck_columns/src/app_creation.rs | 0
Rsrc/app_size_handler.rs -> crates/notedeck_columns/src/app_size_handler.rs | 0
Rsrc/app_style.rs -> crates/notedeck_columns/src/app_style.rs | 0
Rsrc/args.rs -> crates/notedeck_columns/src/args.rs | 0
Rsrc/colors.rs -> crates/notedeck_columns/src/colors.rs | 0
Rsrc/column.rs -> crates/notedeck_columns/src/column.rs | 0
Rsrc/deck_state.rs -> crates/notedeck_columns/src/deck_state.rs | 0
Rsrc/decks.rs -> crates/notedeck_columns/src/decks.rs | 0
Rsrc/draft.rs -> crates/notedeck_columns/src/draft.rs | 0
Rsrc/error.rs -> crates/notedeck_columns/src/error.rs | 0
Rsrc/filter.rs -> crates/notedeck_columns/src/filter.rs | 0
Rsrc/fonts.rs -> crates/notedeck_columns/src/fonts.rs | 0
Rsrc/frame_history.rs -> crates/notedeck_columns/src/frame_history.rs | 0
Rsrc/images.rs -> crates/notedeck_columns/src/images.rs | 0
Rsrc/imgcache.rs -> crates/notedeck_columns/src/imgcache.rs | 0
Rsrc/key_parsing.rs -> crates/notedeck_columns/src/key_parsing.rs | 0
Rsrc/lib.rs -> crates/notedeck_columns/src/lib.rs | 0
Rsrc/login_manager.rs -> crates/notedeck_columns/src/login_manager.rs | 0
Rsrc/multi_subscriber.rs -> crates/notedeck_columns/src/multi_subscriber.rs | 0
Rsrc/muted.rs -> crates/notedeck_columns/src/muted.rs | 0
Rsrc/nav.rs -> crates/notedeck_columns/src/nav.rs | 0
Rsrc/note.rs -> crates/notedeck_columns/src/note.rs | 0
Rsrc/notecache.rs -> crates/notedeck_columns/src/notecache.rs | 0
Rsrc/notes_holder.rs -> crates/notedeck_columns/src/notes_holder.rs | 0
Rsrc/post.rs -> crates/notedeck_columns/src/post.rs | 0
Rsrc/profile.rs -> crates/notedeck_columns/src/profile.rs | 0
Rsrc/relay_pool_manager.rs -> crates/notedeck_columns/src/relay_pool_manager.rs | 0
Rsrc/result.rs -> crates/notedeck_columns/src/result.rs | 0
Rsrc/route.rs -> crates/notedeck_columns/src/route.rs | 0
Rsrc/storage/decks.rs -> crates/notedeck_columns/src/storage/decks.rs | 0
Rsrc/storage/file_key_storage.rs -> crates/notedeck_columns/src/storage/file_key_storage.rs | 0
Rsrc/storage/file_storage.rs -> crates/notedeck_columns/src/storage/file_storage.rs | 0
Rsrc/storage/key_storage_impl.rs -> crates/notedeck_columns/src/storage/key_storage_impl.rs | 0
Rsrc/storage/migration.rs -> crates/notedeck_columns/src/storage/migration.rs | 0
Rsrc/storage/mod.rs -> crates/notedeck_columns/src/storage/mod.rs | 0
Rsrc/storage/security_framework_key_storage.rs -> crates/notedeck_columns/src/storage/security_framework_key_storage.rs | 0
Rsrc/subscriptions.rs -> crates/notedeck_columns/src/subscriptions.rs | 0
Rsrc/support.rs -> crates/notedeck_columns/src/support.rs | 0
Rsrc/test_data.rs -> crates/notedeck_columns/src/test_data.rs | 0
Rsrc/test_utils.rs -> crates/notedeck_columns/src/test_utils.rs | 0
Rsrc/thread.rs -> crates/notedeck_columns/src/thread.rs | 0
Rsrc/time.rs -> crates/notedeck_columns/src/time.rs | 0
Rsrc/timecache.rs -> crates/notedeck_columns/src/timecache.rs | 0
Rsrc/timeline/kind.rs -> crates/notedeck_columns/src/timeline/kind.rs | 0
Rsrc/timeline/mod.rs -> crates/notedeck_columns/src/timeline/mod.rs | 0
Rsrc/timeline/route.rs -> crates/notedeck_columns/src/timeline/route.rs | 0
Rsrc/ui/account_login_view.rs -> crates/notedeck_columns/src/ui/account_login_view.rs | 0
Rsrc/ui/accounts.rs -> crates/notedeck_columns/src/ui/accounts.rs | 0
Rsrc/ui/add_column.rs -> crates/notedeck_columns/src/ui/add_column.rs | 0
Rsrc/ui/anim.rs -> crates/notedeck_columns/src/ui/anim.rs | 0
Rsrc/ui/column/header.rs -> crates/notedeck_columns/src/ui/column/header.rs | 0
Rsrc/ui/column/mod.rs -> crates/notedeck_columns/src/ui/column/mod.rs | 0
Rsrc/ui/configure_deck.rs -> crates/notedeck_columns/src/ui/configure_deck.rs | 0
Rsrc/ui/edit_deck.rs -> crates/notedeck_columns/src/ui/edit_deck.rs | 0
Rsrc/ui/mention.rs -> crates/notedeck_columns/src/ui/mention.rs | 0
Rsrc/ui/mod.rs -> crates/notedeck_columns/src/ui/mod.rs | 0
Rsrc/ui/note/contents.rs -> crates/notedeck_columns/src/ui/note/contents.rs | 0
Rsrc/ui/note/context.rs -> crates/notedeck_columns/src/ui/note/context.rs | 0
Rsrc/ui/note/mod.rs -> crates/notedeck_columns/src/ui/note/mod.rs | 0
Rsrc/ui/note/options.rs -> crates/notedeck_columns/src/ui/note/options.rs | 0
Rsrc/ui/note/post.rs -> crates/notedeck_columns/src/ui/note/post.rs | 0
Rsrc/ui/note/quote_repost.rs -> crates/notedeck_columns/src/ui/note/quote_repost.rs | 0
Rsrc/ui/note/reply.rs -> crates/notedeck_columns/src/ui/note/reply.rs | 0
Rsrc/ui/preview.rs -> crates/notedeck_columns/src/ui/preview.rs | 0
Rsrc/ui/profile/mod.rs -> crates/notedeck_columns/src/ui/profile/mod.rs | 0
Rsrc/ui/profile/picture.rs -> crates/notedeck_columns/src/ui/profile/picture.rs | 0
Rsrc/ui/profile/preview.rs -> crates/notedeck_columns/src/ui/profile/preview.rs | 0
Rsrc/ui/relay.rs -> crates/notedeck_columns/src/ui/relay.rs | 0
Rsrc/ui/side_panel.rs -> crates/notedeck_columns/src/ui/side_panel.rs | 0
Rsrc/ui/support.rs -> crates/notedeck_columns/src/ui/support.rs | 0
Rsrc/ui/thread.rs -> crates/notedeck_columns/src/ui/thread.rs | 0
Rsrc/ui/timeline.rs -> crates/notedeck_columns/src/ui/timeline.rs | 0
Rsrc/ui/username.rs -> crates/notedeck_columns/src/ui/username.rs | 0
Rsrc/unknowns.rs -> crates/notedeck_columns/src/unknowns.rs | 0
Rsrc/user_account.rs -> crates/notedeck_columns/src/user_account.rs | 0
Rsrc/view_state.rs -> crates/notedeck_columns/src/view_state.rs | 0
Denostr/Cargo.toml | 18------------------
Denostr/src/relay/message.rs | 282-------------------------------------------------------------------------------
Dsrc/bin/notedeck.rs | 105-------------------------------------------------------------------------------
Dsrc/ui_preview/main.rs | 114-------------------------------------------------------------------------------
160 files changed, 693 insertions(+), 751 deletions(-)

diff --git a/Cargo.lock b/Cargo.lock @@ -163,7 +163,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8619b80c242aa7bd638b5c7ddd952addeecb71f69c75e33f1d47b2804f8f883a" dependencies = [ "android_log-sys", - "env_logger 0.10.2", + "env_logger", "log", "once_cell", ] @@ -178,55 +178,6 @@ dependencies = [ ] [[package]] -name = "anstream" -version = "0.6.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64e15c1ab1f89faffbf04a634d5e1962e9074f2741eef6d97f3c4e322426d526" -dependencies = [ - "anstyle", - "anstyle-parse", - "anstyle-query", - "anstyle-wincon", - "colorchoice", - "is_terminal_polyfill", - "utf8parse", -] - -[[package]] -name = "anstyle" -version = "1.0.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bec1de6f59aedf83baf9ff929c98f2ad654b97c9510f4e70cf6f661d49fd5b1" - -[[package]] -name = "anstyle-parse" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb47de1e80c2b463c735db5b217a0ddc39d612e7ac9e2e96a5aed1f57616c1cb" -dependencies = [ - "utf8parse", -] - -[[package]] -name = "anstyle-query" -version = "1.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d36fc52c7f6c869915e99412912f22093507da8d9e942ceaf66fe4b7c14422a" -dependencies = [ - "windows-sys 0.52.0", -] - -[[package]] -name = "anstyle-wincon" -version = "3.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5bf74e1b6e971609db8ca7a9ce79fd5768ab6ae46441c572e46cf596f59e57f8" -dependencies = [ - "anstyle", - "windows-sys 0.52.0", -] - -[[package]] name = "anyhow" version = "1.0.87" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -766,12 +717,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b" [[package]] -name = "colorchoice" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0" - -[[package]] name = "com" version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -822,16 +767,6 @@ dependencies = [ ] [[package]] -name = "console_error_panic_hook" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a06aeb73f470f66dcdbf7223caeebb85984942f22f1adb2a088cf9668146bbbc" -dependencies = [ - "cfg-if", - "wasm-bindgen", -] - -[[package]] name = "core-foundation" version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1242,7 +1177,6 @@ dependencies = [ name = "enostr" version = "0.1.0" dependencies = [ - "env_logger 0.11.5", "ewebsock", "hex", "nostr", @@ -1287,16 +1221,6 @@ dependencies = [ ] [[package]] -name = "env_filter" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f2c92ceda6ceec50f43169f9ee8424fe2db276791afde7b2cd8bc084cb376ab" -dependencies = [ - "log", - "regex", -] - -[[package]] name = "env_logger" version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1310,19 +1234,6 @@ dependencies = [ ] [[package]] -name = "env_logger" -version = "0.11.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e13fa619b91fb2381732789fc5de83b45675e882f66623b7d8cb4f643017018d" -dependencies = [ - "anstream", - "anstyle", - "env_filter", - "humantime", - "log", -] - -[[package]] name = "epaint" version = "0.29.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -2088,12 +1999,6 @@ dependencies = [ ] [[package]] -name = "is_terminal_polyfill" -version = "1.70.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" - -[[package]] name = "itertools" version = "0.10.5" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -2591,9 +2496,20 @@ version = "0.2.0" dependencies = [ "android-activity 0.4.3", "android_logger", + "eframe", + "notedeck_columns", + "tokio", + "tracing-appender", + "tracing-subscriber", + "winit", +] + +[[package]] +name = "notedeck_columns" +version = "0.2.0" +dependencies = [ "base32", "bitflags 2.6.0", - "console_error_panic_hook", "dirs", "eframe", "egui", @@ -2603,7 +2519,7 @@ dependencies = [ "egui_virtual_list", "ehttp 0.2.0", "enostr", - "env_logger 0.10.2", + "env_logger", "hex", "image", "indexmap", @@ -2625,12 +2541,9 @@ dependencies = [ "tracing", "tracing-appender", "tracing-subscriber", - "tracing-wasm", "url", "urlencoding", "uuid", - "wasm-bindgen-futures", - "winit", ] [[package]] @@ -4658,17 +4571,6 @@ dependencies = [ ] [[package]] -name = "tracing-wasm" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4575c663a174420fa2d78f4108ff68f65bf2fbb7dd89f33749b6e826b3626e07" -dependencies = [ - "tracing", - "tracing-subscriber", - "wasm-bindgen", -] - -[[package]] name = "try-lock" version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -4871,12 +4773,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" [[package]] -name = "utf8parse" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" - -[[package]] name = "uuid" version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" diff --git a/Cargo.toml b/Cargo.toml @@ -1,63 +1,51 @@ -[package] -name = "notedeck" -version = "0.2.0" -authors = ["William Casarin <jb55@jb55.com>"] -edition = "2021" -default-run = "notedeck" -#rust-version = "1.60" -license = "GPLv3" -description = "A multiplatform nostr client" +[workspace] +resolver = "2" +members = [ + "crates/notedeck", + "crates/notedeck_columns", # Replace with the name of your subcrate -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[lib] -crate-type = ["lib", "cdylib"] + "crates/enostr", +] -[dependencies] -egui = { version = "0.29.1", features = ["serde"] } +[workspace.dependencies] +base32 = "0.4.0" +bitflags = "2.5.0" +dirs = "5.0.1" eframe = { version = "0.29.1", default-features = false, features = [ "wgpu", "wayland", "x11", "android-native-activity" ] } +egui = { version = "0.29.1", features = ["serde"] } egui_extras = { version = "0.29.1", features = ["all_loaders"] } -nostrdb = { git = "https://github.com/damus-io/nostrdb-rs", rev = "71154e4100775f6932ee517da4350c433ba14ec7" } -#egui-android = { git = "https://github.com/jb55/egui-android.git" } -ehttp = "0.2.0" -egui_tabs = "0.2.0" egui_nav = "0.2.0" +egui_tabs = "0.2.0" egui_virtual_list = "0.5.0" -reqwest = { version = "0.12.4", default-features = false, features = [ "rustls-tls-native-roots" ] } +ehttp = "0.2.0" +enostr = { path = "crates/enostr" } +env_logger = "0.10.0" +ewebsock = { version = "0.2.0", features = ["tls"] } +hex = "0.4.3" image = { version = "0.25", features = ["jpeg", "png", "webp"] } +indexmap = "2.6.0" log = "0.4.17" +nostr = { version = "0.30.0" } +nostrdb = { git = "https://github.com/damus-io/nostrdb-rs", rev = "71154e4100775f6932ee517da4350c433ba14ec7" } +notedeck = { path = "crates/notedeck" } +notedeck_columns = { path = "crates/notedeck_columns" } +open = "5.3.0" poll-promise = { version = "0.3.0", features = ["tokio"] } -serde_derive = "1" +puffin = { git = "https://github.com/jb55/puffin", package = "puffin", rev = "70ff86d5503815219b01a009afd3669b7903a057" } +puffin_egui = { git = "https://github.com/jb55/puffin", package = "puffin_egui", rev = "70ff86d5503815219b01a009afd3669b7903a057" } +reqwest = { version = "0.12.4", default-features = false, features = [ "rustls-tls-native-roots" ] } serde = { version = "1", features = ["derive"] } # You only need this if you want app persistence -tracing = "0.1.40" -enostr = { path = "enostr" } +serde_derive = "1" serde_json = "1.0.89" -env_logger = "0.10.0" -puffin_egui = { git = "https://github.com/jb55/puffin", package = "puffin_egui", rev = "70ff86d5503815219b01a009afd3669b7903a057", optional = true } -puffin = { git = "https://github.com/jb55/puffin", package = "puffin", rev = "70ff86d5503815219b01a009afd3669b7903a057", optional = true } -hex = "0.4.3" -base32 = "0.4.0" strum = "0.26" strum_macros = "0.26" -bitflags = "2.5.0" -uuid = { version = "1.10.0", features = ["v4"] } -indexmap = "2.6.0" -dirs = "5.0.1" +tokio = { version = "1.16", features = ["macros", "rt-multi-thread", "fs"] } +tracing = "0.1.40" tracing-appender = "0.2.3" +tracing-subscriber = { version = "0.3", features = ["env-filter"] } +url = "2.5.2" urlencoding = "2.1.3" -open = "5.3.0" -url = "2.5" - -[dev-dependencies] -tempfile = "3.13.0" - -[target.'cfg(target_os = "macos")'.dependencies] -security-framework = "2.11.0" - - -[features] -default = [] -profiling = ["puffin", "puffin_egui", "eframe/puffin"] +uuid = { version = "1.10.0", features = ["v4"] } [profile.small] inherits = 'release' @@ -66,72 +54,3 @@ lto = true # Enable link-time optimization codegen-units = 1 # Reduce number of codegen units to increase optimizations panic = 'abort' # Abort on panic strip = true # Strip symbols from binary* - -# web: -[target.'cfg(target_arch = "wasm32")'.dependencies] -console_error_panic_hook = "0.1.6" -tracing-wasm = "0.2" -wasm-bindgen-futures = "0.4" - -# native: -[target.'cfg(not(target_arch = "wasm32"))'.dependencies] -tokio = { version = "1.16", features = ["macros", "rt-multi-thread", "fs"] } -tracing-subscriber = { version = "0.3", features = ["env-filter"] } - - -[target.'cfg(target_os = "android")'.dependencies] -android_logger = "0.11.1" -android-activity = { version = "0.4", features = [ "native-activity" ] } -winit = { version = "0.30.5", features = [ "android-native-activity" ] } -#winit = { git="https://github.com/rust-windowing/winit.git", rev = "2a58b785fed2a3746f7c7eebce95bce67ddfd27c", features = ["android-native-activity"] } - -[package.metadata.bundle] -identifier = "com.damus.notedeck" -icon = ["assets/app_icon.icns"] - -[package.metadata.android] -package = "com.damus.app" -apk_name = "damus" -#assets = "assets" - -[[package.metadata.android.uses_feature]] -name = "android.hardware.vulkan.level" -required = true -version = 1 - -[[package.metadata.android.uses_permission]] -name = "android.permission.WRITE_EXTERNAL_STORAGE" -max_sdk_version = 18 - -[[package.metadata.android.uses_permission]] -name = "android.permission.READ_EXTERNAL_STORAGE" -max_sdk_version = 18 - -[package.metadata.android.signing.release] -path = "damus.keystore" -keystore_password = "damuskeystore" - -[[package.metadata.android.uses_permission]] -name = "android.permission.INTERNET" - -[package.metadata.android.application] -label = "Damus" - -[package.metadata.generate-rpm] -assets = [ - { source = "target/release/notedeck", dest = "/usr/bin/notedeck", mode = "755" }, -] - -[[bin]] -name = "notedeck" -path = "src/bin/notedeck.rs" - -[[bin]] -name = "ui_preview" -path = "src/ui_preview/main.rs" - -#[patch.crates-io] -#egui = "0.29.1" -#eframe = "0.29.1" -#emath = "0.29.1" -#egui_extras = "0.29.1" diff --git a/enostr/Cargo.lock b/crates/enostr/Cargo.lock diff --git a/crates/enostr/Cargo.toml b/crates/enostr/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "enostr" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +ewebsock = { version = "0.2.0", features = ["tls"] } +serde_derive = "1" +serde = { version = "1", features = ["derive"] } # You only need this if you want app persistence +serde_json = "1.0.89" +nostr = { version = "0.30.0" } +nostrdb = { workspace = true } +hex = { workspace = true } +tracing = { workspace = true } +url = { workspace = true } diff --git a/enostr/src/client/message.rs b/crates/enostr/src/client/message.rs diff --git a/enostr/src/client/mod.rs b/crates/enostr/src/client/mod.rs diff --git a/enostr/src/error.rs b/crates/enostr/src/error.rs diff --git a/enostr/src/filter.rs b/crates/enostr/src/filter.rs diff --git a/enostr/src/keypair.rs b/crates/enostr/src/keypair.rs diff --git a/enostr/src/lib.rs b/crates/enostr/src/lib.rs diff --git a/enostr/src/note.rs b/crates/enostr/src/note.rs diff --git a/enostr/src/profile.rs b/crates/enostr/src/profile.rs diff --git a/enostr/src/pubkey.rs b/crates/enostr/src/pubkey.rs diff --git a/crates/enostr/src/relay/message.rs b/crates/enostr/src/relay/message.rs @@ -0,0 +1,281 @@ +use crate::{Error, Result}; +use ewebsock::{WsEvent, WsMessage}; + +#[derive(Debug, Eq, PartialEq)] +pub struct CommandResult<'a> { + event_id: &'a str, + status: bool, + message: &'a str, +} + +#[derive(Debug, Eq, PartialEq)] +pub enum RelayMessage<'a> { + OK(CommandResult<'a>), + Eose(&'a str), + Event(&'a str, &'a str), + Notice(&'a str), +} + +#[derive(Debug)] +pub enum RelayEvent<'a> { + Opened, + Closed, + Other(&'a WsMessage), + Error(Error), + Message(RelayMessage<'a>), +} + +impl<'a> From<&'a WsEvent> for RelayEvent<'a> { + fn from(event: &'a WsEvent) -> RelayEvent<'a> { + match event { + WsEvent::Opened => RelayEvent::Opened, + WsEvent::Closed => RelayEvent::Closed, + WsEvent::Message(ref ws_msg) => ws_msg.into(), + WsEvent::Error(s) => RelayEvent::Error(Error::Generic(s.to_owned())), + } + } +} + +impl<'a> From<&'a WsMessage> for RelayEvent<'a> { + fn from(wsmsg: &'a WsMessage) -> RelayEvent<'a> { + match wsmsg { + WsMessage::Text(s) => match RelayMessage::from_json(s).map(RelayEvent::Message) { + Ok(msg) => msg, + Err(err) => RelayEvent::Error(err), + }, + wsmsg => RelayEvent::Other(wsmsg), + } + } +} + +impl<'a> RelayMessage<'a> { + pub fn eose(subid: &'a str) -> Self { + RelayMessage::Eose(subid) + } + + pub fn notice(msg: &'a str) -> Self { + RelayMessage::Notice(msg) + } + + pub fn ok(event_id: &'a str, status: bool, message: &'a str) -> Self { + RelayMessage::OK(CommandResult { + event_id, + status, + message, + }) + } + + pub fn event(ev: &'a str, sub_id: &'a str) -> Self { + RelayMessage::Event(sub_id, ev) + } + + pub fn from_json(msg: &'a str) -> Result<RelayMessage<'a>> { + if msg.is_empty() { + return Err(Error::Empty); + } + + // Notice + // Relay response format: ["NOTICE", <message>] + if &msg[0..=9] == "[\"NOTICE\"," { + // TODO: there could be more than one space, whatever + let start = if msg.as_bytes().get(10).copied() == Some(b' ') { + 12 + } else { + 11 + }; + let end = msg.len() - 2; + return Ok(Self::notice(&msg[start..end])); + } + + // Event + // Relay response format: ["EVENT", <subscription id>, <event JSON>] + if &msg[0..=7] == "[\"EVENT\"" { + let mut start = 9; + while let Some(&b' ') = msg.as_bytes().get(start) { + start += 1; // Move past optional spaces + } + if let Some(comma_index) = msg[start..].find(',') { + let subid_end = start + comma_index; + let subid = &msg[start..subid_end].trim().trim_matches('"'); + return Ok(Self::event(msg, subid)); + } else { + return Ok(Self::event(msg, "fixme")); + } + } + + // EOSE (NIP-15) + // Relay response format: ["EOSE", <subscription_id>] + if &msg[0..=7] == "[\"EOSE\"," { + let start = if msg.as_bytes().get(8).copied() == Some(b' ') { + 10 + } else { + 9 + }; + let end = msg.len() - 2; + return Ok(Self::eose(&msg[start..end])); + } + + // OK (NIP-20) + // Relay response format: ["OK",<event_id>, <true|false>, <message>] + if &msg[0..=5] == "[\"OK\"," { + // TODO: fix this + let event_id = &msg[7..71]; + let booly = &msg[73..77]; + let status: bool = if booly == "true" { + true + } else if booly == "false" { + false + } else { + return Err(Error::DecodeFailed); + }; + + return Ok(Self::ok(event_id, status, "fixme")); + } + + Err(Error::DecodeFailed) + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_handle_valid_notice() -> Result<()> { + let valid_notice_msg = r#"["NOTICE","Invalid event format!"]"#; + let handled_valid_notice_msg = RelayMessage::notice("Invalid event format!".to_string()); + + assert_eq!( + RelayMessage::from_json(valid_notice_msg)?, + handled_valid_notice_msg + ); + + Ok(()) + } + #[test] + fn test_handle_invalid_notice() { + //Missing content + let invalid_notice_msg = r#"["NOTICE"]"#; + //The content is not string + let invalid_notice_msg_content = r#"["NOTICE": 404]"#; + + assert_eq!( + RelayMessage::from_json(invalid_notice_msg).unwrap_err(), + Error::DecodeFailed + ); + assert_eq!( + RelayMessage::from_json(invalid_notice_msg_content).unwrap_err(), + Error::DecodeFailed + ); + } + + #[test] + fn test_handle_valid_event() -> Result<()> { + use tracing::debug; + + let valid_event_msg = r#"["EVENT", "random_string", {"id":"70b10f70c1318967eddf12527799411b1a9780ad9c43858f5e5fcd45486a13a5","pubkey":"379e863e8357163b5bce5d2688dc4f1dcc2d505222fb8d74db600f30535dfdfe","created_at":1612809991,"kind":1,"tags":[],"content":"test","sig":"273a9cd5d11455590f4359500bccb7a89428262b96b3ea87a756b770964472f8c3e87f5d5e64d8d2e859a71462a3f477b554565c4f2f326cb01dd7620db71502"}]"#; + + let id = "70b10f70c1318967eddf12527799411b1a9780ad9c43858f5e5fcd45486a13a5"; + let pubkey = "379e863e8357163b5bce5d2688dc4f1dcc2d505222fb8d74db600f30535dfdfe"; + let created_at = 1612809991; + let kind = 1; + let tags = vec![]; + let content = "test"; + let sig = "273a9cd5d11455590f4359500bccb7a89428262b96b3ea87a756b770964472f8c3e87f5d5e64d8d2e859a71462a3f477b554565c4f2f326cb01dd7620db71502"; + + let handled_event = Event::new_dummy(id, pubkey, created_at, kind, tags, content, sig); + debug!("event {:?}", handled_event); + + let msg = RelayMessage::from_json(valid_event_msg); + debug!("msg {:?}", msg); + + assert_eq!( + msg?, + RelayMessage::event(handled_event?, "random_string".to_string()) + ); + + Ok(()) + } + + #[test] + fn test_handle_invalid_event() { + //Mising Event field + let invalid_event_msg = r#"["EVENT","random_string"]"#; + //Event JSON with incomplete content + let invalid_event_msg_content = r#"["EVENT","random_string",{"id":"70b10f70c1318967eddf12527799411b1a9780ad9c43858f5e5fcd45486a13a5","pubkey":"379e863e8357163b5bce5d2688dc4f1dcc2d505222fb8d74db600f30535dfdfe"}]"#; + + assert_eq!( + RelayMessage::from_json(invalid_event_msg).unwrap_err(), + Error::DecodeFailed + ); + + assert_eq!( + RelayMessage::from_json(invalid_event_msg_content).unwrap_err(), + Error::DecodeFailed + ); + } + + #[test] + fn test_handle_valid_eose() -> Result<()> { + let valid_eose_msg = r#"["EOSE","random-subscription-id"]"#; + let handled_valid_eose_msg = RelayMessage::eose("random-subscription-id".to_string()); + + assert_eq!( + RelayMessage::from_json(valid_eose_msg)?, + handled_valid_eose_msg + ); + + Ok(()) + } + #[test] + fn test_handle_invalid_eose() { + // Missing subscription ID + assert_eq!( + RelayMessage::from_json(r#"["EOSE"]"#).unwrap_err(), + Error::DecodeFailed + ); + + // The subscription ID is not string + assert_eq!( + RelayMessage::from_json(r#"["EOSE",404]"#).unwrap_err(), + Error::DecodeFailed + ); + } + + #[test] + fn test_handle_valid_ok() -> Result<()> { + let valid_ok_msg = r#"["OK","b1a649ebe8b435ec71d3784793f3bbf4b93e64e17568a741aecd4c7ddeafce30",true,"pow: difficulty 25>=24"]"#; + let handled_valid_ok_msg = RelayMessage::ok( + "b1a649ebe8b435ec71d3784793f3bbf4b93e64e17568a741aecd4c7ddeafce30".to_string(), + true, + "pow: difficulty 25>=24".into(), + ); + + assert_eq!(RelayMessage::from_json(valid_ok_msg)?, handled_valid_ok_msg); + + Ok(()) + } + #[test] + fn test_handle_invalid_ok() { + // Missing params + assert_eq!( + RelayMessage::from_json( + r#"["OK","b1a649ebe8b435ec71d3784793f3bbf4b93e64e17568a741aecd4c7ddeafce30"]"# + ) + .unwrap_err(), + Error::DecodeFailed + ); + + // Invalid status + assert_eq!( + RelayMessage::from_json(r#"["OK","b1a649ebe8b435ec71d3784793f3bbf4b93e64e17568a741aecd4c7ddeafce30",hello,""]"#).unwrap_err(), + Error::DecodeFailed + ); + + // Invalid message + assert_eq!( + RelayMessage::from_json(r#"["OK","b1a649ebe8b435ec71d3784793f3bbf4b93e64e17568a741aecd4c7ddeafce30",hello,404]"#).unwrap_err(), + Error::DecodeFailed + ); + } +} diff --git a/enostr/src/relay/mod.rs b/crates/enostr/src/relay/mod.rs diff --git a/enostr/src/relay/pool.rs b/crates/enostr/src/relay/pool.rs diff --git a/crates/notedeck/Cargo.toml b/crates/notedeck/Cargo.toml @@ -0,0 +1,71 @@ +[package] +name = "notedeck" +version = "0.2.0" +authors = ["William Casarin <jb55@jb55.com>", "kernelkind <kernelkind@gmail.com>"] +edition = "2021" +default-run = "notedeck" +#rust-version = "1.60" +license = "GPLv3" +description = "A nostr browser" + +[dependencies] +notedeck_columns = { workspace = true } +tracing-subscriber = { workspace = true } +tracing-appender = { workspace = true } +tokio = { workspace = true } +eframe = { workspace = true } + +[[bin]] +name = "notedeck" +path = "src/notedeck.rs" + +[[bin]] +name = "ui_preview" +path = "src/preview.rs" + +[features] +default = [] +profiling = ["notedeck_columns/puffin"] + +[target.'cfg(target_os = "android")'.dependencies] +android_logger = "0.11.1" +android-activity = { version = "0.4", features = [ "native-activity" ] } +winit = { version = "0.30.5", features = [ "android-native-activity" ] } +#winit = { git="https://github.com/rust-windowing/winit.git", rev = "2a58b785fed2a3746f7c7eebce95bce67ddfd27c", features = ["android-native-activity"] } + +[package.metadata.bundle] +identifier = "com.damus.notedeck" +icon = ["assets/app_icon.icns"] + +[package.metadata.android] +package = "com.damus.app" +apk_name = "damus" +#assets = "assets" + +[[package.metadata.android.uses_feature]] +name = "android.hardware.vulkan.level" +required = true +version = 1 + +[[package.metadata.android.uses_permission]] +name = "android.permission.WRITE_EXTERNAL_STORAGE" +max_sdk_version = 18 + +[[package.metadata.android.uses_permission]] +name = "android.permission.READ_EXTERNAL_STORAGE" +max_sdk_version = 18 + +[package.metadata.android.signing.release] +path = "damus.keystore" +keystore_password = "damuskeystore" + +[[package.metadata.android.uses_permission]] +name = "android.permission.INTERNET" + +[package.metadata.android.application] +label = "Damus" + +[package.metadata.generate-rpm] +assets = [ + { source = "target/release/notedeck", dest = "/usr/bin/notedeck", mode = "755" }, +] diff --git a/crates/notedeck/src/notedeck.rs b/crates/notedeck/src/notedeck.rs @@ -0,0 +1,105 @@ +#![warn(clippy::all, rust_2018_idioms)] +#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release +use notedeck_columns::{ + app_creation::generate_native_options, + storage::{DataPath, DataPathType}, + Damus, +}; +use std::{path::PathBuf, str::FromStr}; + +use tracing_subscriber::EnvFilter; + +// Entry point for wasm +//#[cfg(target_arch = "wasm32")] +//use wasm_bindgen::prelude::*; + +fn setup_logging(path: &DataPath) { + #[allow(unused_variables)] // need guard to live for lifetime of program + let (maybe_non_blocking, maybe_guard) = { + let log_path = path.path(DataPathType::Log); + // Setup logging to file + + use tracing_appender::{ + non_blocking, + rolling::{RollingFileAppender, Rotation}, + }; + + let file_appender = RollingFileAppender::new( + Rotation::DAILY, + log_path, + format!("notedeck-{}.log", env!("CARGO_PKG_VERSION")), + ); + + let (non_blocking, _guard) = non_blocking(file_appender); + + (Some(non_blocking), Some(_guard)) + }; + + // Log to stdout (if you run with `RUST_LOG=debug`). + if let Some(non_blocking_writer) = maybe_non_blocking { + use tracing_subscriber::{fmt, layer::SubscriberExt, util::SubscriberInitExt}; + + let console_layer = fmt::layer().with_target(true).with_writer(std::io::stdout); + + // Create the file layer (writes to the file) + let file_layer = fmt::layer() + .with_ansi(false) + .with_writer(non_blocking_writer); + + let env_filter = + EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("info")); + + // Set up the subscriber to combine both layers + tracing_subscriber::registry() + .with(console_layer) + .with(file_layer) + .with(env_filter) + .init(); + } else { + tracing_subscriber::fmt() + .with_env_filter(EnvFilter::from_default_env()) + .init(); + } +} + +// Desktop +#[cfg(not(target_arch = "wasm32"))] +#[tokio::main] +async fn main() { + let base_path = DataPath::default_base().unwrap_or(PathBuf::from_str(".").unwrap()); + let path = DataPath::new(&base_path); + + setup_logging(&path); + + let _res = eframe::run_native( + "Damus Notedeck", + generate_native_options(path), + Box::new(|cc| { + Ok(Box::new(Damus::new( + &cc.egui_ctx, + base_path, + std::env::args().collect(), + ))) + }), + ); +} + +#[cfg(target_arch = "wasm32")] +pub fn main() { + // Make sure panics are logged using `console.error`. + console_error_panic_hook::set_once(); + + // Redirect tracing to console.log and friends: + tracing_wasm::set_as_global_default(); + + wasm_bindgen_futures::spawn_local(async { + let web_options = eframe::WebOptions::default(); + eframe::start_web( + "the_canvas_id", // hardcode it + web_options, + Box::new(|cc| Box::new(Damus::new(cc, "."))), + ) + .await + .expect("failed to start eframe"); + }); +} diff --git a/crates/notedeck/src/preview.rs b/crates/notedeck/src/preview.rs @@ -0,0 +1,114 @@ +use notedeck_columns::ui::configure_deck::ConfigureDeckView; +use notedeck_columns::ui::edit_deck::EditDeckView; +use notedeck_columns::ui::{ + account_login_view::AccountLoginView, accounts::AccountsView, add_column::AddColumnView, + DesktopSidePanel, PostView, Preview, PreviewApp, PreviewConfig, ProfilePic, ProfilePreview, + RelayView, +}; +use notedeck_columns::{ + app_creation::{generate_mobile_emulator_native_options, generate_native_options, setup_cc}, + storage::DataPath, +}; +use std::env; + +struct PreviewRunner { + force_mobile: bool, + light_mode: bool, +} + +impl PreviewRunner { + fn new(force_mobile: bool, light_mode: bool) -> Self { + PreviewRunner { + force_mobile, + light_mode, + } + } + + async fn run<P>(self, preview: P) + where + P: Into<PreviewApp> + 'static, + { + tracing_subscriber::fmt::init(); + + let native_options = if self.force_mobile { + generate_mobile_emulator_native_options() + } else { + // TODO: tmp preview pathbuf? + generate_native_options(DataPath::new("previews")) + }; + + let is_mobile = self.force_mobile; + let light_mode = self.light_mode; + + let _ = eframe::run_native( + "UI Preview Runner", + native_options, + Box::new(move |cc| { + let app = Into::<PreviewApp>::into(preview); + setup_cc(&cc.egui_ctx, is_mobile, light_mode); + Ok(Box::new(app)) + }), + ); + } +} + +macro_rules! previews { + // Accept a runner and name variable, followed by one or more identifiers for the views + ($runner:expr, $name:expr, $is_mobile:expr, $($view:ident),* $(,)?) => { + match $name.as_ref() { + $( + stringify!($view) => { + $runner.run($view::preview(PreviewConfig { is_mobile: $is_mobile })).await; + } + )* + _ => println!("Component not found."), + } + }; +} + +#[tokio::main] +async fn main() { + let mut name: Option<String> = None; + let mut is_mobile: Option<bool> = None; + let mut light_mode: bool = false; + + for arg in env::args() { + if arg == "--mobile" { + is_mobile = Some(true); + } else if arg == "--light" { + light_mode = true; + } else { + name = Some(arg); + } + } + + let name = if let Some(name) = name { + name + } else { + println!("Please specify a component to test"); + return; + }; + + println!( + "light mode previews: {}", + if light_mode { "enabled" } else { "disabled" } + ); + let is_mobile = is_mobile.unwrap_or(notedeck_columns::ui::is_compiled_as_mobile()); + let runner = PreviewRunner::new(is_mobile, light_mode); + + previews!( + runner, + name, + is_mobile, + RelayView, + AccountLoginView, + ProfilePreview, + ProfilePic, + AccountsView, + DesktopSidePanel, + PostView, + AddColumnView, + ConfigureDeckView, + EditDeckView, + ); +} diff --git a/crates/notedeck_columns/Cargo.toml b/crates/notedeck_columns/Cargo.toml @@ -0,0 +1,58 @@ +[package] +name = "notedeck_columns" +version = "0.2.0" +authors = ["William Casarin <jb55@jb55.com>"] +edition = "2021" +#rust-version = "1.60" +license = "GPLv3" +description = "A tweetdeck-style notedeck app" + +[lib] +crate-type = ["lib", "cdylib"] + +[dependencies] +base32 = { workspace = true } +bitflags = { workspace = true } +dirs = { workspace = true } +eframe = { workspace = true } +egui = { workspace = true } +egui_extras = { workspace = true } +egui_nav = { workspace = true } +egui_tabs = { workspace = true } +egui_virtual_list = { workspace = true } +ehttp = { workspace = true } +enostr = { workspace = true } +env_logger = { workspace = true } +hex = { workspace = true } +image = { workspace = true } +indexmap = { workspace = true } +log = { workspace = true } +nostrdb = { workspace = true } +open = { workspace = true } +poll-promise = { workspace = true } +puffin = { workspace = true, optional = true } +puffin_egui = { workspace = true, optional = true } +reqwest = { workspace = true } +serde = { workspace = true } +serde_derive = { workspace = true } +serde_json = { workspace = true } +strum = { workspace = true } +strum_macros = { workspace = true } +tokio = { workspace = true, features = ["macros", "rt-multi-thread", "fs"] } +tracing = { workspace = true } +tracing-appender = { workspace = true } +tracing-subscriber = { workspace = true } +url = { workspace = true } +urlencoding = { workspace = true } +uuid = { workspace = true } + +[dev-dependencies] +tempfile = "3.13.0" + +[target.'cfg(target_os = "macos")'.dependencies] +security-framework = "2.11.0" + +[features] +default = [] +profiling = ["puffin", "puffin_egui", "eframe/puffin"] + diff --git a/assets/Logo-Gradient-2x.png b/crates/notedeck_columns/assets/Logo-Gradient-2x.png Binary files differ. diff --git a/assets/Welcome to Nostrdeck 2x.png b/crates/notedeck_columns/assets/Welcome to Nostrdeck 2x.png Binary files differ. diff --git a/assets/app_icon.icns b/crates/notedeck_columns/assets/app_icon.icns Binary files differ. diff --git a/assets/damus-app-icon.png b/crates/notedeck_columns/assets/damus-app-icon.png Binary files differ. diff --git a/assets/damus-app-icon.svg b/crates/notedeck_columns/assets/damus-app-icon.svg diff --git a/assets/damus.ico b/crates/notedeck_columns/assets/damus.ico Binary files differ. diff --git a/assets/damus.svg b/crates/notedeck_columns/assets/damus.svg diff --git a/assets/damus_rounded.svg b/crates/notedeck_columns/assets/damus_rounded.svg diff --git a/assets/damus_rounded_80.png b/crates/notedeck_columns/assets/damus_rounded_80.png Binary files differ. diff --git a/assets/favicon.ico b/crates/notedeck_columns/assets/favicon.ico Binary files differ. diff --git a/assets/fonts/DejaVuSans-Bold-SansEmoji.ttf b/crates/notedeck_columns/assets/fonts/DejaVuSans-Bold-SansEmoji.ttf Binary files differ. diff --git a/assets/fonts/DejaVuSans-Bold.ttf b/crates/notedeck_columns/assets/fonts/DejaVuSans-Bold.ttf Binary files differ. diff --git a/assets/fonts/DejaVuSans.ttf b/crates/notedeck_columns/assets/fonts/DejaVuSans.ttf Binary files differ. diff --git a/assets/fonts/DejaVuSansSansEmoji.ttf b/crates/notedeck_columns/assets/fonts/DejaVuSansSansEmoji.ttf Binary files differ. diff --git a/assets/fonts/Inconsolata-Regular.ttf b/crates/notedeck_columns/assets/fonts/Inconsolata-Regular.ttf Binary files differ. diff --git a/assets/fonts/NotoEmoji-Regular.ttf b/crates/notedeck_columns/assets/fonts/NotoEmoji-Regular.ttf Binary files differ. diff --git a/assets/fonts/NotoSansCJK-Regular.ttc b/crates/notedeck_columns/assets/fonts/NotoSansCJK-Regular.ttc Binary files differ. diff --git a/assets/fonts/NotoSansThai-Regular.ttf b/crates/notedeck_columns/assets/fonts/NotoSansThai-Regular.ttf Binary files differ. diff --git a/assets/fonts/ark/ark-pixel-10px-proportional-latin.ttf b/crates/notedeck_columns/assets/fonts/ark/ark-pixel-10px-proportional-latin.ttf Binary files differ. diff --git a/assets/fonts/onest/OnestBlack1602-hint.ttf b/crates/notedeck_columns/assets/fonts/onest/OnestBlack1602-hint.ttf Binary files differ. diff --git a/assets/fonts/onest/OnestBold1602-hint.ttf b/crates/notedeck_columns/assets/fonts/onest/OnestBold1602-hint.ttf Binary files differ. diff --git a/assets/fonts/onest/OnestExtraBold1602-hint.ttf b/crates/notedeck_columns/assets/fonts/onest/OnestExtraBold1602-hint.ttf Binary files differ. diff --git a/assets/fonts/onest/OnestLight1602-hint.ttf b/crates/notedeck_columns/assets/fonts/onest/OnestLight1602-hint.ttf Binary files differ. diff --git a/assets/fonts/onest/OnestMedium1602-hint.ttf b/crates/notedeck_columns/assets/fonts/onest/OnestMedium1602-hint.ttf Binary files differ. diff --git a/assets/fonts/onest/OnestRegular1602-hint.ttf b/crates/notedeck_columns/assets/fonts/onest/OnestRegular1602-hint.ttf Binary files differ. diff --git a/assets/fonts/onest/OnestThin1602-hint.ttf b/crates/notedeck_columns/assets/fonts/onest/OnestThin1602-hint.ttf Binary files differ. diff --git a/assets/fonts/pressstart/PressStart2P.ttf b/crates/notedeck_columns/assets/fonts/pressstart/PressStart2P.ttf Binary files differ. diff --git a/assets/icons/add_account_icon_4x.png b/crates/notedeck_columns/assets/icons/add_account_icon_4x.png Binary files differ. diff --git a/assets/icons/add_column_dark_4x.png b/crates/notedeck_columns/assets/icons/add_column_dark_4x.png Binary files differ. diff --git a/assets/icons/add_column_light_4x.png b/crates/notedeck_columns/assets/icons/add_column_light_4x.png Binary files differ. diff --git a/assets/icons/column_delete_icon_4x.png b/crates/notedeck_columns/assets/icons/column_delete_icon_4x.png Binary files differ. diff --git a/assets/icons/column_delete_icon_light_4x.png b/crates/notedeck_columns/assets/icons/column_delete_icon_light_4x.png Binary files differ. diff --git a/assets/icons/connected_icon_4x.png b/crates/notedeck_columns/assets/icons/connected_icon_4x.png Binary files differ. diff --git a/assets/icons/connecting_icon_4x.png b/crates/notedeck_columns/assets/icons/connecting_icon_4x.png Binary files differ. diff --git a/assets/icons/delete_icon_4x.png b/crates/notedeck_columns/assets/icons/delete_icon_4x.png Binary files differ. diff --git a/assets/icons/disconnected_icon_4x.png b/crates/notedeck_columns/assets/icons/disconnected_icon_4x.png Binary files differ. diff --git a/assets/icons/help_icon_dark_4x.png b/crates/notedeck_columns/assets/icons/help_icon_dark_4x.png Binary files differ. diff --git a/assets/icons/help_icon_inverted_4x.png b/crates/notedeck_columns/assets/icons/help_icon_inverted_4x.png Binary files differ. diff --git a/assets/icons/home_icon_dark_4x.png b/crates/notedeck_columns/assets/icons/home_icon_dark_4x.png Binary files differ. diff --git a/assets/icons/new_deck_icon_4x_dark.png b/crates/notedeck_columns/assets/icons/new_deck_icon_4x_dark.png Binary files differ. diff --git a/assets/icons/notifications_icon_dark_4x.png b/crates/notedeck_columns/assets/icons/notifications_icon_dark_4x.png Binary files differ. diff --git a/assets/icons/plus_icon_4x.png b/crates/notedeck_columns/assets/icons/plus_icon_4x.png Binary files differ. diff --git a/assets/icons/reply-dark.png b/crates/notedeck_columns/assets/icons/reply-dark.png Binary files differ. diff --git a/assets/icons/reply.png b/crates/notedeck_columns/assets/icons/reply.png Binary files differ. diff --git a/assets/icons/reply.svg b/crates/notedeck_columns/assets/icons/reply.svg diff --git a/assets/icons/repost_icon_4x.png b/crates/notedeck_columns/assets/icons/repost_icon_4x.png Binary files differ. diff --git a/assets/icons/repost_light_4x.png b/crates/notedeck_columns/assets/icons/repost_light_4x.png Binary files differ. diff --git a/assets/icons/select_icon_3x.png b/crates/notedeck_columns/assets/icons/select_icon_3x.png Binary files differ. diff --git a/assets/icons/settings_dark_4x.png b/crates/notedeck_columns/assets/icons/settings_dark_4x.png Binary files differ. diff --git a/assets/icons/settings_light_4x.png b/crates/notedeck_columns/assets/icons/settings_light_4x.png Binary files differ. diff --git a/assets/icons/signout_icon_4x.png b/crates/notedeck_columns/assets/icons/signout_icon_4x.png Binary files differ. diff --git a/assets/icons/universe_icon_dark_4x.png b/crates/notedeck_columns/assets/icons/universe_icon_dark_4x.png Binary files differ. diff --git a/assets/manifest.json b/crates/notedeck_columns/assets/manifest.json diff --git a/assets/sw.js b/crates/notedeck_columns/assets/sw.js diff --git a/build.rs b/crates/notedeck_columns/build.rs diff --git a/src/abbrev.rs b/crates/notedeck_columns/src/abbrev.rs diff --git a/src/accounts/mod.rs b/crates/notedeck_columns/src/accounts/mod.rs diff --git a/src/accounts/route.rs b/crates/notedeck_columns/src/accounts/route.rs diff --git a/src/actionbar.rs b/crates/notedeck_columns/src/actionbar.rs diff --git a/src/app.rs b/crates/notedeck_columns/src/app.rs diff --git a/src/app_creation.rs b/crates/notedeck_columns/src/app_creation.rs diff --git a/src/app_size_handler.rs b/crates/notedeck_columns/src/app_size_handler.rs diff --git a/src/app_style.rs b/crates/notedeck_columns/src/app_style.rs diff --git a/src/args.rs b/crates/notedeck_columns/src/args.rs diff --git a/src/colors.rs b/crates/notedeck_columns/src/colors.rs diff --git a/src/column.rs b/crates/notedeck_columns/src/column.rs diff --git a/src/deck_state.rs b/crates/notedeck_columns/src/deck_state.rs diff --git a/src/decks.rs b/crates/notedeck_columns/src/decks.rs diff --git a/src/draft.rs b/crates/notedeck_columns/src/draft.rs diff --git a/src/error.rs b/crates/notedeck_columns/src/error.rs diff --git a/src/filter.rs b/crates/notedeck_columns/src/filter.rs diff --git a/src/fonts.rs b/crates/notedeck_columns/src/fonts.rs diff --git a/src/frame_history.rs b/crates/notedeck_columns/src/frame_history.rs diff --git a/src/images.rs b/crates/notedeck_columns/src/images.rs diff --git a/src/imgcache.rs b/crates/notedeck_columns/src/imgcache.rs diff --git a/src/key_parsing.rs b/crates/notedeck_columns/src/key_parsing.rs diff --git a/src/lib.rs b/crates/notedeck_columns/src/lib.rs diff --git a/src/login_manager.rs b/crates/notedeck_columns/src/login_manager.rs diff --git a/src/multi_subscriber.rs b/crates/notedeck_columns/src/multi_subscriber.rs diff --git a/src/muted.rs b/crates/notedeck_columns/src/muted.rs diff --git a/src/nav.rs b/crates/notedeck_columns/src/nav.rs diff --git a/src/note.rs b/crates/notedeck_columns/src/note.rs diff --git a/src/notecache.rs b/crates/notedeck_columns/src/notecache.rs diff --git a/src/notes_holder.rs b/crates/notedeck_columns/src/notes_holder.rs diff --git a/src/post.rs b/crates/notedeck_columns/src/post.rs diff --git a/src/profile.rs b/crates/notedeck_columns/src/profile.rs diff --git a/src/relay_pool_manager.rs b/crates/notedeck_columns/src/relay_pool_manager.rs diff --git a/src/result.rs b/crates/notedeck_columns/src/result.rs diff --git a/src/route.rs b/crates/notedeck_columns/src/route.rs diff --git a/src/storage/decks.rs b/crates/notedeck_columns/src/storage/decks.rs diff --git a/src/storage/file_key_storage.rs b/crates/notedeck_columns/src/storage/file_key_storage.rs diff --git a/src/storage/file_storage.rs b/crates/notedeck_columns/src/storage/file_storage.rs diff --git a/src/storage/key_storage_impl.rs b/crates/notedeck_columns/src/storage/key_storage_impl.rs diff --git a/src/storage/migration.rs b/crates/notedeck_columns/src/storage/migration.rs diff --git a/src/storage/mod.rs b/crates/notedeck_columns/src/storage/mod.rs diff --git a/src/storage/security_framework_key_storage.rs b/crates/notedeck_columns/src/storage/security_framework_key_storage.rs diff --git a/src/subscriptions.rs b/crates/notedeck_columns/src/subscriptions.rs diff --git a/src/support.rs b/crates/notedeck_columns/src/support.rs diff --git a/src/test_data.rs b/crates/notedeck_columns/src/test_data.rs diff --git a/src/test_utils.rs b/crates/notedeck_columns/src/test_utils.rs diff --git a/src/thread.rs b/crates/notedeck_columns/src/thread.rs diff --git a/src/time.rs b/crates/notedeck_columns/src/time.rs diff --git a/src/timecache.rs b/crates/notedeck_columns/src/timecache.rs diff --git a/src/timeline/kind.rs b/crates/notedeck_columns/src/timeline/kind.rs diff --git a/src/timeline/mod.rs b/crates/notedeck_columns/src/timeline/mod.rs diff --git a/src/timeline/route.rs b/crates/notedeck_columns/src/timeline/route.rs diff --git a/src/ui/account_login_view.rs b/crates/notedeck_columns/src/ui/account_login_view.rs diff --git a/src/ui/accounts.rs b/crates/notedeck_columns/src/ui/accounts.rs diff --git a/src/ui/add_column.rs b/crates/notedeck_columns/src/ui/add_column.rs diff --git a/src/ui/anim.rs b/crates/notedeck_columns/src/ui/anim.rs diff --git a/src/ui/column/header.rs b/crates/notedeck_columns/src/ui/column/header.rs diff --git a/src/ui/column/mod.rs b/crates/notedeck_columns/src/ui/column/mod.rs diff --git a/src/ui/configure_deck.rs b/crates/notedeck_columns/src/ui/configure_deck.rs diff --git a/src/ui/edit_deck.rs b/crates/notedeck_columns/src/ui/edit_deck.rs diff --git a/src/ui/mention.rs b/crates/notedeck_columns/src/ui/mention.rs diff --git a/src/ui/mod.rs b/crates/notedeck_columns/src/ui/mod.rs diff --git a/src/ui/note/contents.rs b/crates/notedeck_columns/src/ui/note/contents.rs diff --git a/src/ui/note/context.rs b/crates/notedeck_columns/src/ui/note/context.rs diff --git a/src/ui/note/mod.rs b/crates/notedeck_columns/src/ui/note/mod.rs diff --git a/src/ui/note/options.rs b/crates/notedeck_columns/src/ui/note/options.rs diff --git a/src/ui/note/post.rs b/crates/notedeck_columns/src/ui/note/post.rs diff --git a/src/ui/note/quote_repost.rs b/crates/notedeck_columns/src/ui/note/quote_repost.rs diff --git a/src/ui/note/reply.rs b/crates/notedeck_columns/src/ui/note/reply.rs diff --git a/src/ui/preview.rs b/crates/notedeck_columns/src/ui/preview.rs diff --git a/src/ui/profile/mod.rs b/crates/notedeck_columns/src/ui/profile/mod.rs diff --git a/src/ui/profile/picture.rs b/crates/notedeck_columns/src/ui/profile/picture.rs diff --git a/src/ui/profile/preview.rs b/crates/notedeck_columns/src/ui/profile/preview.rs diff --git a/src/ui/relay.rs b/crates/notedeck_columns/src/ui/relay.rs diff --git a/src/ui/side_panel.rs b/crates/notedeck_columns/src/ui/side_panel.rs diff --git a/src/ui/support.rs b/crates/notedeck_columns/src/ui/support.rs diff --git a/src/ui/thread.rs b/crates/notedeck_columns/src/ui/thread.rs diff --git a/src/ui/timeline.rs b/crates/notedeck_columns/src/ui/timeline.rs diff --git a/src/ui/username.rs b/crates/notedeck_columns/src/ui/username.rs diff --git a/src/unknowns.rs b/crates/notedeck_columns/src/unknowns.rs diff --git a/src/user_account.rs b/crates/notedeck_columns/src/user_account.rs diff --git a/src/view_state.rs b/crates/notedeck_columns/src/view_state.rs diff --git a/enostr/Cargo.toml b/enostr/Cargo.toml @@ -1,18 +0,0 @@ -[package] -name = "enostr" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -ewebsock = { version = "0.2.0", features = ["tls"] } -serde_derive = "1" -serde = { version = "1", features = ["derive"] } # You only need this if you want app persistence -serde_json = "1.0.89" -nostr = { version = "0.30.0" } -nostrdb = { git = "https://github.com/damus-io/nostrdb-rs", rev = "71154e4100775f6932ee517da4350c433ba14ec7" } -hex = "0.4.3" -tracing = "0.1.40" -env_logger = "0.11.1" -url = "2.5.2" diff --git a/enostr/src/relay/message.rs b/enostr/src/relay/message.rs @@ -1,282 +0,0 @@ -use crate::{Error, Result}; -use ewebsock::{WsEvent, WsMessage}; - -#[derive(Debug, Eq, PartialEq)] -pub struct CommandResult<'a> { - event_id: &'a str, - status: bool, - message: &'a str, -} - -#[derive(Debug, Eq, PartialEq)] -pub enum RelayMessage<'a> { - OK(CommandResult<'a>), - Eose(&'a str), - Event(&'a str, &'a str), - Notice(&'a str), -} - -#[derive(Debug)] -pub enum RelayEvent<'a> { - Opened, - Closed, - Other(&'a WsMessage), - Error(Error), - Message(RelayMessage<'a>), -} - -impl<'a> From<&'a WsEvent> for RelayEvent<'a> { - fn from(event: &'a WsEvent) -> RelayEvent<'a> { - match event { - WsEvent::Opened => RelayEvent::Opened, - WsEvent::Closed => RelayEvent::Closed, - WsEvent::Message(ref ws_msg) => ws_msg.into(), - WsEvent::Error(s) => RelayEvent::Error(Error::Generic(s.to_owned())), - } - } -} - -impl<'a> From<&'a WsMessage> for RelayEvent<'a> { - fn from(wsmsg: &'a WsMessage) -> RelayEvent<'a> { - match wsmsg { - WsMessage::Text(s) => match RelayMessage::from_json(s).map(RelayEvent::Message) { - Ok(msg) => msg, - Err(err) => RelayEvent::Error(err), - }, - wsmsg => RelayEvent::Other(wsmsg), - } - } -} - -impl<'a> RelayMessage<'a> { - pub fn eose(subid: &'a str) -> Self { - RelayMessage::Eose(subid) - } - - pub fn notice(msg: &'a str) -> Self { - RelayMessage::Notice(msg) - } - - pub fn ok(event_id: &'a str, status: bool, message: &'a str) -> Self { - RelayMessage::OK(CommandResult { - event_id, - status, - message, - }) - } - - pub fn event(ev: &'a str, sub_id: &'a str) -> Self { - RelayMessage::Event(sub_id, ev) - } - - pub fn from_json(msg: &'a str) -> Result<RelayMessage<'a>> { - if msg.is_empty() { - return Err(Error::Empty); - } - - // Notice - // Relay response format: ["NOTICE", <message>] - if &msg[0..=9] == "[\"NOTICE\"," { - // TODO: there could be more than one space, whatever - let start = if msg.as_bytes().get(10).copied() == Some(b' ') { - 12 - } else { - 11 - }; - let end = msg.len() - 2; - return Ok(Self::notice(&msg[start..end])); - } - - // Event - // Relay response format: ["EVENT", <subscription id>, <event JSON>] - if &msg[0..=7] == "[\"EVENT\"" { - let mut start = 9; - while let Some(&b' ') = msg.as_bytes().get(start) { - start += 1; // Move past optional spaces - } - if let Some(comma_index) = msg[start..].find(',') { - let subid_end = start + comma_index; - let subid = &msg[start..subid_end].trim().trim_matches('"'); - return Ok(Self::event(msg, subid)); - } else { - return Ok(Self::event(msg, "fixme")); - } - } - - // EOSE (NIP-15) - // Relay response format: ["EOSE", <subscription_id>] - if &msg[0..=7] == "[\"EOSE\"," { - let start = if msg.as_bytes().get(8).copied() == Some(b' ') { - 10 - } else { - 9 - }; - let end = msg.len() - 2; - return Ok(Self::eose(&msg[start..end])); - } - - // OK (NIP-20) - // Relay response format: ["OK",<event_id>, <true|false>, <message>] - if &msg[0..=5] == "[\"OK\"," { - // TODO: fix this - let event_id = &msg[7..71]; - let booly = &msg[73..77]; - let status: bool = if booly == "true" { - true - } else if booly == "false" { - false - } else { - return Err(Error::DecodeFailed); - }; - - return Ok(Self::ok(event_id, status, "fixme")); - } - - Err(Error::DecodeFailed) - } -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_handle_valid_notice() -> Result<()> { - let valid_notice_msg = r#"["NOTICE","Invalid event format!"]"#; - let handled_valid_notice_msg = RelayMessage::notice("Invalid event format!".to_string()); - - assert_eq!( - RelayMessage::from_json(valid_notice_msg)?, - handled_valid_notice_msg - ); - - Ok(()) - } - #[test] - fn test_handle_invalid_notice() { - //Missing content - let invalid_notice_msg = r#"["NOTICE"]"#; - //The content is not string - let invalid_notice_msg_content = r#"["NOTICE": 404]"#; - - assert_eq!( - RelayMessage::from_json(invalid_notice_msg).unwrap_err(), - Error::DecodeFailed - ); - assert_eq!( - RelayMessage::from_json(invalid_notice_msg_content).unwrap_err(), - Error::DecodeFailed - ); - } - - #[test] - fn test_handle_valid_event() -> Result<()> { - use tracing::debug; - - env_logger::init(); - let valid_event_msg = r#"["EVENT", "random_string", {"id":"70b10f70c1318967eddf12527799411b1a9780ad9c43858f5e5fcd45486a13a5","pubkey":"379e863e8357163b5bce5d2688dc4f1dcc2d505222fb8d74db600f30535dfdfe","created_at":1612809991,"kind":1,"tags":[],"content":"test","sig":"273a9cd5d11455590f4359500bccb7a89428262b96b3ea87a756b770964472f8c3e87f5d5e64d8d2e859a71462a3f477b554565c4f2f326cb01dd7620db71502"}]"#; - - let id = "70b10f70c1318967eddf12527799411b1a9780ad9c43858f5e5fcd45486a13a5"; - let pubkey = "379e863e8357163b5bce5d2688dc4f1dcc2d505222fb8d74db600f30535dfdfe"; - let created_at = 1612809991; - let kind = 1; - let tags = vec![]; - let content = "test"; - let sig = "273a9cd5d11455590f4359500bccb7a89428262b96b3ea87a756b770964472f8c3e87f5d5e64d8d2e859a71462a3f477b554565c4f2f326cb01dd7620db71502"; - - let handled_event = Event::new_dummy(id, pubkey, created_at, kind, tags, content, sig); - debug!("event {:?}", handled_event); - - let msg = RelayMessage::from_json(valid_event_msg); - debug!("msg {:?}", msg); - - assert_eq!( - msg?, - RelayMessage::event(handled_event?, "random_string".to_string()) - ); - - Ok(()) - } - - #[test] - fn test_handle_invalid_event() { - //Mising Event field - let invalid_event_msg = r#"["EVENT","random_string"]"#; - //Event JSON with incomplete content - let invalid_event_msg_content = r#"["EVENT","random_string",{"id":"70b10f70c1318967eddf12527799411b1a9780ad9c43858f5e5fcd45486a13a5","pubkey":"379e863e8357163b5bce5d2688dc4f1dcc2d505222fb8d74db600f30535dfdfe"}]"#; - - assert_eq!( - RelayMessage::from_json(invalid_event_msg).unwrap_err(), - Error::DecodeFailed - ); - - assert_eq!( - RelayMessage::from_json(invalid_event_msg_content).unwrap_err(), - Error::DecodeFailed - ); - } - - #[test] - fn test_handle_valid_eose() -> Result<()> { - let valid_eose_msg = r#"["EOSE","random-subscription-id"]"#; - let handled_valid_eose_msg = RelayMessage::eose("random-subscription-id".to_string()); - - assert_eq!( - RelayMessage::from_json(valid_eose_msg)?, - handled_valid_eose_msg - ); - - Ok(()) - } - #[test] - fn test_handle_invalid_eose() { - // Missing subscription ID - assert_eq!( - RelayMessage::from_json(r#"["EOSE"]"#).unwrap_err(), - Error::DecodeFailed - ); - - // The subscription ID is not string - assert_eq!( - RelayMessage::from_json(r#"["EOSE",404]"#).unwrap_err(), - Error::DecodeFailed - ); - } - - #[test] - fn test_handle_valid_ok() -> Result<()> { - let valid_ok_msg = r#"["OK","b1a649ebe8b435ec71d3784793f3bbf4b93e64e17568a741aecd4c7ddeafce30",true,"pow: difficulty 25>=24"]"#; - let handled_valid_ok_msg = RelayMessage::ok( - "b1a649ebe8b435ec71d3784793f3bbf4b93e64e17568a741aecd4c7ddeafce30".to_string(), - true, - "pow: difficulty 25>=24".into(), - ); - - assert_eq!(RelayMessage::from_json(valid_ok_msg)?, handled_valid_ok_msg); - - Ok(()) - } - #[test] - fn test_handle_invalid_ok() { - // Missing params - assert_eq!( - RelayMessage::from_json( - r#"["OK","b1a649ebe8b435ec71d3784793f3bbf4b93e64e17568a741aecd4c7ddeafce30"]"# - ) - .unwrap_err(), - Error::DecodeFailed - ); - - // Invalid status - assert_eq!( - RelayMessage::from_json(r#"["OK","b1a649ebe8b435ec71d3784793f3bbf4b93e64e17568a741aecd4c7ddeafce30",hello,""]"#).unwrap_err(), - Error::DecodeFailed - ); - - // Invalid message - assert_eq!( - RelayMessage::from_json(r#"["OK","b1a649ebe8b435ec71d3784793f3bbf4b93e64e17568a741aecd4c7ddeafce30",hello,404]"#).unwrap_err(), - Error::DecodeFailed - ); - } -} diff --git a/src/bin/notedeck.rs b/src/bin/notedeck.rs @@ -1,105 +0,0 @@ -#![warn(clippy::all, rust_2018_idioms)] -#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release -use notedeck::{ - app_creation::generate_native_options, - storage::{DataPath, DataPathType}, - Damus, -}; -use std::{path::PathBuf, str::FromStr}; - -use tracing_subscriber::EnvFilter; - -// Entry point for wasm -//#[cfg(target_arch = "wasm32")] -//use wasm_bindgen::prelude::*; - -fn setup_logging(path: &DataPath) { - #[allow(unused_variables)] // need guard to live for lifetime of program - let (maybe_non_blocking, maybe_guard) = { - let log_path = path.path(DataPathType::Log); - // Setup logging to file - - use tracing_appender::{ - non_blocking, - rolling::{RollingFileAppender, Rotation}, - }; - - let file_appender = RollingFileAppender::new( - Rotation::DAILY, - log_path, - format!("notedeck-{}.log", env!("CARGO_PKG_VERSION")), - ); - - let (non_blocking, _guard) = non_blocking(file_appender); - - (Some(non_blocking), Some(_guard)) - }; - - // Log to stdout (if you run with `RUST_LOG=debug`). - if let Some(non_blocking_writer) = maybe_non_blocking { - use tracing_subscriber::{fmt, layer::SubscriberExt, util::SubscriberInitExt}; - - let console_layer = fmt::layer().with_target(true).with_writer(std::io::stdout); - - // Create the file layer (writes to the file) - let file_layer = fmt::layer() - .with_ansi(false) - .with_writer(non_blocking_writer); - - let env_filter = - EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("info")); - - // Set up the subscriber to combine both layers - tracing_subscriber::registry() - .with(console_layer) - .with(file_layer) - .with(env_filter) - .init(); - } else { - tracing_subscriber::fmt() - .with_env_filter(EnvFilter::from_default_env()) - .init(); - } -} - -// Desktop -#[cfg(not(target_arch = "wasm32"))] -#[tokio::main] -async fn main() { - let base_path = DataPath::default_base().unwrap_or(PathBuf::from_str(".").unwrap()); - let path = DataPath::new(&base_path); - - setup_logging(&path); - - let _res = eframe::run_native( - "Damus Notedeck", - generate_native_options(path), - Box::new(|cc| { - Ok(Box::new(Damus::new( - &cc.egui_ctx, - base_path, - std::env::args().collect(), - ))) - }), - ); -} - -#[cfg(target_arch = "wasm32")] -pub fn main() { - // Make sure panics are logged using `console.error`. - console_error_panic_hook::set_once(); - - // Redirect tracing to console.log and friends: - tracing_wasm::set_as_global_default(); - - wasm_bindgen_futures::spawn_local(async { - let web_options = eframe::WebOptions::default(); - eframe::start_web( - "the_canvas_id", // hardcode it - web_options, - Box::new(|cc| Box::new(Damus::new(cc, "."))), - ) - .await - .expect("failed to start eframe"); - }); -} diff --git a/src/ui_preview/main.rs b/src/ui_preview/main.rs @@ -1,114 +0,0 @@ -use notedeck::ui::configure_deck::ConfigureDeckView; -use notedeck::ui::edit_deck::EditDeckView; -use notedeck::ui::{ - account_login_view::AccountLoginView, accounts::AccountsView, add_column::AddColumnView, - DesktopSidePanel, PostView, Preview, PreviewApp, PreviewConfig, ProfilePic, ProfilePreview, - RelayView, -}; -use notedeck::{ - app_creation::{generate_mobile_emulator_native_options, generate_native_options, setup_cc}, - storage::DataPath, -}; -use std::env; - -struct PreviewRunner { - force_mobile: bool, - light_mode: bool, -} - -impl PreviewRunner { - fn new(force_mobile: bool, light_mode: bool) -> Self { - PreviewRunner { - force_mobile, - light_mode, - } - } - - async fn run<P>(self, preview: P) - where - P: Into<PreviewApp> + 'static, - { - tracing_subscriber::fmt::init(); - - let native_options = if self.force_mobile { - generate_mobile_emulator_native_options() - } else { - // TODO: tmp preview pathbuf? - generate_native_options(DataPath::new("previews")) - }; - - let is_mobile = self.force_mobile; - let light_mode = self.light_mode; - - let _ = eframe::run_native( - "UI Preview Runner", - native_options, - Box::new(move |cc| { - let app = Into::<PreviewApp>::into(preview); - setup_cc(&cc.egui_ctx, is_mobile, light_mode); - Ok(Box::new(app)) - }), - ); - } -} - -macro_rules! previews { - // Accept a runner and name variable, followed by one or more identifiers for the views - ($runner:expr, $name:expr, $is_mobile:expr, $($view:ident),* $(,)?) => { - match $name.as_ref() { - $( - stringify!($view) => { - $runner.run($view::preview(PreviewConfig { is_mobile: $is_mobile })).await; - } - )* - _ => println!("Component not found."), - } - }; -} - -#[tokio::main] -async fn main() { - let mut name: Option<String> = None; - let mut is_mobile: Option<bool> = None; - let mut light_mode: bool = false; - - for arg in env::args() { - if arg == "--mobile" { - is_mobile = Some(true); - } else if arg == "--light" { - light_mode = true; - } else { - name = Some(arg); - } - } - - let name = if let Some(name) = name { - name - } else { - println!("Please specify a component to test"); - return; - }; - - println!( - "light mode previews: {}", - if light_mode { "enabled" } else { "disabled" } - ); - let is_mobile = is_mobile.unwrap_or(notedeck::ui::is_compiled_as_mobile()); - let runner = PreviewRunner::new(is_mobile, light_mode); - - previews!( - runner, - name, - is_mobile, - RelayView, - AccountLoginView, - ProfilePreview, - ProfilePic, - AccountsView, - DesktopSidePanel, - PostView, - AddColumnView, - ConfigureDeckView, - EditDeckView, - ); -}