mirror of
https://github.com/ONLYOFFICE/desktop-apps.git
synced 2026-04-07 14:09:22 +08:00
[macos] refactoring
This commit is contained in:
@ -164,7 +164,6 @@
|
||||
|
||||
// Create CEF event listener
|
||||
[ASCEventsController sharedInstance];
|
||||
[ASCThemesController sharedInstance];
|
||||
|
||||
[self setupTabControl];
|
||||
[self createStartPage];
|
||||
|
||||
@ -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}];
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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];
|
||||
}
|
||||
|
||||
|
||||
@ -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];
|
||||
|
||||
Reference in New Issue
Block a user