Skip to content

Commit c0ccb7c

Browse files
authored
Merge pull request #557 from kevinaboos/tsp
2 parents acc9262 + 5149d7b commit c0ccb7c

28 files changed

+4048
-347
lines changed

Cargo.lock

Lines changed: 1918 additions & 118 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ matrix-sdk = { git = "https://github.com/matrix-org/matrix-rust-sdk", branch = "
4141
matrix-sdk-ui = { git = "https://github.com/matrix-org/matrix-rust-sdk", branch = "main", default-features = false, features = [ "rustls-tls" ] }
4242
rand = "0.8.5"
4343
rangemap = "1.5.0"
44+
sanitize-filename = "0.6"
4445
serde = "1.0"
4546
serde_json = "1.0"
4647
tokio = { version = "1.43.1", features = ["macros", "rt-multi-thread"] }
@@ -52,15 +53,47 @@ bitflags = "2.6.0"
5253
indexmap = "2.6.0"
5354
blurhash = { version = "0.2.3", default-features = false }
5455

56+
tsp_sdk = { git = "https://github.com/openwallet-foundation-labs/tsp.git", optional = true, features = ["async", "resolve"] }
57+
# tsp_sdk = { version = "0.8.0", optional = true, default-features = false, features = ["async", "resolve"] }
58+
quinn = { version = "0.11.8", default-features = false }
59+
60+
5561
[features]
5662
default = []
63+
## Enables experimental support for using TSP wallets.
64+
tsp = ["dep:tsp_sdk"]
65+
5766
## Hides the command prompt console on Windows.
5867
hide_windows_console = []
68+
5969
## Logs all diffs received by the Matrix RoomListService.
6070
log_room_list_diffs = []
71+
6172
## Logs all diffs to all room timelines.
6273
log_timeline_diffs = []
6374

75+
76+
[patch.crates-io]
77+
## This is required to avoid a version conflict on the libsqlite3-sys crate,
78+
## which is a native crate that can only exist once in the dependency graph.
79+
## The `matrix-sdk` crate's dependencies require a specific version of `libsqlite3-sys`
80+
## (via rustsqlite which requires libsqlite3-sys 0.33.0),
81+
## whereas the `tsp_sdk` crate depends on `sqlx`, which requires a different version
82+
## of `libsqlite3-sys` (via `aries-askar`, which depends on `askar-storage`,
83+
## which requires libsqlite3-sys 0.30.0).
84+
## So this patch is a custom version of sqlx that *pretends* to be 0.8.6
85+
## (even though in reality uses the newest commit of `sqlx`,
86+
## which recently was updated to allow for a *range* of versions of `libsqlite3-sys`).
87+
## See <https://github.com/launchbadge/sqlx/pull/3928/files#diff-4f4849707ed063bc5de6d9f6d105f0e7baf62d1085b3c8aee4a547468b89248fR57>
88+
# sqlx = { git = "https://github.com/project-robius/sqlx.git", branch = "version_0.9_alpha_as_0.8.6" }
89+
sqlx = { git = "https://github.com/project-robius/sqlx.git", branch = "update_libsqlite3-sys_version" }
90+
91+
## This is required for the askar repos to work with the above-patched `sqlx` crate,
92+
## more specifically, the updated `libsqlite3-sys` version (0.31.0).
93+
## See <https://github.com/openwallet-foundation/askar/pull/386>
94+
askar-storage = { git = "https://github.com/openwallet-foundation/askar.git", rev = "0b919bb58205416df7cd2cc1a24ce52373cbe105" }
95+
96+
6497
[package.metadata.docs.rs]
6598
all-features = true
6699

License Attributions.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
## Icons
2+
3+
Nearly all icons used in Robrix are obtained from [SVG Repo](https://www.svgrepo.com/). Every icon downloaded from that website is used in accordance with [their licensing terms here]( https://www.svgrepo.com/page/licensing/).
4+
5+
6+
Other icons are individually attributed below, as required.
7+
8+
* Add Wallet by Creative Stall from <a href="https://thenounproject.com/browse/icons/term/add-wallet/" target="_blank" title="Add Wallet Icons">Noun Project</a> (CC BY 3.0)

resources/icons/add_wallet.svg

Lines changed: 1 addition & 0 deletions
Loading

resources/icons/import.svg

Lines changed: 2 additions & 0 deletions
Loading

resources/icons/import2.svg

Lines changed: 6 additions & 0 deletions
Loading

src/app.rs

Lines changed: 40 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,7 @@ use crate::{
2020
JoinLeaveRoomModalWidgetRefExt,
2121
},
2222
login::login_screen::LoginAction,
23-
persistent_state::{
24-
load_window_state,
25-
save_app_state,
26-
save_window_state,
27-
},
23+
persistence,
2824
shared::callout_tooltip::{
2925
CalloutTooltipOptions,
3026
CalloutTooltipWidgetRefExt,
@@ -41,7 +37,6 @@ use crate::{
4137
VerificationModalWidgetRefExt,
4238
},
4339
};
44-
use serde::{self, Deserialize, Serialize};
4540

4641
live_design! {
4742
use link::theme::*;
@@ -116,7 +111,7 @@ live_design! {
116111
// but behind the verification modal.
117112
new_message_context_menu = <NewMessageContextMenu> { }
118113

119-
// We want the verification modal to always show up on top of
114+
// We want the verification modal to always show up in front of
120115
// all other elements when an incoming verification request is received.
121116
verification_modal = <Modal> {
122117
content: {
@@ -153,6 +148,8 @@ impl LiveRegister for App {
153148
// then other modules widgets.
154149
makepad_widgets::live_design(cx);
155150
crate::shared::live_design(cx);
151+
#[cfg(feature = "tsp")]
152+
crate::tsp::live_design(cx);
156153
crate::settings::live_design(cx);
157154
crate::room::live_design(cx);
158155
crate::join_leave_room_modal::live_design(cx);
@@ -181,13 +178,20 @@ impl MatchEvent for App {
181178
// such that background threads/tasks will be able to can access it.
182179
let _app_data_dir = crate::app_data_dir();
183180
log!("App::handle_startup(): app_data_dir: {:?}", _app_data_dir);
184-
self.update_login_visibility(cx);
185181

186-
log!("App::handle_startup(): starting matrix sdk loop");
187-
crate::sliding_sync::start_matrix_tokio().unwrap();
188-
if let Err(e) = load_window_state(self.ui.window(id!(main_window)), cx) {
182+
if let Err(e) = persistence::load_window_state(self.ui.window(id!(main_window)), cx) {
189183
error!("Failed to load window state: {}", e);
190184
}
185+
186+
self.update_login_visibility(cx);
187+
188+
log!("App::Startup: starting matrix sdk loop");
189+
let _tokio_rt = crate::sliding_sync::start_matrix_tokio().unwrap();
190+
191+
#[cfg(feature = "tsp")] {
192+
log!("App::Startup: initializing TSP (Trust Spanning Protocol) module.");
193+
crate::tsp::tsp_init(_tokio_rt).unwrap();
194+
}
191195
}
192196

193197
fn handle_actions(&mut self, cx: &mut Cx, actions: &Actions) {
@@ -353,13 +357,34 @@ impl AppMain for App {
353357

354358
if let Event::Shutdown = event {
355359
let window_ref = self.ui.window(id!(main_window));
356-
if let Err(e) = save_window_state(window_ref, cx) {
357-
error!("Failed to save window state. Error details: {}", e);
360+
if let Err(e) = persistence::save_window_state(window_ref, cx) {
361+
error!("Failed to save window state. Error: {e}");
358362
}
359363
if let Some(user_id) = current_user_id() {
360364
let app_state = self.app_state.clone();
361-
if let Err(e) = save_app_state(app_state, user_id) {
362-
error!("Failed to save app state. Error details: {}", e);
365+
if let Err(e) = persistence::save_app_state(app_state, user_id) {
366+
error!("Failed to save app state. Error: {e}");
367+
}
368+
}
369+
#[cfg(feature = "tsp")] {
370+
// Save the TSP wallet state, if it exists, with a 3-second timeout.
371+
let tsp_state = std::mem::take(&mut *crate::tsp::tsp_state_ref().lock().unwrap());
372+
if tsp_state.has_content() {
373+
let res = crate::sliding_sync::block_on_async_with_timeout(
374+
Some(std::time::Duration::from_secs(3)),
375+
async move {
376+
match tsp_state.close_and_serialize().await {
377+
Ok(saved_state) => match persistence::save_tsp_state_async(saved_state).await {
378+
Ok(_) => { }
379+
Err(e) => error!("Failed to save TSP wallet state. Error: {e}"),
380+
}
381+
Err(e) => error!("Failed to close and serialize TSP wallet state. Error: {e}"),
382+
}
383+
},
384+
);
385+
if let Err(_e) = res {
386+
error!("Failed to save TSP wallet state before app shutdown. Error: Timed Out.");
387+
}
363388
}
364389
}
365390
}
@@ -517,14 +542,3 @@ pub enum AppStateAction {
517542
RoomLoadedSuccessfully(OwnedRoomId),
518543
None,
519544
}
520-
521-
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
522-
/// The state of the window geometry
523-
pub struct WindowGeomState {
524-
/// A tuple containing the window's width and height.
525-
pub inner_size: (f64, f64),
526-
/// A tuple containing the window's x and y position.
527-
pub position: (f64, f64),
528-
/// Maximise fullscreen if true.
529-
pub is_fullscreen: bool,
530-
}

src/home/room_screen.rs

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,23 @@ use std::{borrow::Cow, cell::RefCell, collections::BTreeMap, ops::{DerefMut, Ran
66
use bytesize::ByteSize;
77
use imbl::Vector;
88
use makepad_widgets::{image_cache::ImageBuffer, *};
9-
use matrix_sdk::{room::{reply::{EnforceThread, Reply}, RoomMember}, ruma::{
10-
events::{receipt::Receipt, room::{
11-
message::{
12-
AudioMessageEventContent, EmoteMessageEventContent, FileMessageEventContent, FormattedBody, ImageMessageEventContent, KeyVerificationRequestEventContent, LocationMessageEventContent, MessageFormat, MessageType, NoticeMessageEventContent, RoomMessageEventContent, TextMessageEventContent, VideoMessageEventContent
13-
}, ImageInfo, MediaSource
9+
use matrix_sdk::{
10+
room::{reply::{EnforceThread, Reply}, RoomMember},
11+
ruma::{
12+
events::{
13+
receipt::Receipt,
14+
room::{
15+
message::{
16+
AudioMessageEventContent, EmoteMessageEventContent, FileMessageEventContent, FormattedBody, ImageMessageEventContent, KeyVerificationRequestEventContent, LocationMessageEventContent, MessageFormat, MessageType, NoticeMessageEventContent, RoomMessageEventContent, TextMessageEventContent, VideoMessageEventContent
17+
},
18+
ImageInfo, MediaSource
19+
},
20+
sticker::{StickerEventContent, StickerMediaSource},
21+
},
22+
matrix_uri::MatrixId, uint, EventId, MatrixToUri, MatrixUri, OwnedEventId, OwnedMxcUri, OwnedRoomId, UserId
1423
},
15-
sticker::{StickerEventContent, StickerMediaSource}}, matrix_uri::MatrixId, uint, EventId, MatrixToUri, MatrixUri, OwnedEventId, OwnedMxcUri, OwnedRoomId, UserId
16-
}, OwnedServerName};
24+
OwnedServerName,
25+
};
1726
use matrix_sdk_ui::timeline::{
1827
self, EmbeddedEvent, EncryptedMessage, EventTimelineItem, InReplyToDetails, MemberProfileChange, MsgLikeContent, MsgLikeKind, PollState, RoomMembershipChange, TimelineDetails, TimelineEventItemId, TimelineItem, TimelineItemContent, TimelineItemKind, VirtualTimelineItem
1928
};
@@ -1264,7 +1273,7 @@ impl Widget for RoomScreen {
12641273
let room_screen_widget_uid = self.widget_uid();
12651274

12661275
while let Some(subview) = self.view.draw_walk(cx, scope, walk).step() {
1267-
// We only care about drawing the portal list.
1276+
// Here, we only need to handle drawing the portal list.
12681277
let portal_list_ref = subview.as_portal_list();
12691278
let Some(mut list_ref) = portal_list_ref.borrow_mut() else {
12701279
error!("!!! RoomScreen::draw_walk(): BUG: expected a PortalList widget, but got something else");
@@ -1627,11 +1636,11 @@ impl RoomScreen {
16271636
}
16281637
}
16291638
TimelineUpdate::PaginationError { error, direction } => {
1630-
error!("Pagination error ({direction}) in room {}: {error:?}", tl.room_id);
1639+
error!("Pagination error ({direction}) in room \"{}\", {}: {error:?}", self.room_name, tl.room_id);
16311640
enqueue_popup_notification(PopupItem {
1632-
message: format!("Error loading earlier messages in \"{}\": {error}", self.room_name),
1633-
kind: PopupKind::Error,
1641+
message: utils::stringify_pagination_error(&error, &self.room_name),
16341642
auto_dismissal_duration: None,
1643+
kind: PopupKind::Error,
16351644
});
16361645
done_loading = true;
16371646
}

src/home/rooms_list.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,6 @@ live_design! {
4646
use crate::shared::collapsible_header::*;
4747
use crate::home::room_preview::*;
4848

49-
// An empty view that takes up no space in the portal list.
50-
Empty = <View> { }
51-
5249
StatusLabel = <View> {
5350
width: Fill, height: Fit,
5451
align: { x: 0.5, y: 0.5 }
@@ -80,7 +77,7 @@ live_design! {
8077

8178
collapsible_header = <CollapsibleHeader> {}
8279
room_preview = <RoomPreview> {}
83-
empty = <Empty> {}
80+
empty = <View> {}
8481
status_label = <StatusLabel> {}
8582
bottom_filler = <View> {
8683
width: Fill,

src/join_leave_room_modal.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
//! A modal dialog for joining or leaving rooms in Matrix.
2+
//!
3+
//! Also used as a confirmation dialog for accepting or rejecting room invites.
4+
15
use makepad_widgets::*;
26
use matrix_sdk::ruma::OwnedRoomId;
37

0 commit comments

Comments
 (0)