Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
116 commits
Select commit Hold shift + click to select a range
27871c3
fix pr #293 about logout
TigerInYourDream Mar 11, 2025
708d493
Merge branch 'main' into fix-logout
TigerInYourDream Mar 12, 2025
c380f0f
explain key exchange
TigerInYourDream Mar 12, 2025
9b0a7fd
CORE_TASKS for save and abort async task
TigerInYourDream Mar 14, 2025
b4242ed
refactor logout
TigerInYourDream Mar 18, 2025
82704ed
Merge branch 'main' into fix-logout
TigerInYourDream Mar 18, 2025
1b827fa
fix: typos
TigerInYourDream Mar 18, 2025
66e00ea
trace more long term async task and resource async_task
TigerInYourDream Mar 18, 2025
d702758
Merge branch 'main' into fix-logout
TigerInYourDream Mar 18, 2025
0d3d156
Merge branch 'main' into fix-logout
TigerInYourDream Mar 19, 2025
ccfc991
Merge branch 'main' into fix-logout
TigerInYourDream Mar 20, 2025
53dc860
fix with clippy check
TigerInYourDream Mar 20, 2025
734536b
feat(auth): Enhance Matrix logout robustness and error handling
TigerInYourDream Mar 24, 2025
f41d554
feat(auth): delete_last_user_id file
TigerInYourDream Mar 25, 2025
52014ea
Merge branch 'main' into fix-logout
TigerInYourDream Apr 2, 2025
90c06dc
add close all tab and collect all error during logout
TigerInYourDream Apr 6, 2025
e4ec15e
Merge branch 'main' into fix-logout
TigerInYourDream Apr 6, 2025
fee0443
add TODO for direct message
TigerInYourDream Apr 7, 2025
6e795e3
redraw ui
TigerInYourDream Apr 7, 2025
3564a70
save docker as pressed HOME_TAB
TigerInYourDream Apr 8, 2025
31ae379
ait for UI to update
TigerInYourDream Apr 8, 2025
714d14c
add logout_confirm_modal
TigerInYourDream Apr 15, 2025
7247edb
Merge branch 'main' into fix-logout
TigerInYourDream Apr 15, 2025
d328277
clean code and add reason for sleep
TigerInYourDream Apr 16, 2025
045ae55
add TODO for close_all_tabs
TigerInYourDream Apr 16, 2025
9561e76
Merge branch 'main' into fix-logout
TigerInYourDream Apr 17, 2025
1bec0e6
Merge branch 'main' into fix-logout
TigerInYourDream Apr 18, 2025
e98ff8c
Simplified logging in logout process
TigerInYourDream Apr 21, 2025
43794bf
improve code
TigerInYourDream May 7, 2025
7232052
Merge branch 'main' into fix-logout
TigerInYourDream May 7, 2025
82542c6
Fix compilation issues after merging main into fix-logout
TigerInYourDream May 8, 2025
5875399
improve code use action not weight_action
TigerInYourDream May 12, 2025
bb29667
close and open
TigerInYourDream May 15, 2025
88d3011
use shoutdown background
TigerInYourDream May 29, 2025
827577d
Merge branch 'main' into fix-logout
TigerInYourDream May 29, 2025
ae6ef31
clean code
TigerInYourDream May 29, 2025
ad4be11
Merge branch 'main' into fix-logout
ZhangHanDong Jun 3, 2025
6adcd2b
undo change for Cargo.toml
TigerInYourDream Jun 10, 2025
d34edc0
Fix: Implement code review suggestions
TigerInYourDream Jun 10, 2025
4eaf293
Ref: refactor logout modal
TigerInYourDream Jun 13, 2025
160ad42
notify close all tab by makepad::oneshot
TigerInYourDream Jun 17, 2025
574431b
improve LogoutConfirmModal
TigerInYourDream Jun 18, 2025
d6b82a6
remove DropMemberSubscription
TigerInYourDream Jun 19, 2025
aaaa791
remove take_client and take_service func
TigerInYourDream Jun 19, 2025
0c7922d
Merge remote-tracking branch 'origin/main' into fix-logout
TigerInYourDream Jun 19, 2025
9e27deb
resolve conflicts
TigerInYourDream Jun 19, 2025
9af1c7d
doc: doc for logout_and_refresh
TigerInYourDream Jun 19, 2025
778eaf6
undo
TigerInYourDream Jun 19, 2025
621be46
Merge branch 'main' into fix-logout
TigerInYourDream Jun 20, 2025
ca5ff03
fix typo and use new matrix api
TigerInYourDream Jun 20, 2025
e759795
mobile logout
TigerInYourDream Jun 20, 2025
a267ea4
prevent infinite loops in logout modal
TigerInYourDream Jun 25, 2025
ec16e6a
rename modal_interaction_state
TigerInYourDream Jun 25, 2025
d54734e
doc: add doc for dismiss_handled
TigerInYourDream Jun 25, 2025
ce43d70
use LogoutConfirmModalAction for all logout responese, remove LogoutS…
TigerInYourDream Jun 25, 2025
7d34959
refactor: improve logout flow with better state management and UI han…
TigerInYourDream Jun 26, 2025
a355170
fix: reset_state after successfully logout
TigerInYourDream Jun 26, 2025
f561bbd
improve code
TigerInYourDream Jun 26, 2025
8b3fe11
improve code and add timeout for server logout
TigerInYourDream Jun 26, 2025
0d0ed1b
Merge branch 'main' into fix-logout
TigerInYourDream Jun 27, 2025
1a85ecf
clean code
TigerInYourDream Jun 27, 2025
a4986c7
log
TigerInYourDream Jun 27, 2025
e1f80ea
add doc for REQUEST_SENDER clean
TigerInYourDream Jun 27, 2025
2b80cae
fix: fix crash when switch layout
TigerInYourDream Jul 1, 2025
712b4d2
feat: treat M_UNKNOWN_TOKEN as successful
TigerInYourDream Jul 2, 2025
e44103f
improve CleanMobileResource
TigerInYourDream Jul 3, 2025
5d88a50
improve UX
TigerInYourDream Jul 3, 2025
c75eb9b
typo
TigerInYourDream Jul 3, 2025
d0e9abd
Add ApplicationRequiresRestart for corner case
TigerInYourDream Jul 4, 2025
df39c2f
exchange seq
TigerInYourDream Jul 4, 2025
d293459
Merge branch 'origin/main' into fix-logout
TigerInYourDream Jul 10, 2025
8f14cc2
add ALL_JOINED_ROOMS clear
TigerInYourDream Jul 11, 2025
5ecc2fc
Merge branch 'main' into fix-logout
TigerInYourDream Jul 14, 2025
f34e1de
clean appstate both in mobile and desktop
TigerInYourDream Jul 14, 2025
d8bff52
doc
TigerInYourDream Jul 14, 2025
6546418
merge origin/main
TigerInYourDream Jul 15, 2025
a4a25bc
ref: logout with state machine
TigerInYourDream Jul 16, 2025
1b75c12
add doc
TigerInYourDream Jul 17, 2025
ad67b4d
add doc and fix typos
TigerInYourDream Jul 17, 2025
87d43f5
Merge branch 'main' into fix-logout
TigerInYourDream Jul 20, 2025
789ddee
doc for design
TigerInYourDream Jul 25, 2025
8065a1f
mt
TigerInYourDream Jul 25, 2025
2a72ff3
update doc for clean all caches
TigerInYourDream Jul 25, 2025
a10e89d
Merge remote-tracking branch 'origin/main' into fix-logout
TigerInYourDream Jul 25, 2025
32b1e98
fmt
TigerInYourDream Jul 28, 2025
18f4e3f
fix color
TigerInYourDream Jul 29, 2025
e0221f0
Merge branch 'main' into fix-logout
TigerInYourDream Jul 29, 2025
eeb92fb
move logout button to account_settings
TigerInYourDream Jul 30, 2025
312befd
test: test version no leak
TigerInYourDream Jul 30, 2025
42819d5
remove all leak and add Cx for clear_all_caches
TigerInYourDream Aug 4, 2025
7a5ce4d
fmt
TigerInYourDream Aug 4, 2025
d53ec5d
improve code via review comment
TigerInYourDream Aug 6, 2025
ebeeda2
improve logout confirm modal
TigerInYourDream Aug 6, 2025
f626aae
improve UX
TigerInYourDream Aug 6, 2025
0f1cf06
remove restart now and add abort in logout process
TigerInYourDream Aug 7, 2025
2031e9f
logout folder
TigerInYourDream Aug 7, 2025
9c45b2b
Resolve merge conflicts with main
TigerInYourDream Aug 7, 2025
917dc61
refactor: make runtime shutdown synchronous with independent thread
TigerInYourDream Aug 7, 2025
50d9f99
fix merge main abort tsp and use Arc<Notify> remove makepad oneshot
TigerInYourDream Aug 11, 2025
9fe43e1
refactor: remove Arc wrapper from TOKIO_RUNTIME to enable proper shut…
TigerInYourDream Aug 12, 2025
3a185c5
use cx quit
TigerInYourDream Aug 12, 2025
4d9b321
Merge branch 'main' into fix-logout
TigerInYourDream Aug 12, 2025
d9d47c5
restore tsp code in app.rs
TigerInYourDream Aug 12, 2025
8a23fc5
update doc
TigerInYourDream Aug 13, 2025
8ca0589
restore doc
TigerInYourDream Aug 13, 2025
41f9997
use replace for REQUEST_SENDER
TigerInYourDream Aug 13, 2025
81fed9d
Store tokio Runtime instance as a single object not wrapped in Arc
kevinaboos Aug 13, 2025
06a47e2
Merge branch 'main' into fix-logout
TigerInYourDream Aug 18, 2025
b4a3236
clippy
TigerInYourDream Aug 18, 2025
24c4102
improve code by review comments and remove LOGOUT_IN_PROGRESS LOGOUT_…
TigerInYourDream Aug 19, 2025
474952a
Merge branch 'main' into fix-logout
TigerInYourDream Aug 20, 2025
c4dfbb4
fmt
TigerInYourDream Aug 20, 2025
6da968a
improve code and remove set Atomic flag in rest_state()
TigerInYourDream Aug 21, 2025
14dd45d
Merge branch 'main' into fix-logout
TigerInYourDream Aug 21, 2025
e41b8b8
use LogoutAction::InProgress
TigerInYourDream Aug 22, 2025
b40cada
Fix comment
kevinaboos Aug 22, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 58 additions & 16 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,25 @@ use std::collections::HashMap;
use makepad_widgets::{makepad_micro_serde::*, *};
use matrix_sdk::ruma::{OwnedRoomId, RoomId};
use crate::{
home::{
avatar_cache::clear_avatar_cache, home::{
main_desktop_ui::MainDesktopUiAction,
new_message_context_menu::NewMessageContextMenuWidgetRefExt,
room_screen::MessageAction,
rooms_list::RoomsListAction,
},
join_leave_room_modal::{
room_screen::{clear_timeline_states, MessageAction},
rooms_list::{clear_all_invited_rooms, RoomsListAction},
}, join_leave_room_modal::{
JoinLeaveRoomModalAction,
JoinLeaveRoomModalWidgetRefExt,
},
login::login_screen::LoginAction,
persistence,
shared::callout_tooltip::{
}, login::login_screen::LoginAction, logout::logout_confirm_modal::{LogoutAction, LogoutConfirmModalAction, LogoutConfirmModalWidgetRefExt}, persistence, profile::user_profile_cache::clear_user_profile_cache, shared::callout_tooltip::{
CalloutTooltipOptions,
CalloutTooltipWidgetRefExt,
TooltipAction,
},
sliding_sync::current_user_id,
utils::{
}, sliding_sync::current_user_id, utils::{
room_name_or_id,
OwnedRoomIdRon,
},
verification::VerificationAction,
verification_modal::{
}, verification::VerificationAction, verification_modal::{
VerificationModalAction,
VerificationModalWidgetRefExt,
},
}
};

