One Armed state asks again before log out, leave, remove friend, delete user/account/community (menus + Ctrl+K)
Browse files at this commitba41270289b42cf1251e9646ad9ad221ce770cc9Parent: 073ad59- feat
- one Armed state asks again before log out, leave, remove friend, delete user/account/community (menus + Ctrl+K)
- Danger zone is its own settings section, log out/leave left in their menus
- single instance per config dir (second launch shows the running window), --multi skips it
19 changed files +281 -156
- crates/client/lang/en/common.txt +1 -0
- crates/client/lang/en/community_settings.txt +0 -1
- crates/client/lang/en/profile.txt +0 -1
- crates/client/lang/en/settings_page.txt +1 -2
- crates/client/lang/tr/common.txt +1 -0
- crates/client/lang/tr/community_settings.txt +0 -1
- crates/client/lang/tr/profile.txt +0 -1
- crates/client/lang/tr/settings_page.txt +1 -2
- crates/client/src/gui.rs +29 -1
- crates/client/src/gui/chat.rs +12 -10
- crates/client/src/gui/community_card.rs +13 -6
- crates/client/src/gui/community_settings.rs +7 -29
- crates/client/src/gui/jump.rs +10 -2
- crates/client/src/gui/profile.rs +23 -24
- crates/client/src/gui/settings_page.rs +32 -61
- crates/client/src/gui/sidebar.rs +28 -15
- crates/client/src/instance.rs +109 -0
- crates/client/src/lib.rs +1 -0
- crates/client/src/main.rs +13 -0
crates/client/lang/en/common.txtmodified+1 -0
| @@ -22,3 +22,4 @@ more = {count} more | |||
| 22 | messages = Messages | 22 | messages = Messages |
| 23 | no_users = No users | 23 | no_users = No users |
| 24 | no_bans = No bans | 24 | no_bans = No bans |
| 25 | +confirm = Confirm | ||
crates/client/lang/en/community_settings.txtmodified+0 -1
| @@ -5,7 +5,6 @@ voice = Voice | |||
| 5 | bans = Bans | 5 | bans = Bans |
| 6 | logs = Logs | 6 | logs = Logs |
| 7 | moderation = Moderation | 7 | moderation = Moderation |
| 8 | -leave_community = Leave community | ||
| 9 | delete_community = Delete community | 8 | delete_community = Delete community |
| 10 | newest = Newest | 9 | newest = Newest |
| 11 | oldest = Oldest | 10 | oldest = Oldest |
crates/client/lang/en/profile.txtmodified+0 -1
| @@ -6,7 +6,6 @@ kick = Kick | |||
| 6 | ban = Ban | 6 | ban = Ban |
| 7 | make_rank = Make {rank} | 7 | make_rank = Make {rank} |
| 8 | delete_user = Delete user | 8 | delete_user = Delete user |
| 9 | -confirm = Confirm | ||
| 10 | a_call = a call | 9 | a_call = a call |
| 11 | in_room = in {room} | 10 | in_room = in {room} |
| 12 | edit_status = Edit status | 11 | edit_status = Edit status |
crates/client/lang/en/settings_page.txtmodified+1 -2
| @@ -7,9 +7,8 @@ identity = Identity | |||
| 7 | name = Name | 7 | name = Name |
| 8 | status = Status | 8 | status = Status |
| 9 | presence = Presence | 9 | presence = Presence |
| 10 | -log_out = Log out | 10 | +danger_zone = Danger zone |
| 11 | delete_account = Delete account | 11 | delete_account = Delete account |
| 12 | -confirm = Confirm | ||
| 13 | save = Save | 12 | save = Save |
| 14 | remove = Remove | 13 | remove = Remove |
| 15 | change_picture = Change picture | 14 | change_picture = Change picture |
crates/client/lang/tr/common.txtmodified+1 -0
| @@ -22,3 +22,4 @@ more = {count} daha | |||
| 22 | messages = Mesajlar | 22 | messages = Mesajlar |
| 23 | no_users = Kullanıcı yok | 23 | no_users = Kullanıcı yok |
| 24 | no_bans = Yasak yok | 24 | no_bans = Yasak yok |
| 25 | +confirm = Onayla | ||
crates/client/lang/tr/community_settings.txtmodified+0 -1
| @@ -5,7 +5,6 @@ voice = Ses | |||
| 5 | bans = Yasaklar | 5 | bans = Yasaklar |
| 6 | logs = Kayıtlar | 6 | logs = Kayıtlar |
| 7 | moderation = Moderasyon | 7 | moderation = Moderasyon |
| 8 | -leave_community = Topluluktan ayrıl | ||
| 9 | delete_community = Topluluğu sil | 8 | delete_community = Topluluğu sil |
| 10 | newest = En yeni | 9 | newest = En yeni |
| 11 | oldest = En eski | 10 | oldest = En eski |
crates/client/lang/tr/profile.txtmodified+0 -1
| @@ -6,7 +6,6 @@ kick = Çıkar | |||
| 6 | ban = Yasakla | 6 | ban = Yasakla |
| 7 | make_rank = {rank} yap | 7 | make_rank = {rank} yap |
| 8 | delete_user = Kullanıcıyı sil | 8 | delete_user = Kullanıcıyı sil |
| 9 | -confirm = Onayla | ||
| 10 | a_call = bir arama | 9 | a_call = bir arama |
| 11 | in_room = {room} içinde | 10 | in_room = {room} içinde |
| 12 | edit_status = Durumu düzenle | 11 | edit_status = Durumu düzenle |
crates/client/lang/tr/settings_page.txtmodified+1 -2
| @@ -7,9 +7,8 @@ identity = Kimlik | |||
| 7 | name = Ad | 7 | name = Ad |
| 8 | status = Durum | 8 | status = Durum |
| 9 | presence = Görünürlük | 9 | presence = Görünürlük |
| 10 | -log_out = Çıkış yap | 10 | +danger_zone = Tehlikeli bölge |
| 11 | delete_account = Hesabı sil | 11 | delete_account = Hesabı sil |
| 12 | -confirm = Onayla | ||
| 13 | save = Kaydet | 12 | save = Kaydet |
| 14 | remove = Kaldır | 13 | remove = Kaldır |
| 15 | change_picture = Resmi değiştir | 14 | change_picture = Resmi değiştir |
crates/client/src/gui.rsmodified+29 -1
| @@ -829,6 +829,34 @@ impl Yumush { | |||
| 829 | cx.notify(); | 829 | cx.notify(); |
| 830 | } | 830 | } |
| 831 | 831 | ||
| 832 | + pub(super) fn armed(&self, armed: chat::Armed) -> bool { | ||
| 833 | + self.chat.armed == Some(armed) | ||
| 834 | + } | ||
| 835 | + | ||
| 836 | + pub(super) fn armed_label(&self, armed: chat::Armed, label: &'static str) -> &'static str { | ||
| 837 | + if self.armed(armed) { | ||
| 838 | + w().common.confirm | ||
| 839 | + } else { | ||
| 840 | + label | ||
| 841 | + } | ||
| 842 | + } | ||
| 843 | + | ||
| 844 | + pub(super) fn arm(&mut self, armed: chat::Armed, cx: &mut Context<Self>) -> bool { | ||
| 845 | + if self.armed(armed) { | ||
| 846 | + self.chat.armed = None; | ||
| 847 | + return true; | ||
| 848 | + } | ||
| 849 | + self.chat.armed = Some(armed); | ||
| 850 | + cx.notify(); | ||
| 851 | + false | ||
| 852 | + } | ||
| 853 | + | ||
| 854 | + pub(super) fn disarm(&mut self, cx: &mut Context<Self>) { | ||
| 855 | + if self.chat.armed.take().is_some() { | ||
| 856 | + cx.notify(); | ||
| 857 | + } | ||
| 858 | + } | ||
| 859 | + | ||
| 832 | fn logout(&mut self, window: &mut Window, cx: &mut Context<Self>) { | 860 | fn logout(&mut self, window: &mut Window, cx: &mut Context<Self>) { |
| 833 | let Some(user) = self.user.clone() else { | 861 | let Some(user) = self.user.clone() else { |
| 834 | return; | 862 | return; |
| @@ -890,7 +918,7 @@ impl Yumush { | |||
| 890 | } | 918 | } |
| 891 | 919 | ||
| 892 | self.chat.view = view; | 920 | self.chat.view = view; |
| 893 | - self.chat.delete_step = chat::DeleteStep::Idle; | 921 | + self.chat.armed = None; |
| 894 | if view == View::Chat { | 922 | if view == View::Chat { |
| 895 | self.chat.focus(window, cx); | 923 | self.chat.focus(window, cx); |
| 896 | } | 924 | } |
crates/client/src/gui/chat.rsmodified+12 -10
| @@ -82,9 +82,13 @@ pub enum View { | |||
| 82 | } | 82 | } |
| 83 | 83 | ||
| 84 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] | 84 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| 85 | -pub enum DeleteStep { | 85 | +pub enum Armed { |
| 86 | - Idle, | 86 | + LogOut, |
| 87 | - Confirm, | 87 | + Leave(Id), |
| 88 | + RemoveFriend(Id), | ||
| 89 | + DeleteUser(Id), | ||
| 90 | + DeleteAccount, | ||
| 91 | + DeleteCommunity, | ||
| 88 | } | 92 | } |
| 89 | 93 | ||
| 90 | #[derive(Debug, Clone, PartialEq, Eq)] | 94 | #[derive(Debug, Clone, PartialEq, Eq)] |
| @@ -177,7 +181,7 @@ pub struct Chat { | |||
| 177 | pub(super) avatar_requests: HashSet<Id>, | 181 | pub(super) avatar_requests: HashSet<Id>, |
| 178 | pub(super) users: HashMap<Id, User>, | 182 | pub(super) users: HashMap<Id, User>, |
| 179 | user_requests: HashSet<Id>, | 183 | user_requests: HashSet<Id>, |
| 180 | - pub(super) delete_step: DeleteStep, | 184 | + pub(super) armed: Option<Armed>, |
| 181 | pub(super) bans: Vec<Ban>, | 185 | pub(super) bans: Vec<Ban>, |
| 182 | pub(super) ban_search: Entity<InputState>, | 186 | pub(super) ban_search: Entity<InputState>, |
| 183 | pub(super) ban_sort: BanSort, | 187 | pub(super) ban_sort: BanSort, |
| @@ -186,7 +190,6 @@ pub struct Chat { | |||
| 186 | pub(super) log_sort: LogSort, | 190 | pub(super) log_sort: LogSort, |
| 187 | pub(super) friends: Friends, | 191 | pub(super) friends: Friends, |
| 188 | pub(super) invitations: Vec<Invitation>, | 192 | pub(super) invitations: Vec<Invitation>, |
| 189 | - pub(super) pending_user_delete: Option<Id>, | ||
| 190 | pub(super) card_menu: CardMenu, | 193 | pub(super) card_menu: CardMenu, |
| 191 | pub(super) presences: HashMap<Id, Presence>, | 194 | pub(super) presences: HashMap<Id, Presence>, |
| 192 | pub(super) slowed_until: Option<u64>, | 195 | pub(super) slowed_until: Option<u64>, |
| @@ -459,8 +462,7 @@ impl Chat { | |||
| 459 | avatar_requests: HashSet::new(), | 462 | avatar_requests: HashSet::new(), |
| 460 | users: HashMap::new(), | 463 | users: HashMap::new(), |
| 461 | user_requests: HashSet::new(), | 464 | user_requests: HashSet::new(), |
| 462 | - delete_step: DeleteStep::Idle, | 465 | + armed: None, |
| 463 | - pending_user_delete: None, | ||
| 464 | card_menu: CardMenu::Main, | 466 | card_menu: CardMenu::Main, |
| 465 | presences: HashMap::new(), | 467 | presences: HashMap::new(), |
| 466 | slowed_until: None, | 468 | slowed_until: None, |
| @@ -842,7 +844,7 @@ impl Chat { | |||
| 842 | } | 844 | } |
| 843 | if self.view == View::CommunitySettings { | 845 | if self.view == View::CommunitySettings { |
| 844 | self.view = View::Chat; | 846 | self.view = View::Chat; |
| 845 | - self.delete_step = DeleteStep::Idle; | 847 | + self.armed = None; |
| 846 | } | 848 | } |
| 847 | self.selected_community_id = community_id; | 849 | self.selected_community_id = community_id; |
| 848 | self.users.extend( | 850 | self.users.extend( |
| @@ -852,7 +854,7 @@ impl Chat { | |||
| 852 | ); | 854 | ); |
| 853 | self.bans.clear(); | 855 | self.bans.clear(); |
| 854 | self.logs.clear(); | 856 | self.logs.clear(); |
| 855 | - self.pending_user_delete = None; | 857 | + self.armed = None; |
| 856 | self.messages.clear(); | 858 | self.messages.clear(); |
| 857 | self.jump = None; | 859 | self.jump = None; |
| 858 | self.pins.clear(); | 860 | self.pins.clear(); |
| @@ -1259,7 +1261,7 @@ impl Chat { | |||
| 1259 | self.builder_invites.clear(); | 1261 | self.builder_invites.clear(); |
| 1260 | self.pending_invite_delete = None; | 1262 | self.pending_invite_delete = None; |
| 1261 | self.view = View::Chat; | 1263 | self.view = View::Chat; |
| 1262 | - self.delete_step = DeleteStep::Idle; | 1264 | + self.armed = None; |
| 1263 | self.voice.clear(); | 1265 | self.voice.clear(); |
| 1264 | self.server_muted.clear(); | 1266 | self.server_muted.clear(); |
| 1265 | self.builder_voice_rooms.clear(); | 1267 | self.builder_voice_rooms.clear(); |
crates/client/src/gui/community_card.rsmodified+13 -6
| @@ -11,8 +11,9 @@ use gpui_kit::{ | |||
| 11 | px, | 11 | px, |
| 12 | }; | 12 | }; |
| 13 | 13 | ||
| 14 | +use super::chat::Armed; | ||
| 14 | use super::parts::{Ink, Text, band, small_icon, stack, words}; | 15 | use super::parts::{Ink, Text, band, small_icon, stack, words}; |
| 15 | -use super::profile::{menu_row, yumush_action}; | 16 | +use super::profile::{armed_action, menu_row, yumush_action}; |
| 16 | use super::style::{size, space, stroke, text}; | 17 | use super::style::{size, space, stroke, text}; |
| 17 | use super::{Palette, Trigger, Yumush, text}; | 18 | use super::{Palette, Trigger, Yumush, text}; |
| 18 | use crate::lang::w; | 19 | use crate::lang::w; |
| @@ -26,9 +27,11 @@ pub(super) fn community_popover( | |||
| 26 | let community = community.clone(); | 27 | let community = community.clone(); |
| 27 | let entity = entity.clone(); | 28 | let entity = entity.clone(); |
| 28 | 29 | ||
| 30 | + let disarm = entity.clone(); | ||
| 29 | Popover::new("community_card") | 31 | Popover::new("community_card") |
| 30 | .anchor(Anchor::TopLeft) | 32 | .anchor(Anchor::TopLeft) |
| 31 | .appearance(false) | 33 | .appearance(false) |
| 34 | + .on_open_change(move |_, _, cx| disarm.update(cx, |yumush, cx| yumush.disarm(cx))) | ||
| 32 | .trigger(Trigger::new(trigger)) | 35 | .trigger(Trigger::new(trigger)) |
| 33 | .content(move |_, _, cx| { | 36 | .content(move |_, _, cx| { |
| 34 | let popover = cx.entity(); | 37 | let popover = cx.entity(); |
| @@ -164,12 +167,16 @@ pub(super) fn room_rows( | |||
| 164 | |yumush, id, _, cx| yumush.toggle_mark(Mark::Mute, id, cx), | 167 | |yumush, id, _, cx| yumush.toggle_mark(Mark::Mute, id, cx), |
| 165 | )) | 168 | )) |
| 166 | .when(can_leave, |this| { | 169 | .when(can_leave, |this| { |
| 167 | - this.child(row( | 170 | + let armed = Armed::Leave(id); |
| 168 | - "room_leave", | 171 | + this.child(menu_row( |
| 169 | - words.leave, | 172 | + ("room_leave", id as usize), |
| 170 | - IconName::LogOut, | 173 | + yumush.armed_label(armed, words.leave), |
| 174 | + small_icon(IconName::LogOut), | ||
| 171 | palette.danger, | 175 | palette.danger, |
| 172 | - |yumush, id, window, cx| yumush.leave_community(id, window, cx), | 176 | + palette, |
| 177 | + armed_action(armed, entity, popover, move |yumush, window, cx| { | ||
| 178 | + yumush.leave_community(id, window, cx) | ||
| 179 | + }), | ||
| 173 | )) | 180 | )) |
| 174 | }) | 181 | }) |
| 175 | } | 182 | } |
crates/client/src/gui/community_settings.rsmodified+7 -29
| @@ -20,12 +20,12 @@ use gpui_kit::{ | |||
| 20 | 20 | ||
| 21 | use super::{ | 21 | use super::{ |
| 22 | Palette, Yumush, avatar, | 22 | Palette, Yumush, avatar, |
| 23 | - chat::View, | 23 | + chat::{Armed, View}, |
| 24 | clickable, community_icon, entity_action, millis_time, notify_error, | 24 | clickable, community_icon, entity_action, millis_time, notify_error, |
| 25 | profile::user_link, | 25 | profile::user_link, |
| 26 | settings_page::{ | 26 | settings_page::{ |
| 27 | - Editable, Picture, Section, delete_control, page, picked_avatar, picture_card, row, | 27 | + Editable, Picture, Section, danger, delete_control, page, picked_avatar, picture_card, row, |
| 28 | - section, small_button, text_row, with_danger, | 28 | + section, small_button, text_row, |
| 29 | }, | 29 | }, |
| 30 | style::{radius, size, space, text as text_token}, | 30 | style::{radius, size, space, text as text_token}, |
| 31 | text, | 31 | text, |
| @@ -182,28 +182,22 @@ impl Yumush { | |||
| 182 | moderation, | 182 | moderation, |
| 183 | )); | 183 | )); |
| 184 | } | 184 | } |
| 185 | - let mut danger = Vec::new(); | ||
| 186 | - if let Some(community) = community.filter(|_| permission::can_leave(actor)) { | ||
| 187 | - danger.push(leave_control(entity, community.id, palette).into_any_element()); | ||
| 188 | - } | ||
| 189 | if permission::can_delete_community(actor) { | 185 | if permission::can_delete_community(actor) { |
| 190 | - danger.push( | 186 | + sections.push(danger(vec![ |
| 191 | delete_control( | 187 | delete_control( |
| 192 | "delete_community_button", | 188 | "delete_community_button", |
| 193 | w().community_settings.delete_community, | 189 | w().community_settings.delete_community, |
| 194 | - self.chat.delete_step, | 190 | + self.armed(Armed::DeleteCommunity), |
| 195 | entity, | 191 | entity, |
| 196 | palette, | 192 | palette, |
| 197 | Yumush::delete_community, | 193 | Yumush::delete_community, |
| 198 | ) | 194 | ) |
| 199 | .into_any_element(), | 195 | .into_any_element(), |
| 200 | - ); | 196 | + ])); |
| 201 | } | 197 | } |
| 202 | if sections.is_empty() { | 198 | if sections.is_empty() { |
| 203 | sections.push(section(w().community_settings.general, palette, Vec::new())); | 199 | sections.push(section(w().community_settings.general, palette, Vec::new())); |
| 204 | } | 200 | } |
| 205 | - let first = sections.remove(0); | ||
| 206 | - sections.insert(0, with_danger(first, danger)); | ||
| 207 | 201 | ||
| 208 | page( | 202 | page( |
| 209 | "community_settings_scroll", | 203 | "community_settings_scroll", |
| @@ -309,7 +303,7 @@ impl Yumush { | |||
| 309 | } | 303 | } |
| 310 | 304 | ||
| 311 | pub(super) fn delete_community(&mut self, window: &mut Window, cx: &mut Context<Self>) { | 305 | pub(super) fn delete_community(&mut self, window: &mut Window, cx: &mut Context<Self>) { |
| 312 | - if !self.confirm_delete(cx) { | 306 | + if !self.arm(Armed::DeleteCommunity, cx) { |
| 313 | return; | 307 | return; |
| 314 | } | 308 | } |
| 315 | let Some(community_id) = self.chat.selected_community_id else { | 309 | let Some(community_id) = self.chat.selected_community_id else { |
| @@ -667,22 +661,6 @@ fn log_row(entry: &LogEntry, palette: Palette, avatars: &HashMap<Id, Arc<Image>> | |||
| 667 | ) | 661 | ) |
| 668 | } | 662 | } |
| 669 | 663 | ||
| 670 | -fn leave_control(entity: &Entity<Yumush>, community_id: Id, palette: Palette) -> impl IntoElement { | ||
| 671 | - let entity = entity.clone(); | ||
| 672 | - | ||
| 673 | - small_button( | ||
| 674 | - "leave_community_button", | ||
| 675 | - palette, | ||
| 676 | - palette.danger, | ||
| 677 | - move |window, cx| { | ||
| 678 | - entity.update(cx, |yumush, cx| { | ||
| 679 | - yumush.leave_community(community_id, window, cx) | ||
| 680 | - }); | ||
| 681 | - }, | ||
| 682 | - ) | ||
| 683 | - .child(w().community_settings.leave_community) | ||
| 684 | -} | ||
| 685 | - | ||
| 686 | fn ban_row( | 664 | fn ban_row( |
| 687 | ban: &Ban, | 665 | ban: &Ban, |
| 688 | entity: &Entity<Yumush>, | 666 | entity: &Entity<Yumush>, |
crates/client/src/gui/jump.rsmodified+10 -2
| @@ -14,7 +14,7 @@ use gpui_kit::{ | |||
| 14 | use super::{ | 14 | use super::{ |
| 15 | Palette, Yumush, avatar, | 15 | Palette, Yumush, avatar, |
| 16 | builder::BuilderTab, | 16 | builder::BuilderTab, |
| 17 | - chat::View, | 17 | + chat::{Armed, View}, |
| 18 | community_icon, community_name, | 18 | community_icon, community_name, |
| 19 | parts::{Ink, Text, band, words}, | 19 | parts::{Ink, Text, band, words}, |
| 20 | presence_avatar, | 20 | presence_avatar, |
| @@ -333,7 +333,11 @@ impl Yumush { | |||
| 333 | Glyph::Icon(IconName::Circle), | 333 | Glyph::Icon(IconName::Circle), |
| 334 | ) | 334 | ) |
| 335 | })) | 335 | })) |
| 336 | - .chain([action(Place::LogOut, w().jump.log_out, IconName::LogOut)]); | 336 | + .chain([action( |
| 337 | + Place::LogOut, | ||
| 338 | + self.armed_label(Armed::LogOut, w().jump.log_out), | ||
| 339 | + IconName::LogOut, | ||
| 340 | + )]); | ||
| 337 | let mut found: Vec<_> = rooms | 341 | let mut found: Vec<_> = rooms |
| 338 | .chain(people) | 342 | .chain(people) |
| 339 | .chain(pages) | 343 | .chain(pages) |
| @@ -364,6 +368,7 @@ impl Yumush { | |||
| 364 | 368 | ||
| 365 | pub(super) fn close_jump(&mut self, window: &mut Window, cx: &mut Context<Self>) { | 369 | pub(super) fn close_jump(&mut self, window: &mut Window, cx: &mut Context<Self>) { |
| 366 | self.chat.goto.open = false; | 370 | self.chat.goto.open = false; |
| 371 | + self.chat.armed = None; | ||
| 367 | window.focus(&self.focus, cx); | 372 | window.focus(&self.focus, cx); |
| 368 | cx.notify(); | 373 | cx.notify(); |
| 369 | } | 374 | } |
| @@ -391,6 +396,9 @@ impl Yumush { | |||
| 391 | } | 396 | } |
| 392 | 397 | ||
| 393 | fn pick(&mut self, place: Place, window: &mut Window, cx: &mut Context<Self>) { | 398 | fn pick(&mut self, place: Place, window: &mut Window, cx: &mut Context<Self>) { |
| 399 | + if place == Place::LogOut && !self.arm(Armed::LogOut, cx) { | ||
| 400 | + return; | ||
| 401 | + } | ||
| 394 | self.close_jump(window, cx); | 402 | self.close_jump(window, cx); |
| 395 | *self.settings.jump_usage.entry(place.key()).or_default() += 1; | 403 | *self.settings.jump_usage.entry(place.key()).or_default() += 1; |
| 396 | crate::settings::save(&self.settings); | 404 | crate::settings::save(&self.settings); |
crates/client/src/gui/profile.rsmodified+23 -24
| @@ -25,7 +25,7 @@ use gpui_kit::{ | |||
| 25 | div, px, | 25 | div, px, |
| 26 | }; | 26 | }; |
| 27 | 27 | ||
| 28 | -use super::chat::{CardMenu, ReportTarget, View}; | 28 | +use super::chat::{Armed, CardMenu, ReportTarget, View}; |
| 29 | use super::message_actions::report_bar; | 29 | use super::message_actions::report_bar; |
| 30 | use super::parts::{ | 30 | use super::parts::{ |
| 31 | Ink, Scale, Text, Tone, Voice, band, icon_button, small_icon, stack, voice_line, words, | 31 | Ink, Scale, Text, Tone, Voice, band, icon_button, small_icon, stack, voice_line, words, |
| @@ -92,7 +92,7 @@ pub(super) fn profile_popover( | |||
| 92 | .on_open_change(move |_, _, cx| { | 92 | .on_open_change(move |_, _, cx| { |
| 93 | notify_entity.update(cx, |yumush, cx| { | 93 | notify_entity.update(cx, |yumush, cx| { |
| 94 | yumush.chat.card_menu = CardMenu::Main; | 94 | yumush.chat.card_menu = CardMenu::Main; |
| 95 | - yumush.chat.pending_user_delete = None; | 95 | + yumush.chat.armed = None; |
| 96 | yumush.open_user_volume(volume_user_id, cx); | 96 | yumush.open_user_volume(volume_user_id, cx); |
| 97 | cx.notify() | 97 | cx.notify() |
| 98 | }) | 98 | }) |
| @@ -107,7 +107,7 @@ pub(super) fn profile_popover( | |||
| 107 | relation: yumush.relation(user.id), | 107 | relation: yumush.relation(user.id), |
| 108 | card_menu: yumush.chat.card_menu, | 108 | card_menu: yumush.chat.card_menu, |
| 109 | presence: yumush.presence_of(user.id), | 109 | presence: yumush.presence_of(user.id), |
| 110 | - confirming: yumush.chat.pending_user_delete == Some(user.id), | 110 | + armed: yumush.chat.armed, |
| 111 | reporting: yumush.chat.report == Some(ReportTarget::User(user.id)), | 111 | reporting: yumush.chat.report == Some(ReportTarget::User(user.id)), |
| 112 | reason: yumush.chat.report_reason.clone(), | 112 | reason: yumush.chat.report_reason.clone(), |
| 113 | status: yumush.chat.status_input.clone(), | 113 | status: yumush.chat.status_input.clone(), |
| @@ -144,7 +144,7 @@ struct Card { | |||
| 144 | relation: Relation, | 144 | relation: Relation, |
| 145 | card_menu: CardMenu, | 145 | card_menu: CardMenu, |
| 146 | presence: Presence, | 146 | presence: Presence, |
| 147 | - confirming: bool, | 147 | + armed: Option<Armed>, |
| 148 | reporting: bool, | 148 | reporting: bool, |
| 149 | reason: Entity<InputState>, | 149 | reason: Entity<InputState>, |
| 150 | status: Entity<InputState>, | 150 | status: Entity<InputState>, |
| @@ -241,6 +241,7 @@ impl Card { | |||
| 241 | self.viewer | 241 | self.viewer |
| 242 | .as_ref() | 242 | .as_ref() |
| 243 | .is_some_and(|viewer| permission::is_builder(viewer.role)), | 243 | .is_some_and(|viewer| permission::is_builder(viewer.role)), |
| 244 | + self.armed, | ||
| 244 | entity, | 245 | entity, |
| 245 | &popover, | 246 | &popover, |
| 246 | palette, | 247 | palette, |
| @@ -554,8 +555,9 @@ impl Card { | |||
| 554 | .as_ref() | 555 | .as_ref() |
| 555 | .is_some_and(|viewer| permission::can_delete_user(viewer.role, false, self.user.role)); | 556 | .is_some_and(|viewer| permission::can_delete_user(viewer.role, false, self.user.role)); |
| 556 | if deletable { | 557 | if deletable { |
| 557 | - let label = if self.confirming { | 558 | + let armed = Armed::DeleteUser(user_id); |
| 558 | - w().profile.confirm | 559 | + let label = if self.armed == Some(armed) { |
| 560 | + w().common.confirm | ||
| 559 | } else { | 561 | } else { |
| 560 | w().profile.delete_user | 562 | w().profile.delete_user |
| 561 | }; | 563 | }; |
| @@ -567,7 +569,9 @@ impl Card { | |||
| 567 | small_icon(IconName::Trash), | 569 | small_icon(IconName::Trash), |
| 568 | palette.danger, | 570 | palette.danger, |
| 569 | palette, | 571 | palette, |
| 570 | - delete_user_action(user_id, self.confirming, entity, popover), | 572 | + armed_action(armed, entity, popover, move |yumush, window, cx| { |
| 573 | + yumush.delete_member_account(user_id, window, cx) | ||
| 574 | + }), | ||
| 571 | ) | 575 | ) |
| 572 | .into_any_element(), | 576 | .into_any_element(), |
| 573 | ); | 577 | ); |
| @@ -579,6 +583,7 @@ impl Card { | |||
| 579 | 583 | ||
| 580 | fn main_self_rows( | 584 | fn main_self_rows( |
| 581 | builder: bool, | 585 | builder: bool, |
| 586 | + armed: Option<Armed>, | ||
| 582 | entity: &Entity<Yumush>, | 587 | entity: &Entity<Yumush>, |
| 583 | popover: &Entity<PopoverState>, | 588 | popover: &Entity<PopoverState>, |
| 584 | palette: Palette, | 589 | palette: Palette, |
| @@ -614,11 +619,15 @@ fn main_self_rows( | |||
| 614 | rows.push( | 619 | rows.push( |
| 615 | menu_row( | 620 | menu_row( |
| 616 | "profile_logout", | 621 | "profile_logout", |
| 617 | - w().profile.log_out, | 622 | + if armed == Some(Armed::LogOut) { |
| 623 | + w().common.confirm | ||
| 624 | + } else { | ||
| 625 | + w().profile.log_out | ||
| 626 | + }, | ||
| 618 | small_icon(IconName::LogOut), | 627 | small_icon(IconName::LogOut), |
| 619 | palette.danger, | 628 | palette.danger, |
| 620 | palette, | 629 | palette, |
| 621 | - yumush_action(entity, popover, |yumush, window, cx| { | 630 | + armed_action(Armed::LogOut, entity, popover, |yumush, window, cx| { |
| 622 | yumush.logout(window, cx) | 631 | yumush.logout(window, cx) |
| 623 | }), | 632 | }), |
| 624 | ) | 633 | ) |
| @@ -711,23 +720,19 @@ pub(super) fn yumush_action( | |||
| 711 | } | 720 | } |
| 712 | } | 721 | } |
| 713 | 722 | ||
| 714 | -fn delete_user_action( | 723 | +pub(super) fn armed_action( |
| 715 | - user_id: Id, | 724 | + armed: Armed, |
| 716 | - confirming: bool, | ||
| 717 | entity: &Entity<Yumush>, | 725 | entity: &Entity<Yumush>, |
| 718 | popover: &Entity<PopoverState>, | 726 | popover: &Entity<PopoverState>, |
| 727 | + run: impl Fn(&mut Yumush, &mut Window, &mut Context<Yumush>) + 'static, | ||
| 719 | ) -> impl Fn(&mut Window, &mut App) + 'static { | 728 | ) -> impl Fn(&mut Window, &mut App) + 'static { |
| 720 | let entity = entity.clone(); | 729 | let entity = entity.clone(); |
| 721 | let popover = popover.clone(); | 730 | let popover = popover.clone(); |
| 722 | 731 | ||
| 723 | move |window, cx| { | 732 | move |window, cx| { |
| 724 | - if confirming { | 733 | + if entity.update(cx, |yumush, cx| yumush.arm(armed, cx)) { |
| 725 | popover.update(cx, |state, cx| state.dismiss(window, cx)); | 734 | popover.update(cx, |state, cx| state.dismiss(window, cx)); |
| 726 | - entity.update(cx, |yumush, cx| { | 735 | + entity.update(cx, |yumush, cx| run(yumush, window, cx)); |
| 727 | - yumush.delete_member_account(user_id, window, cx) | ||
| 728 | - }); | ||
| 729 | - } else { | ||
| 730 | - entity.update(cx, |yumush, cx| yumush.request_member_delete(user_id, cx)); | ||
| 731 | } | 736 | } |
| 732 | } | 737 | } |
| 733 | } | 738 | } |
| @@ -925,18 +930,12 @@ impl Yumush { | |||
| 925 | }); | 930 | }); |
| 926 | } | 931 | } |
| 927 | 932 | ||
| 928 | - pub(super) fn request_member_delete(&mut self, user_id: Id, cx: &mut Context<Self>) { | ||
| 929 | - self.chat.pending_user_delete = Some(user_id); | ||
| 930 | - cx.notify(); | ||
| 931 | - } | ||
| 932 | - | ||
| 933 | pub(super) fn delete_member_account( | 933 | pub(super) fn delete_member_account( |
| 934 | &mut self, | 934 | &mut self, |
| 935 | user_id: Id, | 935 | user_id: Id, |
| 936 | window: &mut Window, | 936 | window: &mut Window, |
| 937 | cx: &mut Context<Self>, | 937 | cx: &mut Context<Self>, |
| 938 | ) { | 938 | ) { |
| 939 | - self.chat.pending_user_delete = None; | ||
| 940 | let network = self.network.clone(); | 939 | let network = self.network.clone(); |
| 941 | 940 | ||
| 942 | cx.spawn_in(window, async move |this, cx| { | 941 | cx.spawn_in(window, async move |this, cx| { |
crates/client/src/gui/settings_page.rsmodified+32 -61
| @@ -16,7 +16,7 @@ use gpui_kit::{ | |||
| 16 | 16 | ||
| 17 | use super::{ | 17 | use super::{ |
| 18 | Palette, Tooltip as _, Yumush, avatar, | 18 | Palette, Tooltip as _, Yumush, avatar, |
| 19 | - chat::DeleteStep, | 19 | + chat::Armed, |
| 20 | chat::View, | 20 | chat::View, |
| 21 | clickable, notify_error, parts, | 21 | clickable, notify_error, parts, |
| 22 | share_view::{AudioMode, FPS, RESOLUTIONS, codecs, share_modes}, | 22 | share_view::{AudioMode, FPS, RESOLUTIONS, codecs, share_modes}, |
| @@ -31,9 +31,15 @@ use crate::{ | |||
| 31 | 31 | ||
| 32 | pub(super) const SETTINGS_IDS: [&str; 4] = ["profile", "voice", "camera_share", "appearance"]; | 32 | pub(super) const SETTINGS_IDS: [&str; 4] = ["profile", "voice", "camera_share", "appearance"]; |
| 33 | 33 | ||
| 34 | -pub(super) fn settings_titles() -> [&'static str; 4] { | 34 | +pub(super) fn settings_titles() -> [&'static str; 5] { |
| 35 | let w = &w().settings_page; | 35 | let w = &w().settings_page; |
| 36 | - [w.profile, w.voice, w.camera_share, w.appearance] | 36 | + [ |
| 37 | + w.profile, | ||
| 38 | + w.voice, | ||
| 39 | + w.camera_share, | ||
| 40 | + w.appearance, | ||
| 41 | + w.danger_zone, | ||
| 42 | + ] | ||
| 37 | } | 43 | } |
| 38 | 44 | ||
| 39 | pub(super) fn setting_rows() -> [(usize, &'static str); 25] { | 45 | pub(super) fn setting_rows() -> [(usize, &'static str); 25] { |
| @@ -44,7 +50,7 @@ pub(super) fn setting_rows() -> [(usize, &'static str); 25] { | |||
| 44 | (0, s.status), | 50 | (0, s.status), |
| 45 | (0, s.presence), | 51 | (0, s.presence), |
| 46 | (0, s.change_picture), | 52 | (0, s.change_picture), |
| 47 | - (0, s.delete_account), | 53 | + (4, s.delete_account), |
| 48 | (1, v.input_device), | 54 | (1, v.input_device), |
| 49 | (1, v.output_device), | 55 | (1, v.output_device), |
| 50 | (1, v.input_volume), | 56 | (1, v.input_volume), |
| @@ -235,33 +241,18 @@ impl Yumush { | |||
| 235 | )); | 241 | )); |
| 236 | } | 242 | } |
| 237 | sections.push(section(settings_titles()[3], palette, appearance)); | 243 | sections.push(section(settings_titles()[3], palette, appearance)); |
| 238 | - if self.user.is_some() && !sections.is_empty() { | 244 | + if self.user.is_some() { |
| 239 | - let profile = sections.remove(0); | 245 | + sections.push(danger(vec![ |
| 240 | - sections.insert( | 246 | + delete_control( |
| 241 | - 0, | 247 | + "delete_account_button", |
| 242 | - with_danger( | 248 | + w().settings_page.delete_account, |
| 243 | - profile, | 249 | + self.armed(Armed::DeleteAccount), |
| 244 | - vec![ | 250 | + entity, |
| 245 | - small_button("logout_button", palette, palette.muted, { | 251 | + palette, |
| 246 | - let entity = entity.clone(); | 252 | + Yumush::delete_account, |
| 247 | - move |window, cx| { | 253 | + ) |
| 248 | - entity.update(cx, |yumush, cx| yumush.logout(window, cx)) | 254 | + .into_any_element(), |
| 249 | - } | 255 | + ])); |
| 250 | - }) | ||
| 251 | - .child(w().settings_page.log_out) | ||
| 252 | - .into_any_element(), | ||
| 253 | - delete_control( | ||
| 254 | - "delete_account_button", | ||
| 255 | - w().settings_page.delete_account, | ||
| 256 | - self.chat.delete_step, | ||
| 257 | - entity, | ||
| 258 | - palette, | ||
| 259 | - Yumush::delete_account, | ||
| 260 | - ) | ||
| 261 | - .into_any_element(), | ||
| 262 | - ], | ||
| 263 | - ), | ||
| 264 | - ); | ||
| 265 | } | 256 | } |
| 266 | 257 | ||
| 267 | page( | 258 | page( |
| @@ -342,17 +333,8 @@ impl Yumush { | |||
| 342 | .detach(); | 333 | .detach(); |
| 343 | } | 334 | } |
| 344 | 335 | ||
| 345 | - pub(super) fn confirm_delete(&mut self, cx: &mut Context<Self>) -> bool { | ||
| 346 | - if self.chat.delete_step == DeleteStep::Idle { | ||
| 347 | - self.chat.delete_step = DeleteStep::Confirm; | ||
| 348 | - cx.notify(); | ||
| 349 | - return false; | ||
| 350 | - } | ||
| 351 | - true | ||
| 352 | - } | ||
| 353 | - | ||
| 354 | pub(super) fn delete_account(&mut self, window: &mut Window, cx: &mut Context<Self>) { | 336 | pub(super) fn delete_account(&mut self, window: &mut Window, cx: &mut Context<Self>) { |
| 355 | - if !self.confirm_delete(cx) { | 337 | + if !self.arm(Armed::DeleteAccount, cx) { |
| 356 | return; | 338 | return; |
| 357 | } | 339 | } |
| 358 | let Some(user_id) = self.user.as_ref().map(|user| user.id) else { | 340 | let Some(user_id) = self.user.as_ref().map(|user| user.id) else { |
| @@ -639,6 +621,7 @@ pub(super) fn page( | |||
| 639 | move |_, cx| { | 621 | move |_, cx| { |
| 640 | entity.update(cx, |yumush, cx| { | 622 | entity.update(cx, |yumush, cx| { |
| 641 | yumush.chat.section = position; | 623 | yumush.chat.section = position; |
| 624 | + yumush.chat.armed = None; | ||
| 642 | cx.notify(); | 625 | cx.notify(); |
| 643 | }) | 626 | }) |
| 644 | }, | 627 | }, |
| @@ -759,25 +742,15 @@ pub(super) fn section(title: &'static str, palette: Palette, rows: Vec<Div>) -> | |||
| 759 | Section(title, rows_column(palette, rows)) | 742 | Section(title, rows_column(palette, rows)) |
| 760 | } | 743 | } |
| 761 | 744 | ||
| 762 | -pub(super) fn with_danger(section: Section, actions: Vec<AnyElement>) -> Section { | 745 | +pub(super) fn danger(actions: Vec<AnyElement>) -> Section { |
| 763 | - let Section(title, body) = section; | ||
| 764 | Section( | 746 | Section( |
| 765 | - title, | 747 | + w().settings_page.danger_zone, |
| 766 | div() | 748 | div() |
| 749 | + .ml(px(-space::SM)) | ||
| 767 | .flex() | 750 | .flex() |
| 768 | - .flex_col() | 751 | + .items_center() |
| 769 | - .gap(px(space::XXL)) | 752 | + .gap(px(space::LG)) |
| 770 | - .child(body) | 753 | + .children(actions) |
| 771 | - .when(!actions.is_empty(), |this| { | ||
| 772 | - this.child( | ||
| 773 | - div() | ||
| 774 | - .ml(px(-space::SM)) | ||
| 775 | - .flex() | ||
| 776 | - .items_center() | ||
| 777 | - .gap(px(space::LG)) | ||
| 778 | - .children(actions), | ||
| 779 | - ) | ||
| 780 | - }) | ||
| 781 | .into_any_element(), | 754 | .into_any_element(), |
| 782 | ) | 755 | ) |
| 783 | } | 756 | } |
| @@ -936,20 +909,18 @@ pub(super) fn small_button( | |||
| 936 | pub(super) fn delete_control( | 909 | pub(super) fn delete_control( |
| 937 | id: &'static str, | 910 | id: &'static str, |
| 938 | label: &'static str, | 911 | label: &'static str, |
| 939 | - step: DeleteStep, | 912 | + confirming: bool, |
| 940 | entity: &Entity<Yumush>, | 913 | entity: &Entity<Yumush>, |
| 941 | palette: Palette, | 914 | palette: Palette, |
| 942 | action: fn(&mut Yumush, &mut Window, &mut Context<Yumush>), | 915 | action: fn(&mut Yumush, &mut Window, &mut Context<Yumush>), |
| 943 | ) -> impl IntoElement { | 916 | ) -> impl IntoElement { |
| 944 | let entity = entity.clone(); | 917 | let entity = entity.clone(); |
| 945 | - let confirming = step == DeleteStep::Confirm; | ||
| 946 | - | ||
| 947 | small_button(id, palette, palette.danger, move |window, cx| { | 918 | small_button(id, palette, palette.danger, move |window, cx| { |
| 948 | entity.update(cx, |yumush, cx| action(yumush, window, cx)); | 919 | entity.update(cx, |yumush, cx| action(yumush, window, cx)); |
| 949 | }) | 920 | }) |
| 950 | .when(confirming, |this| this.font_weight(FontWeight::MEDIUM)) | 921 | .when(confirming, |this| this.font_weight(FontWeight::MEDIUM)) |
| 951 | .child(if confirming { | 922 | .child(if confirming { |
| 952 | - w().settings_page.confirm | 923 | + w().common.confirm |
| 953 | } else { | 924 | } else { |
| 954 | label | 925 | label |
| 955 | }) | 926 | }) |
crates/client/src/gui/sidebar.rsmodified+28 -15
| @@ -23,7 +23,7 @@ use gpui_kit::{ | |||
| 23 | 23 | ||
| 24 | use super::{ | 24 | use super::{ |
| 25 | Palette, Tooltip as _, Yumush, avatar, | 25 | Palette, Tooltip as _, Yumush, avatar, |
| 26 | - chat::{View, create_community}, | 26 | + chat::{Armed, View, create_community}, |
| 27 | clickable, community_icon, community_name, entity_action, hoverable, input_dialog, | 27 | clickable, community_icon, community_name, entity_action, hoverable, input_dialog, |
| 28 | parts::{Scale, Tone, icon_button}, | 28 | parts::{Scale, Tone, icon_button}, |
| 29 | presence_avatar, | 29 | presence_avatar, |
| @@ -429,20 +429,29 @@ impl Yumush { | |||
| 429 | yumush.open_direct(user_id, window, cx) | 429 | yumush.open_direct(user_id, window, cx) |
| 430 | }) | 430 | }) |
| 431 | }); | 431 | }); |
| 432 | - right_menu(("friend_menu", user_id as usize), row, move |popover, _| { | 432 | + let armed = Armed::RemoveFriend(user_id); |
| 433 | - super::parts::stack(space::XS).child(super::profile::menu_row( | 433 | + right_menu( |
| 434 | - ("remove_friend", user_id as usize), | 434 | + ("friend_menu", user_id as usize), |
| 435 | - w().sidebar.remove_friend, | 435 | + entity, |
| 436 | - super::parts::small_icon(IconName::UserMinus), | 436 | + row, |
| 437 | - palette.danger, | 437 | + move |popover, cx| { |
| 438 | - palette, | 438 | + super::parts::stack(space::XS).child(super::profile::menu_row( |
| 439 | - super::profile::yumush_action( | 439 | + ("remove_friend", user_id as usize), |
| 440 | - &remove, | 440 | + remove |
| 441 | - popover, | 441 | + .read(cx) |
| 442 | - move |yumush, window, cx| yumush.remove_friend(user_id, window, cx), | 442 | + .armed_label(armed, w().sidebar.remove_friend), |
| 443 | - ), | 443 | + super::parts::small_icon(IconName::UserMinus), |
| 444 | - )) | 444 | + palette.danger, |
| 445 | - }) | 445 | + palette, |
| 446 | + super::profile::armed_action( | ||
| 447 | + armed, | ||
| 448 | + &remove, | ||
| 449 | + popover, | ||
| 450 | + move |yumush, window, cx| yumush.remove_friend(user_id, window, cx), | ||
| 451 | + ), | ||
| 452 | + )) | ||
| 453 | + }, | ||
| 454 | + ) | ||
| 446 | .into_any_element() | 455 | .into_any_element() |
| 447 | }) | 456 | }) |
| 448 | .collect() | 457 | .collect() |
| @@ -615,6 +624,7 @@ impl Yumush { | |||
| 615 | let menu = entity.clone(); | 624 | let menu = entity.clone(); |
| 616 | right_menu( | 625 | right_menu( |
| 617 | ("room_menu", community_id as usize), | 626 | ("room_menu", community_id as usize), |
| 627 | + entity, | ||
| 618 | row, | 628 | row, |
| 619 | move |popover, cx| { | 629 | move |popover, cx| { |
| 620 | let yumush = menu.read(cx); | 630 | let yumush = menu.read(cx); |
| @@ -1165,11 +1175,14 @@ fn row_button( | |||
| 1165 | 1175 | ||
| 1166 | fn right_menu( | 1176 | fn right_menu( |
| 1167 | id: impl Into<gpui_kit::ElementId>, | 1177 | id: impl Into<gpui_kit::ElementId>, |
| 1178 | + entity: &Entity<Yumush>, | ||
| 1168 | trigger: impl IntoElement, | 1179 | trigger: impl IntoElement, |
| 1169 | rows: impl Fn(&Entity<PopoverState>, &App) -> Div + 'static, | 1180 | rows: impl Fn(&Entity<PopoverState>, &App) -> Div + 'static, |
| 1170 | ) -> Popover { | 1181 | ) -> Popover { |
| 1182 | + let disarm = entity.clone(); | ||
| 1171 | Popover::new(id) | 1183 | Popover::new(id) |
| 1172 | .mouse_button(gpui_kit::MouseButton::Right) | 1184 | .mouse_button(gpui_kit::MouseButton::Right) |
| 1185 | + .on_open_change(move |_, _, cx| disarm.update(cx, |yumush, cx| yumush.disarm(cx))) | ||
| 1173 | .anchor(Anchor::TopLeft) | 1186 | .anchor(Anchor::TopLeft) |
| 1174 | .appearance(false) | 1187 | .appearance(false) |
| 1175 | .trigger(super::Trigger::new(trigger)) | 1188 | .trigger(super::Trigger::new(trigger)) |
crates/client/src/instance.rsadded+109 -0
| @@ -0,0 +1,109 @@ | |||
| 1 | +use tokio::sync::mpsc::{UnboundedReceiver, unbounded_channel}; | ||
| 2 | + | ||
| 3 | +pub const MULTI: &str = "--multi"; | ||
| 4 | + | ||
| 5 | +pub enum Instance { | ||
| 6 | + First(UnboundedReceiver<()>), | ||
| 7 | + Running, | ||
| 8 | +} | ||
| 9 | + | ||
| 10 | +pub fn claim() -> Instance { | ||
| 11 | + if std::env::args().any(|arg| arg == MULTI) { | ||
| 12 | + return alone(); | ||
| 13 | + } | ||
| 14 | + match crate::config_dir() { | ||
| 15 | + Some(dir) => claim_in(dir), | ||
| 16 | + None => alone(), | ||
| 17 | + } | ||
| 18 | +} | ||
| 19 | + | ||
| 20 | +fn alone() -> Instance { | ||
| 21 | + Instance::First(unbounded_channel().1) | ||
| 22 | +} | ||
| 23 | + | ||
| 24 | +#[cfg(unix)] | ||
| 25 | +fn claim_in(dir: std::path::PathBuf) -> Instance { | ||
| 26 | + use std::os::unix::net::{UnixListener, UnixStream}; | ||
| 27 | + | ||
| 28 | + let path = dir.join("instance.sock"); | ||
| 29 | + if UnixStream::connect(&path).is_ok() { | ||
| 30 | + return Instance::Running; | ||
| 31 | + } | ||
| 32 | + let _ = std::fs::create_dir_all(&dir); | ||
| 33 | + let _ = std::fs::remove_file(&path); | ||
| 34 | + let listener = match UnixListener::bind(&path) { | ||
| 35 | + Ok(listener) => listener, | ||
| 36 | + Err(error) => { | ||
| 37 | + tracing::warn!("instance: {error}"); | ||
| 38 | + return alone(); | ||
| 39 | + } | ||
| 40 | + }; | ||
| 41 | + let (sender, receiver) = unbounded_channel(); | ||
| 42 | + let _ = std::thread::Builder::new() | ||
| 43 | + .name("instance".to_string()) | ||
| 44 | + .spawn(move || { | ||
| 45 | + for stream in listener.incoming() { | ||
| 46 | + if stream.is_ok() && sender.send(()).is_err() { | ||
| 47 | + break; | ||
| 48 | + } | ||
| 49 | + } | ||
| 50 | + }); | ||
| 51 | + Instance::First(receiver) | ||
| 52 | +} | ||
| 53 | + | ||
| 54 | +#[cfg(windows)] | ||
| 55 | +fn claim_in(dir: std::path::PathBuf) -> Instance { | ||
| 56 | + use tokio::net::windows::named_pipe::ServerOptions; | ||
| 57 | + | ||
| 58 | + let name = format!( | ||
| 59 | + r"\\.\pipe\yumush-{}", | ||
| 60 | + dir.display().to_string().replace('\\', "/") | ||
| 61 | + ); | ||
| 62 | + let (sender, receiver) = unbounded_channel(); | ||
| 63 | + let (ready_sender, ready) = std::sync::mpsc::channel(); | ||
| 64 | + let pipe = name.clone(); | ||
| 65 | + let _ = std::thread::Builder::new() | ||
| 66 | + .name("instance".to_string()) | ||
| 67 | + .spawn(move || { | ||
| 68 | + let Ok(runtime) = tokio::runtime::Builder::new_current_thread() | ||
| 69 | + .enable_all() | ||
| 70 | + .build() | ||
| 71 | + else { | ||
| 72 | + let _ = ready_sender.send(false); | ||
| 73 | + return; | ||
| 74 | + }; | ||
| 75 | + runtime.block_on(async move { | ||
| 76 | + let Ok(mut server) = ServerOptions::new().first_pipe_instance(true).create(&pipe) | ||
| 77 | + else { | ||
| 78 | + let _ = ready_sender.send(false); | ||
| 79 | + return; | ||
| 80 | + }; | ||
| 81 | + let _ = ready_sender.send(true); | ||
| 82 | + loop { | ||
| 83 | + if server.connect().await.is_ok() && sender.send(()).is_err() { | ||
| 84 | + break; | ||
| 85 | + } | ||
| 86 | + let Ok(next) = ServerOptions::new().create(&pipe) else { | ||
| 87 | + break; | ||
| 88 | + }; | ||
| 89 | + server = next; | ||
| 90 | + } | ||
| 91 | + }); | ||
| 92 | + }); | ||
| 93 | + if ready.recv() == Ok(true) { | ||
| 94 | + return Instance::First(receiver); | ||
| 95 | + } | ||
| 96 | + match std::fs::OpenOptions::new() | ||
| 97 | + .read(true) | ||
| 98 | + .write(true) | ||
| 99 | + .open(&name) | ||
| 100 | + { | ||
| 101 | + Ok(_) => Instance::Running, | ||
| 102 | + Err(_) => alone(), | ||
| 103 | + } | ||
| 104 | +} | ||
| 105 | + | ||
| 106 | +#[cfg(not(any(unix, windows)))] | ||
| 107 | +fn claim_in(_: std::path::PathBuf) -> Instance { | ||
| 108 | + alone() | ||
| 109 | +} | ||
crates/client/src/lib.rsmodified+1 -0
| @@ -9,6 +9,7 @@ pub mod avatar; | |||
| 9 | pub mod embed; | 9 | pub mod embed; |
| 10 | pub mod emoji; | 10 | pub mod emoji; |
| 11 | pub mod gui; | 11 | pub mod gui; |
| 12 | +pub mod instance; | ||
| 12 | pub mod lang; | 13 | pub mod lang; |
| 13 | pub mod logo; | 14 | pub mod logo; |
| 14 | pub mod marks; | 15 | pub mod marks; |
crates/client/src/main.rsmodified+13 -0
| @@ -41,6 +41,10 @@ fn main() { | |||
| 41 | return; | 41 | return; |
| 42 | } | 42 | } |
| 43 | 43 | ||
| 44 | + let client::instance::Instance::First(mut wake) = client::instance::claim() else { | ||
| 45 | + return; | ||
| 46 | + }; | ||
| 47 | + | ||
| 44 | #[cfg(target_os = "linux")] | 48 | #[cfg(target_os = "linux")] |
| 45 | if let Err(error) = client::logo::install() { | 49 | if let Err(error) = client::logo::install() { |
| 46 | tracing::warn!("desktop entry: {error}"); | 50 | tracing::warn!("desktop entry: {error}"); |
| @@ -83,6 +87,15 @@ fn main() { | |||
| 83 | }) | 87 | }) |
| 84 | .detach(); | 88 | .detach(); |
| 85 | 89 | ||
| 90 | + let woken = view.clone(); | ||
| 91 | + cx.spawn(async move |cx| { | ||
| 92 | + while wake.recv().await.is_some() { | ||
| 93 | + let view = woken.clone(); | ||
| 94 | + cx.update(|cx| show(view, cx)); | ||
| 95 | + } | ||
| 96 | + }) | ||
| 97 | + .detach(); | ||
| 98 | + | ||
| 86 | cx.spawn(async move |cx| { | 99 | cx.spawn(async move |cx| { |
| 87 | while let Some(action) = tray_receiver.recv().await { | 100 | while let Some(action) = tray_receiver.recv().await { |
| 88 | let view = view.clone(); | 101 | let view = view.clone(); |