Skip to content

Commit 2e842cb

Browse files
Desktop: fix Mac restart dialog to show all changes to preferences requiring restart (#3903)
* Desktop: Fix restart dialog on Mac * Fix * Fix * Fix --------- Co-authored-by: Keavon Chambers <[email protected]>
1 parent 7f6571e commit 2e842cb

File tree

6 files changed

+21
-18
lines changed

6 files changed

+21
-18
lines changed

desktop/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ pub fn start() {
114114

115115
match exit_reason {
116116
app::ExitReason::Restart | app::ExitReason::UiAccelerationFailure => {
117-
tracing::error!("Restarting application");
117+
tracing::info!("Restarting application");
118118
let mut command = std::process::Command::new(std::env::current_exe().unwrap());
119119
#[cfg(target_family = "unix")]
120120
let _ = std::os::unix::process::CommandExt::exec(&mut command);

editor/src/messages/dialog/dialog_message.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,7 @@ pub enum DialogMessage {
3737
},
3838
RequestNewDocumentDialog,
3939
RequestPreferencesDialog,
40-
RequestConfirmRestartDialog,
40+
RequestConfirmRestartDialog {
41+
preferences_requiring_restart: Vec<String>,
42+
},
4143
}

editor/src/messages/dialog/dialog_message_handler.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,9 @@ impl MessageHandler<DialogMessage, DialogMessageContext<'_>> for DialogMessageHa
136136
self.on_dismiss = Some(PreferencesDialogMessage::Confirm.into());
137137
self.preferences_dialog.send_dialog_to_frontend(responses, preferences);
138138
}
139-
DialogMessage::RequestConfirmRestartDialog => {
139+
DialogMessage::RequestConfirmRestartDialog { preferences_requiring_restart } => {
140140
self.on_dismiss = Some(DialogMessage::Close.into());
141-
let dialog = ConfirmRestartDialog {
142-
changed_settings: vec!["Disable UI Acceleration".into()],
143-
};
141+
let dialog = ConfirmRestartDialog { preferences_requiring_restart };
144142
dialog.send_dialog_to_frontend(responses);
145143
}
146144
}

editor/src/messages/dialog/preferences_dialog/preferences_dialog_message_handler.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@ impl MessageHandler<PreferencesDialogMessage, PreferencesDialogMessageContext<'_
2828
}
2929
PreferencesDialogMessage::Confirm => {
3030
if let Some(unmodified_preferences) = &self.unmodified_preferences
31-
&& unmodified_preferences.needs_restart(preferences)
31+
&& let preferences_requiring_restart = unmodified_preferences.preferences_requiring_restart(preferences)
32+
&& !preferences_requiring_restart.is_empty()
3233
{
33-
responses.add(DialogMessage::RequestConfirmRestartDialog);
34+
responses.add(DialogMessage::RequestConfirmRestartDialog { preferences_requiring_restart });
3435
} else {
3536
responses.add(DialogMessage::Close);
3637
}

editor/src/messages/dialog/simple_dialogs/confirm_restart_dialog.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::messages::prelude::*;
33

44
/// A dialog for confirming the restart of the application when changing a preference that requires a restart to take effect.
55
pub struct ConfirmRestartDialog {
6-
pub changed_settings: Vec<String>,
6+
pub preferences_requiring_restart: Vec<String>,
77
}
88

99
impl DialogLayoutHolder for ConfirmRestartDialog {
@@ -30,7 +30,7 @@ impl DialogLayoutHolder for ConfirmRestartDialog {
3030

3131
impl LayoutHolder for ConfirmRestartDialog {
3232
fn layout(&self) -> Layout {
33-
let changed_settings = "• ".to_string() + &self.changed_settings.join("\n• ");
33+
let changed_settings = "• ".to_string() + &self.preferences_requiring_restart.join("\n• ");
3434

3535
Layout(vec![
3636
LayoutGroup::row(vec![TextLabel::new("Restart to apply changes?").bold(true).multiline(true).widget_instance()]),

editor/src/messages/preferences/preferences_message_handler.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,16 @@ pub struct PreferencesMessageHandler {
2828
}
2929

3030
impl PreferencesMessageHandler {
31-
#[cfg(not(target_os = "macos"))]
32-
pub fn needs_restart(&self, other: &Self) -> bool {
33-
self.disable_ui_acceleration != other.disable_ui_acceleration
34-
}
35-
36-
#[cfg(target_os = "macos")]
37-
pub fn needs_restart(&self, other: &Self) -> bool {
38-
self.disable_ui_acceleration != other.disable_ui_acceleration || self.vsync != other.vsync
31+
pub fn preferences_requiring_restart(&self, other: &Self) -> Vec<String> {
32+
let mut requiring_restart = Vec::new();
33+
if self.disable_ui_acceleration != other.disable_ui_acceleration {
34+
requiring_restart.push("Disable UI Acceleration");
35+
}
36+
#[cfg(target_os = "macos")]
37+
if self.vsync != other.vsync {
38+
requiring_restart.push("Enable V-Sync");
39+
}
40+
requiring_restart.into_iter().map(String::from).collect()
3941
}
4042

4143
pub fn get_selection_mode(&self) -> SelectionMode {

0 commit comments

Comments
 (0)