From f2bff7a16e47f068d514a712d7cac17dc0e1bd87 Mon Sep 17 00:00:00 2001 From: Gerhard Muendane Date: Mon, 14 Mar 2022 13:06:19 +0100 Subject: [PATCH] Solved Crash on full screen mode. Small code improvements. --- .../SEBOSXBrowserController.m | 3 - .../PreferencesWindow/PreferencesController.m | 203 ++++++++---------- 2 files changed, 86 insertions(+), 120 deletions(-) diff --git a/Classes/BrowserComponents/SEBOSXBrowserController.m b/Classes/BrowserComponents/SEBOSXBrowserController.m index 1f5cad85c..2720acf27 100644 --- a/Classes/BrowserComponents/SEBOSXBrowserController.m +++ b/Classes/BrowserComponents/SEBOSXBrowserController.m @@ -589,9 +589,6 @@ - (void) closeAllBrowserWindows { // Close all browser windows (documents) self.mainBrowserWindow = nil; - [[NSDocumentController sharedDocumentController] closeAllDocumentsWithDelegate:self - didCloseAllSelector:@selector(documentController:didCloseAll:contextInfo:) - contextInfo: nil]; } diff --git a/Classes/Preferences/PreferencesWindow/PreferencesController.m b/Classes/Preferences/PreferencesWindow/PreferencesController.m index 5f3956898..2c9815812 100644 --- a/Classes/Preferences/PreferencesWindow/PreferencesController.m +++ b/Classes/Preferences/PreferencesWindow/PreferencesController.m @@ -668,26 +668,23 @@ - (SEBApplySettingsAnswers) askToApplySettingsAlert [newAlert addButtonWithTitle:NSLocalizedString(@"Apply", nil)]; [newAlert addButtonWithTitle:NSLocalizedString(@"Cancel", nil)]; NSInteger answer = [newAlert runModal]; + switch(answer) { case NSAlertFirstButtonReturn: - { // Don't apply edited settings: Restore previous settings // Release preferences window so bindings get synchronized properly with the new loaded values [self releasePreferencesWindow]; [self restoreStoredSettings]; [self initPreferencesWindow]; - } - } - switch(answer) - { - case NSAlertFirstButtonReturn: return SEBApplySettingsAnswerDontApply; case NSAlertSecondButtonReturn: return SEBApplySettingsAnswerApply; + + default: + return SEBApplySettingsAnswerCancel; } - return SEBApplySettingsAnswerCancel; } @@ -712,88 +709,111 @@ - (IBAction) restartSEB:(id)sender { // If private settings are active, check if those current settings have unsaved changes if (NSUserDefaults.userDefaultsPrivate && browserExamKeyChanged) { // There are unsaved changes - SEBUnsavedSettingsAnswer answer = [self unsavedSettingsAlertWithText: - NSLocalizedString(@"Edited settings have unsaved changes.", nil)]; - switch(answer) + [self handleAlertForUnsavedSettingsAswer:oldSettings withText:NSLocalizedString(@"Edited settings have unsaved changes.", nil) isRestart:TRUE]; + } + + // If settings changed since before opening preferences: + [self handleAlertForApplySettingsAnswer:oldSettings isRestart:TRUE]; + + // If opening the preferences window isn't allowed in these settings, + // which is dangerous when being applied, we confirm the user knows what he's doing + [self handleAlertForDisabledPreferencesAswer:preferences oldSettings:oldSettings isRestart:TRUE]; + + //Close prefs window + restartSEB = YES; + [self closePreferencesWindow]; +} + + +- (void)handleAlertForUnsavedSettingsAswer:(SEBEncapsulatedSettings *)oldSettings withText:(NSString *)alertText isRestart:(BOOL)isRestart { + + SEBUnsavedSettingsAnswer answer; + + if (isRestart) { + answer = [self unsavedSettingsAlertWithText: + alertText]; + } else { + answer = [self unsavedSettingsAlert]; + } + + switch(answer) { case SEBUnsavedSettingsAnswerSave: { // Save the current settings data first (this also updates the Browser Exam Key) - if (![self savePrefsAs:NO fileURLUpdate:NO]) { + if (![self savePrefsAs:NO fileURLUpdate:NO]) { // Saving failed: Saving failed: Abort closing the prefs window, restore possibly changed setting keys - [oldSettings restoreSettings]; - - return; - } - break; - } + [oldSettings restoreSettings]; + return; + } + break; + } + case SEBUnsavedSettingsAnswerCancel: { // Cancel: Don't restart, restore possibly changed setting keys - [oldSettings restoreSettings]; - - return; + [oldSettings restoreSettings]; + + return; } } - } +} - // If settings changed since before opening preferences: + +- (void)handleAlertForApplySettingsAnswer:(SEBEncapsulatedSettings *)oldSettings isRestart:(BOOL)isRestart { + if ([self settingsChanged]) { - // Ask if edited settings should be applied or previously active settings restored + DDLogInfo(@"Client settings have been changed, ask if they should be applied."); + // Ask if edited settings should be applied or previously active settings restored SEBApplySettingsAnswers answer = [self askToApplySettingsAlert]; - switch(answer) - { - case SEBApplySettingsAnswerDontApply: - { - // Don't apply edited settings and restart SEB - break; - } - - case SEBApplySettingsAnswerCancel: - { - // Cancel: Don't restart, restore possibly changed setting keys + if (answer == SEBApplySettingsAnswerCancel) { + if (isRestart) { [oldSettings restoreSettings]; - - return; + } else { + // Cancel: Don't quit + DDLogInfo(@"User selected to cancel applying changed client settings, also abort quitting SEB."); } } } +} + + +- (void)handleAlertForDisabledPreferencesAswer:(NSUserDefaults *)preferences oldSettings:(SEBEncapsulatedSettings *)oldSettings isRestart:(BOOL)isRestart { - // If opening the preferences window isn't allowed in these settings, - // which is dangerous when being applied, we confirm the user knows what he's doing if ([preferences secureBoolForKey:@"org_safeexambrowser_SEB_allowPreferencesWindow"] == NO) { SEBDisabledPreferencesAnswer answer = [self alertForDisabledPreferences]; switch(answer) - { - case SEBDisabledPreferencesAnswerOverride: { - // Apply edited allow prefs setting while overriding disabling the preferences window for this session/resetting it - [preferences setSecureBool:YES forKey:@"org_safeexambrowser_SEB_allowPreferencesWindow"]; - if (NSUserDefaults.userDefaultsPrivate) { - // Release preferences window so bindings get synchronized properly with the new loaded values - [self releasePreferencesWindow]; - // Reopen preferences window - [self initPreferencesWindow]; + case SEBDisabledPreferencesAnswerOverride: + { + // Apply edited allow prefs setting while overriding disabling the preferences window for this session/resetting it + [preferences setSecureBool:YES forKey:@"org_safeexambrowser_SEB_allowPreferencesWindow"]; + + if (isRestart) { + if (NSUserDefaults.userDefaultsPrivate) { + // Release preferences window so bindings get synchronized properly with the new loaded values + [self releasePreferencesWindow]; + // Reopen preferences window + [self initPreferencesWindow]; + } + // Re-generate Browser Exam Key + [[SEBCryptor sharedSEBCryptor] updateEncryptedUserDefaults:YES updateSalt:NO]; + } + break; } - // Re-generate Browser Exam Key - [[SEBCryptor sharedSEBCryptor] updateEncryptedUserDefaults:YES updateSalt:NO]; - break; - } - case SEBDisabledPreferencesAnswerCancel: - { - // Cancel: Don't apply new settings, don't restart, restore possibly changed setting keys - [oldSettings restoreSettings]; - - return; + case SEBDisabledPreferencesAnswerCancel: + { + // Cancel: Don't apply new settings, don't restart, restore possibly changed setting keys + if (isRestart) { + [oldSettings restoreSettings]; + } + + return; + } } - } } - - //Close prefs window - restartSEB = YES; - [self closePreferencesWindow]; } @@ -816,70 +836,19 @@ - (IBAction) quitSEB:(id)sender if (NSUserDefaults.userDefaultsPrivate && browserExamKeyChanged) { DDLogInfo(@"Private user defaults (exam settings) active: There are unsaved changes"); - SEBUnsavedSettingsAnswer answer = [self unsavedSettingsAlert]; - switch(answer) - { - case SEBUnsavedSettingsAnswerSave: - { - // Save the current settings data first (this also updates the Browser Exam Key if saving is successful) - if (![self savePrefsAs:NO fileURLUpdate:NO]) { - // Saving failed: Abort quitting, restore possibly changed setting keys - [oldSettings restoreSettings]; - - return; - } - break; - } - - case SEBUnsavedSettingsAnswerCancel: - { - // Cancel: Don't quit, restore possibly changed setting keys - [oldSettings restoreSettings]; - - return; - } - } + + [self handleAlertForUnsavedSettingsAswer:oldSettings withText:nil isRestart:FALSE]; } else if (!NSUserDefaults.userDefaultsPrivate) { /// Local client settings are active DDLogInfo(@"Client settings are active"); // If settings changed: - if ([self settingsChanged]) { - DDLogInfo(@"Client settings have been changed, ask if they should be applied."); - // Ask if edited settings should be applied or previously active settings restored - SEBApplySettingsAnswers answer = [self askToApplySettingsAlert]; - switch(answer) - { - case SEBApplySettingsAnswerCancel: - { - // Cancel: Don't quit - DDLogInfo(@"User selected to cancel applying changed client settings, also abort quitting SEB."); - return; - } - } - } + [self handleAlertForApplySettingsAnswer:oldSettings isRestart:FALSE]; // If opening the preferences window isn't allowed in these settings, // which is dangerous when being applied, we confirm the user knows what he's doing - if ([preferences secureBoolForKey:@"org_safeexambrowser_SEB_allowPreferencesWindow"] == NO) { - SEBDisabledPreferencesAnswer answer = [self alertForDisabledPreferences]; - switch(answer) - { - case SEBDisabledPreferencesAnswerOverride: - { - // Apply edited allow prefs setting while overriding disabling the preferences window for this session/resetting it - [preferences setSecureBool:YES forKey:@"org_safeexambrowser_SEB_allowPreferencesWindow"]; - break; - } - - case SEBDisabledPreferencesAnswerCancel: - { - // Cancel: Don't apply new settings, don't quit - return; - } - } - } + [self handleAlertForDisabledPreferencesAswer:preferences oldSettings:oldSettings isRestart:FALSE]; } _sebController.quittingMyself = YES; [self closePreferencesWindow];