Skip to content

Commit

Permalink
Solved Crash on full screen mode.
Browse files Browse the repository at this point in the history
Small code improvements.
  • Loading branch information
GerhardAM committed Mar 14, 2022
1 parent 4fdb1b8 commit f2bff7a
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 120 deletions.
3 changes: 0 additions & 3 deletions Classes/BrowserComponents/SEBOSXBrowserController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}


Expand Down
203 changes: 86 additions & 117 deletions Classes/Preferences/PreferencesWindow/PreferencesController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}


Expand All @@ -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];
}


Expand All @@ -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];
Expand Down

0 comments on commit f2bff7a

Please sign in to comment.