diff --git a/macos/ONLYOFFICE/Code/Controllers/Common/ASCCommonViewController.mm b/macos/ONLYOFFICE/Code/Controllers/Common/ASCCommonViewController.mm index 974140cd3..588fdf81d 100644 --- a/macos/ONLYOFFICE/Code/Controllers/Common/ASCCommonViewController.mm +++ b/macos/ONLYOFFICE/Code/Controllers/Common/ASCCommonViewController.mm @@ -164,7 +164,6 @@ // Create CEF event listener [ASCEventsController sharedInstance]; - [ASCThemesController sharedInstance]; [self setupTabControl]; [self createStartPage]; diff --git a/macos/ONLYOFFICE/Code/Controllers/Common/ASCEventsController.mm b/macos/ONLYOFFICE/Code/Controllers/Common/ASCEventsController.mm index 97e6ac413..ae61f87f6 100644 --- a/macos/ONLYOFFICE/Code/Controllers/Common/ASCEventsController.mm +++ b/macos/ONLYOFFICE/Code/Controllers/Common/ASCEventsController.mm @@ -795,34 +795,34 @@ public: pCefView->Apply(pEvent); } } else if (cmd.find(L"system:changed") != std::wstring::npos) { - NSLog(@"nstheme: system changed %@", [NSString stringWithstdwstring:param]); - if ( [[ASCThemesController currentThemeId] isEqualToString:uiThemeSystem] ) { - NSError * error = NULL; - NSRegularExpression * regex = [NSRegularExpression regularExpressionWithPattern: @":\\s?\\\"(light|dark)" - options: NSRegularExpressionCaseInsensitive - error: &error]; - if ( !error ) { - NSString * json = [NSString stringWithstdwstring:param]; - NSTextCheckingResult * match = [regex firstMatchInString:json options:0 range:NSMakeRange(0, [json length])]; - if (match) { - NSRange range = [match rangeAtIndex:1]; - NSString * new_theme_type = [json substringWithRange:range]; - - if ( [ASCThemesController isCurrentThemeDark] != [new_theme_type isEqualToString:@"dark"] ) { - [[ASCSharedSettings sharedInstance] setSetting:new_theme_type forKey:kSettingsColorScheme]; - [[NSNotificationCenter defaultCenter] postNotificationName:ASCEventNameChangedUITheme - object:nil - userInfo:@{@"uitheme": uiThemeSystem}]; - } - } - } - } else { - if (NSDictionary * json = [[NSString stringWithstdwstring:param] dictionary]) { - if ( NSString * colors = json[@"colorscheme"] ) { - [[ASCSharedSettings sharedInstance] setSetting:colors forKey:kSettingsColorScheme]; - } - } - } +// NSLog(@"nstheme: system changed %@", [NSString stringWithstdwstring:param]); +// if ( [[ASCThemesController currentThemeId] isEqualToString:uiThemeSystem] ) { +// NSError * error = NULL; +// NSRegularExpression * regex = [NSRegularExpression regularExpressionWithPattern: @":\\s?\\\"(light|dark)" +// options: NSRegularExpressionCaseInsensitive +// error: &error]; +// if ( !error ) { +// NSString * json = [NSString stringWithstdwstring:param]; +// NSTextCheckingResult * match = [regex firstMatchInString:json options:0 range:NSMakeRange(0, [json length])]; +// if (match) { +// NSRange range = [match rangeAtIndex:1]; +// NSString * new_theme_type = [json substringWithRange:range]; +// +// if ( [ASCThemesController isCurrentThemeDark] != [new_theme_type isEqualToString:@"dark"] ) { +// [[ASCSharedSettings sharedInstance] setSetting:new_theme_type forKey:kSettingsColorScheme]; +// [[NSNotificationCenter defaultCenter] postNotificationName:ASCEventNameChangedUITheme +// object:nil +// userInfo:@{@"uitheme": uiThemeSystem}]; +// } +// } +// } +// } else { +// if (NSDictionary * json = [[NSString stringWithstdwstring:param] dictionary]) { +// if ( NSString * colors = json[@"colorscheme"] ) { +// [[ASCSharedSettings sharedInstance] setSetting:colors forKey:kSettingsColorScheme]; +// } +// } +// } } else if (cmd.find(L"uitheme:changed") != std::wstring::npos) { if (NSDictionary * json = [[NSString stringWithstdwstring:param] dictionary]) { if ( NSString * newTheme = json[@"name"] ) { @@ -834,15 +834,15 @@ public: [[NSNotificationCenter defaultCenter] postNotificationName:ASCEventNameChangedUITheme object:nil userInfo:@{@"uitheme":newTheme}]; - } else if ( [curTheme isEqualToString:uiThemeSystem] ) { - NSString * colorScheme = [[ASCSharedSettings sharedInstance] settingByKey:kSettingsColorScheme]; - if ( [NSApplication isSystemDarkMode] != [colorScheme isEqualToString:@"dark"] ) { - [[ASCSharedSettings sharedInstance] setSetting:([NSApplication isSystemDarkMode] ? @"dark" : @"light") forKey:kSettingsColorScheme]; - - [[NSNotificationCenter defaultCenter] postNotificationName:ASCEventNameChangedUITheme - object:nil - userInfo:@{@"uitheme":newTheme}]; - } +// } else if ( [curTheme isEqualToString:uiThemeSystem] ) { +// NSString * colorScheme = [[ASCSharedSettings sharedInstance] settingByKey:kSettingsColorScheme]; +// if ( [NSApplication isSystemDarkMode] != [colorScheme isEqualToString:@"dark"] ) { +// [[ASCSharedSettings sharedInstance] setSetting:([NSApplication isSystemDarkMode] ? @"dark" : @"light") forKey:kSettingsColorScheme]; +// +// [[NSNotificationCenter defaultCenter] postNotificationName:ASCEventNameChangedUITheme +// object:nil +// userInfo:@{@"uitheme":newTheme}]; +// } } } } diff --git a/macos/ONLYOFFICE/Code/Controllers/Common/ASCThemesController.m b/macos/ONLYOFFICE/Code/Controllers/Common/ASCThemesController.m index e3a0d391e..585eafd11 100644 --- a/macos/ONLYOFFICE/Code/Controllers/Common/ASCThemesController.m +++ b/macos/ONLYOFFICE/Code/Controllers/Common/ASCThemesController.m @@ -67,7 +67,12 @@ [[NSUserDefaults standardUserDefaults] setObject:uiTheme forKey:ASCUserUITheme]; } + [[ASCEditorJSVariables instance] setParameter:@"uitheme" withString:uiTheme]; + [[ASCEditorJSVariables instance] applyParameters]; + NSString * systemColorScheme = [[self class] isSystemDarkMode] ? @"dark" : @"light"; + [[ASCSharedSettings sharedInstance] setSetting:systemColorScheme forKey:kSettingsColorScheme]; + [[ASCEditorJSVariables instance] setVariable:@"theme" withObject:@{@"id":uiTheme, @"system":systemColorScheme, @"type":[[self class] isCurrentThemeDark] ? @"dark" : @"light"}]; @@ -91,7 +96,7 @@ + (BOOL)isCurrentThemeDark { NSString * theme = [[NSUserDefaults standardUserDefaults] valueForKey:ASCUserUITheme]; if ([uiThemeSystem isEqualToString:theme]) { - return [@"dark" isEqualToString:[[ASCSharedSettings sharedInstance] settingByKey:kSettingsColorScheme]]; + return [self isSystemDarkMode]; } else return [uiThemeDark isEqualToString:theme] || [uiThemeContrastDark isEqualToString:theme]; } diff --git a/macos/ONLYOFFICE/main.mm b/macos/ONLYOFFICE/main.mm index 70f18fbb2..e319af2e0 100644 --- a/macos/ONLYOFFICE/main.mm +++ b/macos/ONLYOFFICE/main.mm @@ -106,16 +106,6 @@ int main(int argc, const char * argv[]) { // setup ui theme [ASCThemesController sharedInstance]; - NSString * uiTheme = [[NSUserDefaults standardUserDefaults] valueForKey:ASCUserUITheme]; - if ( !uiTheme ) { - uiTheme = uiThemeSystem; - [[NSUserDefaults standardUserDefaults] setObject:uiTheme forKey:ASCUserUITheme]; - } - - NSString * systemColorScheme = [NSApplication isSystemDarkMode] ? @"dark" : @"light"; - [[ASCEditorJSVariables instance] setParameter:@"uitheme" withString:uiTheme]; - [[ASCSharedSettings sharedInstance] setSetting:systemColorScheme forKey:kSettingsColorScheme]; - [[ASCEditorJSVariables instance] applyParameters]; [[ASCEditorJSVariables instance] setVariable:@"rtl" withBool:[ASCLinguist isUILayoutDirectionRtl]]; [[ASCEditorJSVariables instance] apply];