live_design! {
Expand All @@ -48,6 +40,7 @@ live_design! {
use crate::verification_modal::VerificationModal;
use crate::join_leave_room_modal::JoinLeaveRoomModal;
use crate::login::login_screen::LoginScreen;
use crate::logout::logout_confirm_modal::LogoutConfirmModal;
use crate::shared::popup_list::*;
use crate::home::new_message_context_menu::*;
use crate::shared::callout_tooltip::CalloutTooltip;
Expand Down Expand Up @@ -119,6 +112,13 @@ live_design! {
}
}

// Logout confirmation modal
logout_confirm_modal = <Modal> {
content: {
logout_confirm_modal_inner = <LogoutConfirmModal> {}
}
}

// Tooltips must be shown in front of all other UI elements,
// since they can be shown as a hover atop any other widget.
app_tooltip = <CalloutTooltip> {}
Expand Down Expand Up @@ -171,6 +171,7 @@ impl LiveRegister for App {
crate::home::live_design(cx);
crate::profile::live_design(cx);
crate::login::live_design(cx);
crate::logout::live_design(cx);
}
}

Expand Down Expand Up @@ -210,6 +211,38 @@ impl MatchEvent for App {

fn handle_actions(&mut self, cx: &mut Cx, actions: &Actions) {
for action in actions {
if let Some(logout_modal_action) = action.downcast_ref::<LogoutConfirmModalAction>() {
match logout_modal_action {
LogoutConfirmModalAction::Open => {
self.ui.logout_confirm_modal(id!(logout_confirm_modal_inner)).reset_state(cx);
self.ui.modal(id!(logout_confirm_modal)).open(cx)
},
LogoutConfirmModalAction::Close { was_internal, .. } => {
if *was_internal {
self.ui.modal(id!(logout_confirm_modal)).close(cx);
}
},
_ => {}
}
}

if let Some(LogoutAction::LogoutSuccess) = action.downcast_ref() {
self.app_state.logged_in = false;
self.ui.modal(id!(logout_confirm_modal)).close(cx);
self.update_login_visibility(cx);
self.ui.redraw(cx);
continue;
}

if let Some(LogoutAction::ClearAppState { on_clear_appstate }) = action.downcast_ref() {
// Clear user profile cache, invited_rooms timeline states
clear_all_app_state(cx);
// Reset all app state to its default.
self.app_state = Default::default();
on_clear_appstate.notify_one();
continue;
}

if let Some(LoginAction::LoginSuccess) = action.downcast_ref() {
log!("Received LoginAction::LoginSuccess, hiding login view.");
self.app_state.logged_in = true;
Expand Down Expand Up @@ -363,6 +396,15 @@ impl MatchEvent for App {
}
}

/// Clears all thread-local UI caches (user profiles, invited rooms, and timeline states).
/// The `cx` parameter ensures that these thread-local caches are cleared on the main UI thread,
fn clear_all_app_state(cx: &mut Cx) {
clear_user_profile_cache(cx);
clear_all_invited_rooms(cx);
clear_timeline_states(cx);
clear_avatar_cache(cx);
}

impl AppMain for App {
fn handle_event(&mut self, cx: &mut Cx, event: &Event) {
// if let Event::WindowGeomChange(geom) = event {
Expand Down
9 changes: 9 additions & 0 deletions src/avatar_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,12 @@ pub fn get_or_fetch_avatar(
AvatarCacheEntry::Requested
})
}

/// Clears cached avatars.
/// This function requires passing in a reference to `Cx`,
/// which acts as a guarantee that this function must only be called by the main UI thread.
pub fn clear_avatar_cache(_cx: &mut Cx) {
AVATAR_NEW_CACHE.with_borrow_mut(|cache| {
cache.clear();
});
}
37 changes: 34 additions & 3 deletions src/home/main_desktop_ui.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use makepad_widgets::*;
use matrix_sdk::ruma::OwnedRoomId;
use std::collections::HashMap;
use tokio::sync::Notify;
use std::{collections::HashMap, sync::Arc};

use crate::{app::{AppState, AppStateAction, SelectedRoom}, utils::room_name_or_id};
use super::{invite_screen::InviteScreenWidgetRefExt, room_screen::RoomScreenWidgetRefExt, rooms_list::RoomsListAction};
Expand Down Expand Up @@ -216,6 +217,27 @@ impl MainDesktopUI {
self.open_rooms.remove(&tab_id);
}

/// Closes all tabs
pub fn close_all_tabs(&mut self, cx: &mut Cx) {
let dock = self.view.dock(id!(dock));
for tab_id in self.open_rooms.keys() {
dock.close_tab(cx, *tab_id);
}

dock.select_tab(cx, live_id!(home_tab));
cx.widget_action(
self.widget_uid(),
&HeapLiveIdPath::default(),
AppStateAction::FocusNone,
);

// Clear tab-related dock UI state.
self.open_rooms.clear();
self.tab_to_close = None;
self.room_order.clear();
self.most_recently_selected_room = None;
}

/// Replaces an invite with a joined room in the dock.
fn replace_invite_with_joined_room(
&mut self,
Expand Down Expand Up @@ -268,6 +290,12 @@ impl WidgetMatchEvent for MainDesktopUI {
for action in actions {
let widget_action = action.as_widget_action();

if let Some(MainDesktopUiAction::CloseAllTabs { on_close_all }) = action.downcast_ref() {
self.close_all_tabs(cx);
on_close_all.notify_one();
continue;
}

// Handle actions emitted by the dock within the MainDesktopUI
match widget_action.cast() { // TODO: don't we need to call `widget_uid_eq(dock.widget_uid())` here?
// Whenever a tab (except for the home_tab) is pressed, notify the app state.
Expand Down Expand Up @@ -404,11 +432,14 @@ impl WidgetMatchEvent for MainDesktopUI {
}

/// Actions sent to the MainDesktopUI widget for saving/restoring its dock state.
#[derive(Clone, Debug, DefaultNone)]
#[derive(Debug)]
pub enum MainDesktopUiAction {
/// Save the state of the dock into the AppState.
SaveDockIntoAppState,
/// Load the room panel state from the AppState to the dock.
LoadDockFromAppState,
None,
/// Close all tabs; see [`MainDesktopUI::close_all_tabs()`]
CloseAllTabs {
on_close_all: Arc<Notify>,
},
}
12 changes: 12 additions & 0 deletions src/home/room_screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4387,3 +4387,15 @@ impl MessageRef {
inner.set_data(details);
}
}

/// Clears all UI-related timeline states for all known rooms.
///
/// This function requires passing in a reference to `Cx`,
/// which isn't used, but acts as a guarantee that this function
/// must only be called by the main UI thread.
pub fn clear_timeline_states(_cx: &mut Cx) {
// Clear timeline states cache
TIMELINE_STATES.with_borrow_mut(|states| {
states.clear();
});
}
11 changes: 11 additions & 0 deletions src/home/rooms_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@ pub fn get_invited_rooms(_cx: &mut Cx) -> Rc<RefCell<HashMap<OwnedRoomId, Invite
ALL_INVITED_ROOMS.with(Rc::clone)
}

/// Clears all invited rooms
///
/// This function requires passing in a reference to `Cx`,
/// which isn't used, but acts as a guarantee that this function
/// must only be called by the main UI thread.
pub fn clear_all_invited_rooms(_cx: &mut Cx) {
ALL_INVITED_ROOMS.with(|rooms| {
rooms.borrow_mut().clear();
});
}


live_design! {
use link::theme::*;
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ pub mod settings;

/// Login screen
pub mod login;
/// Logout confirmation and state management
pub mod logout;
/// Core UI content: the main home screen (rooms list), room screen.
pub mod home;
/// User profile info and a user profile sliding pane.
Expand Down
Loading