From 1aed2f90672ca14853f45bda56e54d177068e213 Mon Sep 17 00:00:00 2001 From: ljk Date: Thu, 18 Jan 2024 11:20:56 +0800 Subject: [PATCH] Replace EZConfiguration with Configuration --- Easydict/App/AppDelegate+EZURLScheme.m | 6 +-- Easydict/App/AppDelegate.m | 1 - .../Configuration/NewConfiguration.swift | 41 ++++++++++++++++--- Easydict/Feature/DarkMode/DarkModeManager.m | 2 +- .../Feature/EventMonitor/EZEventMonitor.m | 11 ++--- .../EZDisableAutoSelectTextViewController.m | 5 ++- .../PerferenceWindow/EZAboutViewController.m | 5 ++- .../EZPrivacyViewController.m | 9 ++-- .../EZSettingViewController.m | 6 +-- .../Feature/Service/Apple/EZAppleService.m | 3 +- .../Service/AudioPlayer/EZAudioPlayer.m | 3 +- .../Feature/Service/Baidu/EZBaiduTranslate.m | 6 ++- Easydict/Feature/Service/Bing/EZBingService.m | 3 +- .../Service/Google/EZGoogleTranslate.m | 3 +- .../Service/Language/EZLanguageManager.m | 5 ++- .../Feature/Service/Model/EZDetectManager.m | 5 ++- .../Feature/Service/Model/EZQueryService.m | 3 +- .../OpenAI/EZOpenAIService+EZPromptMessages.m | 5 ++- .../Feature/Service/OpenAI/EZOpenAIService.m | 4 +- .../Service/Youdao/EZYoudaoTranslate.m | 2 +- .../Feature/StatusItem/EZMenuItemManager.m | 6 +-- .../AppleScript/EZAppleScriptManager.m | 3 +- .../Utility/EZLinkParser/EZSchemeParser.m | 15 +++---- Easydict/Feature/Utility/EZLog/EZLog.m | 2 +- .../Cell/EZSelectLanguageCell.m | 15 +++---- .../ViewController/Model/EZQueryModel.m | 7 ++-- .../EZQueryMenuTextView/EZQueryMenuTextView.m | 7 ++-- .../View/QueryView/EZQueryView.m | 4 +- .../ViewController/View/Titlebar/EZTitlebar.m | 7 ++-- .../View/WordResultView/EZWebViewManager.m | 3 +- .../View/WordResultView/EZWordResultView.m | 8 ++-- .../EZBaseQueryViewController.m | 14 +++---- .../Window/WindowManager/EZLayoutManager.m | 5 ++- .../Window/WindowManager/EZWindowManager.m | 29 ++++++------- .../NewApp/Configuration/Configuration.swift | 6 ++- 35 files changed, 158 insertions(+), 101 deletions(-) diff --git a/Easydict/App/AppDelegate+EZURLScheme.m b/Easydict/App/AppDelegate+EZURLScheme.m index eef2674c5..f3ce651bd 100644 --- a/Easydict/App/AppDelegate+EZURLScheme.m +++ b/Easydict/App/AppDelegate+EZURLScheme.m @@ -10,7 +10,7 @@ #import #import "EZWindowManager.h" #import "EZSchemeParser.h" -#import "EZConfiguration.h" +#import "Easydict-Swift.h" @implementation AppDelegate (EZURLScheme) @@ -70,8 +70,8 @@ - (void)registerRouters { - (void)showFloatingWindowAndAutoQueryText:(NSString *)text { EZWindowManager *windowManager = [EZWindowManager shared]; - EZWindowType windowType = EZConfiguration.shared.shortcutSelectTranslateWindowType; - + EZWindowType windowType = Configuration.shared.shortcutSelectTranslateWindowType; + [windowManager showFloatingWindowType:windowType queryText:text.trim autoQuery:YES diff --git a/Easydict/App/AppDelegate.m b/Easydict/App/AppDelegate.m index 8aa9e5f27..94c063961 100644 --- a/Easydict/App/AppDelegate.m +++ b/Easydict/App/AppDelegate.m @@ -12,7 +12,6 @@ #import "MMCrash.h" #import "EZWindowManager.h" #import "EZLanguageManager.h" -#import "EZConfiguration.h" #import "EZLog.h" #import "EZSchemeParser.h" #import "AppDelegate+EZURLScheme.h" diff --git a/Easydict/Feature/Configuration/NewConfiguration.swift b/Easydict/Feature/Configuration/NewConfiguration.swift index 4c199326c..4aaf49d09 100644 --- a/Easydict/Feature/Configuration/NewConfiguration.swift +++ b/Easydict/Feature/Configuration/NewConfiguration.swift @@ -9,7 +9,7 @@ import Defaults import Foundation -class Configuration: NSObject { +@objcMembers class Configuration: NSObject { private(set) static var shared = Configuration() var appDelegate = NSApp.delegate as? AppDelegate @@ -46,7 +46,13 @@ class Configuration: NSObject { var launchAtStartup: Bool var automaticallyChecksForUpdates: Bool { - updater?.automaticallyChecksForUpdates ?? false + get { + updater?.automaticallyChecksForUpdates ?? false + } + set { + updater?.automaticallyChecksForUpdates = newValue + logSettings(["automatically_checks_for_updates": newValue]) + } } @DefaultsWrapper(.hideMainWindow) @@ -76,8 +82,17 @@ class Configuration: NSObject { @DefaultsWrapper(.languageDetectOptimize) var languageDetectOptimize: EZLanguageDetectOptimize - @DefaultsWrapper(.defaultTTSServiceType) - var defaultTTSServiceType: TTSServiceType +// @DefaultsWrapper(.defaultTTSServiceType) +// var defaultTTSServiceType: TTSServiceType + + var defaultTTSServiceType: ServiceType { + get { + ServiceType(rawValue: Defaults[.defaultTTSServiceType].rawValue) + } + set { + Defaults[.defaultTTSServiceType] = TTSServiceType(rawValue: newValue.rawValue) ?? .youdao + } + } @DefaultsWrapper(.showGoogleQuickLink) var showGoogleQuickLink: Bool @@ -134,6 +149,10 @@ class Configuration: NSObject { @DefaultsWrapper(.enableBetaFeature) private(set) var beta: Bool + static func destroySharedInstance() { + shared = Configuration() + } + override init() { super.init() @@ -431,7 +450,7 @@ private extension Configuration { // MARK: Window Frame -private extension Configuration { +extension Configuration { func windowFrameWithType(_ windowType: EZWindowType) -> CGRect { Defaults[.windorFrame(for: windowType)] } @@ -453,6 +472,18 @@ extension Configuration { } } +// MARK: Intelligent Query Text Type of Service + +extension Configuration { + func setQueryTextType(_ queryTextType: EZQueryTextType, serviceType: ServiceType) { + Defaults[.queryTextType(for: serviceType)] = queryTextType + } + + func queryTextTypeForServiceType(_ serviceType: ServiceType) -> EZQueryTextType { + Defaults[.queryTextType(for: serviceType)] + } +} + // MARK: Intelligent Query Mode extension Configuration { diff --git a/Easydict/Feature/DarkMode/DarkModeManager.m b/Easydict/Feature/DarkMode/DarkModeManager.m index af749d661..3818c5a0e 100644 --- a/Easydict/Feature/DarkMode/DarkModeManager.m +++ b/Easydict/Feature/DarkMode/DarkModeManager.m @@ -49,7 +49,7 @@ - (void)updateDarkMode { BOOL isDarkMode = [self isDarkMode]; NSLog(@"%@", isDarkMode ? @"深色模式" : @"浅色模式"); - AppearenceType type = (AppearenceType)EZConfiguration.shared.appearance; + AppearenceType type = Configuration.shared.appearance; switch (type) { case AppearenceTypeDark: self.systemDarkMode = true; diff --git a/Easydict/Feature/EventMonitor/EZEventMonitor.m b/Easydict/Feature/EventMonitor/EZEventMonitor.m index 2578efd37..f3acfe5ab 100644 --- a/Easydict/Feature/EventMonitor/EZEventMonitor.m +++ b/Easydict/Feature/EventMonitor/EZEventMonitor.m @@ -17,6 +17,7 @@ #import "EZLocalStorage.h" #import "EZAppleScriptManager.h" #import "EZSystemUtility.h" +#import "Easydict-Swift.h" static CGFloat const kDismissPopButtonDelayTime = 0.1; static NSTimeInterval const kDelayGetSelectedTextTime = 0.1; @@ -300,7 +301,7 @@ - (void)getSelectedText:(BOOL)checkTextFrame completion:(void (^)(NSString *_Nul self.selectTextType = EZSelectTextTypeAccessibility; // Monitor CGEventTap must be required after using Accessibility successfully. - if (EZConfiguration.shared.autoSelectText) { + if (Configuration.shared.autoSelectText) { [self monitorCGEventTap]; } @@ -407,7 +408,7 @@ - (void)autoGetSelectedText:(BOOL)checkTextFrame { } - (BOOL)enabledAutoSelectText { - EZConfiguration *config = [EZConfiguration shared]; + Configuration *config = [Configuration shared]; BOOL enabled = config.autoSelectText && !config.disabledAutoSelect; if (!enabled) { NSLog(@"disabled autoSelectText"); @@ -437,7 +438,7 @@ - (void)getSelectedTextBySimulatedKey:(void (^)(NSString *_Nullable))completion // If playing audio, we do not silence system volume. [EZAudioUtils isPlayingAudio:^(BOOL isPlaying) { - BOOL shouldTurnOffSoundTemporarily = EZConfiguration.shared.disableEmptyCopyBeep && !isPlaying; + BOOL shouldTurnOffSoundTemporarily = Configuration.shared.disableEmptyCopyBeep && !isPlaying; // Set volume to 0 to avoid system alert. if (shouldTurnOffSoundTemporarily) { @@ -596,7 +597,7 @@ - (BOOL)isAccessibilityEnabled { /// Check if should use simulation key to get selected text. - (BOOL)shouldUseSimulatedKey:(NSString *)text error:(AXError)error { BOOL isAutoSelectQuery = self.actionType == EZActionTypeAutoSelectQuery; - BOOL allowedForceAutoGetSelectedText = [EZConfiguration.shared forceAutoGetSelectedText]; + BOOL allowedForceAutoGetSelectedText = [Configuration.shared forceAutoGetSelectedText]; NSString *easydictBundleID = [[NSBundle mainBundle] bundleIdentifier]; @@ -610,7 +611,7 @@ - (BOOL)shouldUseSimulatedKey:(NSString *)text error:(AXError)error { FIX: https://github.com/tisfeng/Easydict/issues/192#issuecomment-1797878909 */ - if (isInEasydict && EZConfiguration.shared.isRecordingSelectTextShortcutKey) { + if (isInEasydict && Configuration.shared.isRecordingSelectTextShortcutKey) { return NO; } diff --git a/Easydict/Feature/PerferenceWindow/DisableAutoSelectTextViewController/EZDisableAutoSelectTextViewController.m b/Easydict/Feature/PerferenceWindow/DisableAutoSelectTextViewController/EZDisableAutoSelectTextViewController.m index 477b392e3..86a5c8e56 100644 --- a/Easydict/Feature/PerferenceWindow/DisableAutoSelectTextViewController/EZDisableAutoSelectTextViewController.m +++ b/Easydict/Feature/PerferenceWindow/DisableAutoSelectTextViewController/EZDisableAutoSelectTextViewController.m @@ -16,6 +16,7 @@ #import "EZConfiguration.h" #import "NSImage+EZSymbolmage.h" #import "NSImage+EZResize.h" +#import "Easydict-Swift.h" static CGFloat const kMargin = 20; static CGFloat const kRowHeight = 45; @@ -254,7 +255,7 @@ - (void)selectApp { [openPanel setAllowedContentTypes:allowedTypes]; // ???: Since [auto select] will cause lag when dragging select apps, I don't know why 😰 - EZConfiguration.shared.disabledAutoSelect = YES; + Configuration.shared.disabledAutoSelect = YES; NSModalResponse result = [openPanel runModal]; if (result == NSModalResponseOK) { @@ -267,7 +268,7 @@ - (void)selectApp { [self.tableView reloadData]; } - EZConfiguration.shared.disabledAutoSelect = NO; + Configuration.shared.disabledAutoSelect = NO; } - (NSArray *)appModelsFromBundleIDDict:(NSDictionary *)appBundleIDDict { diff --git a/Easydict/Feature/PerferenceWindow/EZAboutViewController.m b/Easydict/Feature/PerferenceWindow/EZAboutViewController.m index 67fc4d277..9196c696a 100644 --- a/Easydict/Feature/PerferenceWindow/EZAboutViewController.m +++ b/Easydict/Feature/PerferenceWindow/EZAboutViewController.m @@ -10,6 +10,7 @@ #import "EZBlueTextButton.h" #import "EZConfiguration.h" #import "EZMenuItemManager.h" +#import "Easydict-Swift.h" @interface EZAboutViewController () @@ -35,7 +36,7 @@ - (void)viewDidLoad { [super viewDidLoad]; [self setupUI]; - self.autoCheckUpdateButton.mm_isOn = EZConfiguration.shared.automaticallyChecksForUpdates; + self.autoCheckUpdateButton.mm_isOn = Configuration.shared.automaticallyChecksForUpdates; [self updateViewSize]; @@ -177,7 +178,7 @@ - (void)updateViewConstraints { #pragma mark - Actions - (void)autoCheckUpdateButtonClicked:(NSButton *)sender { - EZConfiguration.shared.automaticallyChecksForUpdates = sender.mm_isOn; + Configuration.shared.automaticallyChecksForUpdates = sender.mm_isOn; } - (void)updateLatestVersion { diff --git a/Easydict/Feature/PerferenceWindow/EZPrivacyViewController.m b/Easydict/Feature/PerferenceWindow/EZPrivacyViewController.m index e5fc7ccd3..fb00a64e3 100644 --- a/Easydict/Feature/PerferenceWindow/EZPrivacyViewController.m +++ b/Easydict/Feature/PerferenceWindow/EZPrivacyViewController.m @@ -11,6 +11,7 @@ #import "EZConfiguration.h" #import "NSViewController+EZWindow.h" #import "NSImage+EZSymbolmage.h" +#import "Easydict-Swift.h" @interface EZPrivacyViewController () @@ -61,7 +62,7 @@ - (void)setupUI { action:@selector(analyticsButtonClicked:)]; [self.contentView addSubview:self.analyticsButton]; - EZConfiguration *configuration = [EZConfiguration shared]; + Configuration *configuration = [Configuration shared]; self.crashLogButton.mm_isOn = configuration.allowCrashLog; self.analyticsButton.mm_isOn = configuration.allowAnalytics; } @@ -120,16 +121,16 @@ - (void)crashLogButtonClicked:(NSButton *)sender { } else { sender.mm_isOn = YES; } - EZConfiguration.shared.allowCrashLog = sender.mm_isOn; + Configuration.shared.allowCrashLog = sender.mm_isOn; }]; } else { - EZConfiguration.shared.allowCrashLog = YES; + Configuration.shared.allowCrashLog = YES; } } - (void)analyticsButtonClicked:(NSButton *)sender { - EZConfiguration.shared.allowAnalytics = sender.mm_isOn; + Configuration.shared.allowAnalytics = sender.mm_isOn; } #pragma mark - MASPreferencesViewController diff --git a/Easydict/Feature/PerferenceWindow/EZSettingViewController.m b/Easydict/Feature/PerferenceWindow/EZSettingViewController.m index 528ab13e0..38d2aec42 100644 --- a/Easydict/Feature/PerferenceWindow/EZSettingViewController.m +++ b/Easydict/Feature/PerferenceWindow/EZSettingViewController.m @@ -17,7 +17,7 @@ @interface EZSettingViewController () -@property (nonatomic, strong) EZConfiguration *config; +@property (nonatomic, strong) Configuration *config; @property (nonatomic, strong) NSTextField *selectLabel; @property (nonatomic, strong) NSTextField *inputLabel; @@ -153,7 +153,7 @@ - (void)viewDidLoad { [super viewDidLoad]; // Do view setup here. - self.config = [EZConfiguration shared]; + self.config = [Configuration shared]; [self setupUI]; @@ -165,7 +165,7 @@ - (void)viewDidLoad { // Observe selectionShortcutView.recording status. [self.KVOController observe:self.selectionShortcutView keyPath:@"recording" options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew block:^(EZSettingViewController *settingVC, MASShortcutView *selectionShortcutView, NSDictionary *_Nonnull change) { - EZConfiguration.shared.isRecordingSelectTextShortcutKey = [change[NSKeyValueChangeNewKey] boolValue]; + Configuration.shared.isRecordingSelectTextShortcutKey = [change[NSKeyValueChangeNewKey] boolValue]; }]; } diff --git a/Easydict/Feature/Service/Apple/EZAppleService.m b/Easydict/Feature/Service/Apple/EZAppleService.m index e2a4b567c..be76679f2 100644 --- a/Easydict/Feature/Service/Apple/EZAppleService.m +++ b/Easydict/Feature/Service/Apple/EZAppleService.m @@ -16,6 +16,7 @@ #import #import "NSString+EZUtils.h" #import "EZAppleDictionary.h" +#import "Easydict-Swift.h" static NSString *const kLineBreakText = @"\n"; static NSString *const kParagraphBreakText = @"\n\n"; @@ -607,7 +608,7 @@ - (NLLanguage)detectUnkownText:(NSString *)text { NLLanguage language = NLLanguageEnglish; // 729 if ([text isNumbers]) { - EZLanguage firstLanguage = EZConfiguration.shared.firstLanguage; + EZLanguage firstLanguage = Configuration.shared.firstLanguage; language = [self appleLanguageFromLanguageEnum:firstLanguage]; } diff --git a/Easydict/Feature/Service/AudioPlayer/EZAudioPlayer.m b/Easydict/Feature/Service/AudioPlayer/EZAudioPlayer.m index 7ef68a030..ce07b3d7a 100644 --- a/Easydict/Feature/Service/AudioPlayer/EZAudioPlayer.m +++ b/Easydict/Feature/Service/AudioPlayer/EZAudioPlayer.m @@ -17,6 +17,7 @@ #import "EZServiceTypes.h" #import "EZConfiguration.h" #import +#import "Easydict-Swift.h" static NSString *const kFileExtendedAttributes = @"NSFileExtendedAttributes"; @@ -128,7 +129,7 @@ - (void)setIsPlaying:(BOOL)playing { // Note that user may change it when using, so we need to read it every time. - (EZQueryService *)defaultTTSService { - EZServiceType defaultTTSServiceType = EZConfiguration.shared.defaultTTSServiceType; + EZServiceType defaultTTSServiceType = Configuration.shared.defaultTTSServiceType; if (![_defaultTTSService.serviceType isEqualToString:defaultTTSServiceType]) { EZQueryService *defaultTTSService = [EZServiceTypes.shared serviceWithType:defaultTTSServiceType]; _defaultTTSService = defaultTTSService; diff --git a/Easydict/Feature/Service/Baidu/EZBaiduTranslate.m b/Easydict/Feature/Service/Baidu/EZBaiduTranslate.m index 5b6137076..4f1fb8101 100644 --- a/Easydict/Feature/Service/Baidu/EZBaiduTranslate.m +++ b/Easydict/Feature/Service/Baidu/EZBaiduTranslate.m @@ -13,6 +13,7 @@ #import "EZNetworkManager.h" #import "EZConfiguration.h" #import "NSString+EZRegex.h" +#import "Easydict-Swift.h" static NSString *const kBaiduTranslateURL = @"https://fanyi.baidu.com"; @@ -124,7 +125,8 @@ - (EZServiceType)serviceType { - (EZQueryTextType)queryTextType { EZQueryTextType defaultType = EZQueryTextTypeDictionary | EZQueryTextTypeSentence | EZQueryTextTypeTranslation; - EZQueryTextType type = [EZConfiguration.shared queryTextTypeForServiceType:self.serviceType]; +// EZQueryTextType type = [Configuration.shared queryTextTypeForServiceType:self.serviceType]; + EZQueryTextType type = [Configuration.shared queryTextTypeForServiceType:EZServiceTypeGoogle]; if (type == 0) { type = defaultType; } @@ -132,7 +134,7 @@ - (EZQueryTextType)queryTextType { } - (EZQueryTextType)intelligentQueryTextType { - EZQueryTextType type = [EZConfiguration.shared intelligentQueryTextTypeForServiceType:self.serviceType]; + EZQueryTextType type = [Configuration.shared intelligentQueryTextTypeForServiceType:self.serviceType]; return type; } diff --git a/Easydict/Feature/Service/Bing/EZBingService.m b/Easydict/Feature/Service/Bing/EZBingService.m index db282c86b..2b08d0ed1 100644 --- a/Easydict/Feature/Service/Bing/EZBingService.m +++ b/Easydict/Feature/Service/Bing/EZBingService.m @@ -12,6 +12,7 @@ #import "EZBingLookupModel.h" #import "EZConfiguration.h" #import "NSString+EZUtils.h" +#import "Easydict-Swift.h" @interface EZBingService () @property (nonatomic, strong) EZBingRequest *request; @@ -32,7 +33,7 @@ - (instancetype)init { #pragma mark - override - (EZQueryTextType)intelligentQueryTextType { - EZQueryTextType type = [EZConfiguration.shared intelligentQueryTextTypeForServiceType:self.serviceType]; + EZQueryTextType type = [Configuration.shared intelligentQueryTextTypeForServiceType:self.serviceType]; return type; } diff --git a/Easydict/Feature/Service/Google/EZGoogleTranslate.m b/Easydict/Feature/Service/Google/EZGoogleTranslate.m index 5c65d0e22..f2af0a9ae 100644 --- a/Easydict/Feature/Service/Google/EZGoogleTranslate.m +++ b/Easydict/Feature/Service/Google/EZGoogleTranslate.m @@ -11,6 +11,7 @@ #import #import "NSString+EZUtils.h" #import "EZConfiguration.h" +#import "Easydict-Swift.h" static NSString *const kGoogleTranslateURL = @"https://translate.google.com"; @@ -115,7 +116,7 @@ - (EZQueryTextType)queryTextType { } - (EZQueryTextType)intelligentQueryTextType { - EZQueryTextType type = [EZConfiguration.shared intelligentQueryTextTypeForServiceType:self.serviceType]; + EZQueryTextType type = [Configuration.shared intelligentQueryTextTypeForServiceType:self.serviceType]; return type; } diff --git a/Easydict/Feature/Service/Language/EZLanguageManager.m b/Easydict/Feature/Service/Language/EZLanguageManager.m index f2e430349..6650763d5 100644 --- a/Easydict/Feature/Service/Language/EZLanguageManager.m +++ b/Easydict/Feature/Service/Language/EZLanguageManager.m @@ -9,6 +9,7 @@ #import "EZLanguageManager.h" #import "EZAppleService.h" #import "EZConfiguration.h" +#import "Easydict-Swift.h" @interface EZLanguageManager () @@ -170,7 +171,7 @@ - (EZLanguage)systemSecondLanguage { } - (EZLanguage)userFirstLanguage { - EZLanguage firstLanguage = EZConfiguration.shared.firstLanguage; + EZLanguage firstLanguage = Configuration.shared.firstLanguage; if (!firstLanguage) { firstLanguage = [self systemPreferredTwoLanguages][0]; } @@ -178,7 +179,7 @@ - (EZLanguage)userFirstLanguage { } - (EZLanguage)userSecondLanguage { - EZLanguage secondLanguage = EZConfiguration.shared.secondLanguage; + EZLanguage secondLanguage = Configuration.shared.secondLanguage; if (!secondLanguage) { secondLanguage = [self systemPreferredTwoLanguages][1]; } diff --git a/Easydict/Feature/Service/Model/EZDetectManager.m b/Easydict/Feature/Service/Model/EZDetectManager.m index 40d6c9bff..0a037b41c 100644 --- a/Easydict/Feature/Service/Model/EZDetectManager.m +++ b/Easydict/Feature/Service/Model/EZDetectManager.m @@ -12,6 +12,7 @@ #import "EZConfiguration.h" #import "EZYoudaoTranslate.h" #import "EZConfiguration+EZUserData.h" +#import "Easydict-Swift.h" @interface EZDetectManager () @@ -101,7 +102,7 @@ - (void)detectText:(NSString *)queryText completion:(void (^)(EZQueryModel *_Non [self.appleService detectText:queryText completion:^(EZLanguage appleDetectdedLanguage, NSError *_Nullable error) { NSMutableArray *preferredLanguages = [[EZLanguageManager.shared preferredLanguages] mutableCopy]; - EZLanguageDetectOptimize languageDetectOptimize = EZConfiguration.shared.languageDetectOptimize; + EZLanguageDetectOptimize languageDetectOptimize = Configuration.shared.languageDetectOptimize; // Add English and Chinese to the preferred language list, in general, sysytem detect English and Chinese is relatively accurate, so we don't need to use google or baidu to detect again. [preferredLanguages addObjectsFromArray:@[ @@ -237,7 +238,7 @@ - (void)handleOCRResult:(EZOCRResult *_Nullable)ocrResult error:(NSError *_Nulla Sometimes Apple OCR may fail, like Japanese text, but we have set Japanese as preferred language and OCR again when OCR result is empty, currently it seems work, but we do not guarantee it is always work in other languages. */ - if ([EZConfiguration.shared isBeta]) { + if (Configuration.shared.beta) { [self.youdaoService ocr:self.queryModel completion:^(EZOCRResult *_Nullable youdaoOCRResult, NSError *_Nullable youdaoOCRError) { if (!youdaoOCRError) { completion(youdaoOCRResult, nil); diff --git a/Easydict/Feature/Service/Model/EZQueryService.m b/Easydict/Feature/Service/Model/EZQueryService.m index b7cc43e1c..a2a5f7734 100644 --- a/Easydict/Feature/Service/Model/EZQueryService.m +++ b/Easydict/Feature/Service/Model/EZQueryService.m @@ -12,6 +12,7 @@ #import "NSString+EZChineseText.h" #import "NSString+EZUtils.h" #import "EZConfiguration.h" +#import "Easydict-Swift.h" #define MethodNotImplemented() \ @throw [NSException exceptionWithName:NSInternalInconsistencyException \ @@ -54,7 +55,7 @@ - (BOOL)enabledAutoQuery { return NO; } - if ([EZConfiguration.shared intelligentQueryModeForWindowType:self.windowType]) { + if ([Configuration.shared intelligentQueryModeForWindowType:self.windowType]) { // We usually don't want to lookup dictionary if text word > 1. EZQueryTextType queryType = [self.queryModel.queryText queryTypeWithLanguage:self.queryModel.queryFromLanguage maxWordCount:1]; if ((queryType & self.intelligentQueryTextType) != queryType) { diff --git a/Easydict/Feature/Service/OpenAI/EZOpenAIService+EZPromptMessages.m b/Easydict/Feature/Service/OpenAI/EZOpenAIService+EZPromptMessages.m index 2bfa712d6..2b32e8d74 100644 --- a/Easydict/Feature/Service/OpenAI/EZOpenAIService+EZPromptMessages.m +++ b/Easydict/Feature/Service/OpenAI/EZOpenAIService+EZPromptMessages.m @@ -9,6 +9,7 @@ #import "EZOpenAIService+EZPromptMessages.h" #import "EZConfiguration.h" #import "NSString+EZUtils.h" +#import "Easydict-Swift.h" // You are a faithful translation assistant that can only translate text and cannot interpret it, you can only return the translated text, do not show additional descriptions and annotations. @@ -84,7 +85,7 @@ - (NSArray *)translatioMessages:(NSString *)text from:(EZLanguage)sourceLanguage /// Sentence messages. - (NSArray *)sentenceMessages:(NSString *)sentence from:(EZLanguage)sourceLanguage to:(EZLanguage)targetLanguage { - NSString *answerLanguage = EZConfiguration.shared.firstLanguage; + NSString *answerLanguage = Configuration.shared.firstLanguage; self.result.to = answerLanguage; NSString *prompt = @""; @@ -274,7 +275,7 @@ - (NSArray *)translatioMessages:(NSString *)text from:(EZLanguage)sourceLanguage // V5. prompt NSString *prompt = @""; - NSString *answerLanguage = EZConfiguration.shared.firstLanguage; + NSString *answerLanguage = Configuration.shared.firstLanguage; self.result.to = answerLanguage; NSString *pronunciation = @"Pronunciation"; diff --git a/Easydict/Feature/Service/OpenAI/EZOpenAIService.m b/Easydict/Feature/Service/OpenAI/EZOpenAIService.m index 1123049e4..f97a0ea71 100644 --- a/Easydict/Feature/Service/OpenAI/EZOpenAIService.m +++ b/Easydict/Feature/Service/OpenAI/EZOpenAIService.m @@ -57,7 +57,7 @@ - (NSString *)apiKey { // easydict://writeKeyValue?EZOpenAIAPIKey= NSString *apiKey = [[NSUserDefaults standardUserDefaults] stringForKey:EZOpenAIAPIKey] ?: @""; - if (apiKey.length == 0 && EZConfiguration.shared.isBeta) { + if (apiKey.length == 0 && Configuration.shared.beta) { apiKey = self.defaultAPIKey; } return apiKey; @@ -135,7 +135,7 @@ - (EZQueryTextType)queryTextType { } - (EZQueryTextType)intelligentQueryTextType { - EZQueryTextType type = [EZConfiguration.shared intelligentQueryTextTypeForServiceType:self.serviceType]; + EZQueryTextType type = [Configuration.shared intelligentQueryTextTypeForServiceType:self.serviceType]; return type; } diff --git a/Easydict/Feature/Service/Youdao/EZYoudaoTranslate.m b/Easydict/Feature/Service/Youdao/EZYoudaoTranslate.m index 0df3d35b1..3c9f476b4 100644 --- a/Easydict/Feature/Service/Youdao/EZYoudaoTranslate.m +++ b/Easydict/Feature/Service/Youdao/EZYoudaoTranslate.m @@ -174,7 +174,7 @@ - (EZQueryTextType)queryTextType { } - (EZQueryTextType)intelligentQueryTextType { - EZQueryTextType type = [EZConfiguration.shared intelligentQueryTextTypeForServiceType:self.serviceType]; + EZQueryTextType type = [Configuration.shared intelligentQueryTextTypeForServiceType:self.serviceType]; return type; } diff --git a/Easydict/Feature/StatusItem/EZMenuItemManager.m b/Easydict/Feature/StatusItem/EZMenuItemManager.m index 1d47cb1d6..8d9f3b017 100644 --- a/Easydict/Feature/StatusItem/EZMenuItemManager.m +++ b/Easydict/Feature/StatusItem/EZMenuItemManager.m @@ -70,7 +70,7 @@ - (void)setup { if (self.statusItem) { return; } - if (EZConfiguration.shared.hideMenuBarIcon) { + if (Configuration.shared.hideMenuBarIcon) { return; } @@ -273,12 +273,12 @@ - (IBAction)appleDictionaryAction:(NSMenuItem *)sender { } - (IBAction)increaseFontSizeAction:(NSMenuItem *)sender { - EZConfiguration.shared.fontSizeIndex += 1; + Configuration.shared.fontSizeIndex += 1; } - (IBAction)decreaseFontSizeAction:(NSMenuItem *)sender { - EZConfiguration.shared.fontSizeIndex -= 1; + Configuration.shared.fontSizeIndex -= 1; } diff --git a/Easydict/Feature/Utility/AppleScript/EZAppleScriptManager.m b/Easydict/Feature/Utility/AppleScript/EZAppleScriptManager.m index a32fb0dda..6cf871203 100644 --- a/Easydict/Feature/Utility/AppleScript/EZAppleScriptManager.m +++ b/Easydict/Feature/Utility/AppleScript/EZAppleScriptManager.m @@ -8,6 +8,7 @@ #import "EZAppleScriptManager.h" #import "EZConfiguration.h" +#import "Easydict-Swift.h" @interface EZAppleScriptManager () @@ -225,7 +226,7 @@ - (void)checkApplicationSupportCopyAction:(NSString *)appBundleID completion:(vo NSString *edit; if (!appLanguage) { - appLanguage = EZConfiguration.shared.firstLanguage; + appLanguage = Configuration.shared.firstLanguage; } if ([appLanguage isEqualToString:EZLanguageEnglish]) { diff --git a/Easydict/Feature/Utility/EZLinkParser/EZSchemeParser.m b/Easydict/Feature/Utility/EZLinkParser/EZSchemeParser.m index cd8ba1630..6a7a25442 100644 --- a/Easydict/Feature/Utility/EZLinkParser/EZSchemeParser.m +++ b/Easydict/Feature/Utility/EZLinkParser/EZSchemeParser.m @@ -14,6 +14,7 @@ #import "EZConfiguration+EZUserData.h" #import "EZConfiguration.h" #import "EZLocalStorage.h" +#import "Easydict-Swift.h" @implementation EZSchemeParser @@ -110,14 +111,14 @@ - (BOOL)writeKeyValues:(NSDictionary *)keyValues { NSString *value = keyValues[key]; handled = [self enabledReadWriteKey:key]; if (handled) { - EZConfiguration *config = [EZConfiguration shared]; - BOOL isBeta = config.isBeta; + Configuration *config = [Configuration shared]; + BOOL isBeta = config.beta; [[NSUserDefaults standardUserDefaults] setObject:value forKey:key]; // If enabling beta feature, setup beta features. - if (!isBeta && config.isBeta) { - [EZConfiguration.shared enableBetaFeaturesIfNeeded]; + if (!isBeta && config.beta) { + [Configuration.shared enableBetaFeaturesIfNeeded]; } } } @@ -154,15 +155,15 @@ - (BOOL)enabledReadWriteKey:(NSString *)key { - (void)resetUserDefaultsData { // easydict://resetUserDefaultsData - [EZConfiguration.shared resetUserDefaultsData]; + [Configuration.shared resetUserDefaultsData]; [EZLocalStorage destroySharedInstance]; - [EZConfiguration destroySharedInstance]; + [Configuration destroySharedInstance]; } - (void)saveUserDefaultsDataToDownloadFolder { // easydict://saveUserDefaultsDataToDownloadFolder - [EZConfiguration.shared saveUserDefaultsDataToDownloadFolder]; + [Configuration.shared saveUserDefaultsDataToDownloadFolder]; } diff --git a/Easydict/Feature/Utility/EZLog/EZLog.m b/Easydict/Feature/Utility/EZLog/EZLog.m index 81ba2860b..c17f1e7b9 100644 --- a/Easydict/Feature/Utility/EZLog/EZLog.m +++ b/Easydict/Feature/Utility/EZLog/EZLog.m @@ -47,7 +47,7 @@ + (void)setCrashEnabled:(BOOL)enabled { + (void)logEventWithName:(NSString *)name parameters:(nullable NSDictionary *)dict { // NSLog(@"log event: %@, %@", name, dict); - if (![EZConfiguration.shared allowAnalytics]) { + if (![Configuration.shared allowAnalytics]) { return; } diff --git a/Easydict/Feature/ViewController/Cell/EZSelectLanguageCell.m b/Easydict/Feature/ViewController/Cell/EZSelectLanguageCell.m index bc993c1df..1be65ee65 100644 --- a/Easydict/Feature/ViewController/Cell/EZSelectLanguageCell.m +++ b/Easydict/Feature/ViewController/Cell/EZSelectLanguageCell.m @@ -11,6 +11,7 @@ #import "EZConfiguration.h" #import "NSColor+MyColors.h" #import "EZHoverButton.h" +#import "Easydict-Swift.h" @interface EZSelectLanguageCell () @@ -86,8 +87,8 @@ - (void)setup { mm_strongify(self); self.queryModel.userSourceLanguage = selectedLanguage; - if (![selectedLanguage isEqualToString:EZConfiguration.shared.from]) { - EZConfiguration.shared.from = selectedLanguage; + if (![selectedLanguage isEqualToString:Configuration.shared.fromLanguage]) { + Configuration.shared.fromLanguage = selectedLanguage; [self enterAction]; } }]; @@ -103,8 +104,8 @@ - (void)setup { mm_strongify(self); self.queryModel.userTargetLanguage = selectedLanguage; - if (![selectedLanguage isEqualToString:EZConfiguration.shared.to]) { - EZConfiguration.shared.to = selectedLanguage; + if (![selectedLanguage isEqualToString:Configuration.shared.toLanguage]) { + Configuration.shared.toLanguage = selectedLanguage; [self enterAction]; } }]; @@ -164,8 +165,8 @@ - (void)toggleTranslationLanguages { EZLanguage toLang = self.queryModel.userTargetLanguage; if (![fromLang isEqualToString:toLang]) { - EZConfiguration.shared.from = toLang; - EZConfiguration.shared.to = fromLang; + Configuration.shared.fromLanguage = toLang; + Configuration.shared.toLanguage = fromLang; [self.fromLanguageButton setSelectedLanguage:toLang]; [self.toLanguageButton setSelectedLanguage:fromLang]; @@ -181,7 +182,7 @@ - (void)enterAction { [self setNeedsUpdateConstraints:YES]; if (self.enterActionBlock) { - self.enterActionBlock(EZConfiguration.shared.from, EZConfiguration.shared.to); + self.enterActionBlock(Configuration.shared.fromLanguage, Configuration.shared.toLanguage); } } diff --git a/Easydict/Feature/ViewController/Model/EZQueryModel.m b/Easydict/Feature/ViewController/Model/EZQueryModel.m index c398ffd87..810385940 100644 --- a/Easydict/Feature/ViewController/Model/EZQueryModel.m +++ b/Easydict/Feature/ViewController/Model/EZQueryModel.m @@ -13,6 +13,7 @@ #import "NSString+EZSplit.h" #import "EZAppleDictionary.h" #import "NSString+EZHandleInputText.h" +#import "Easydict-Swift.h" @interface EZQueryModel () @@ -29,10 +30,10 @@ @implementation EZQueryModel - (instancetype)init { if (self = [super init]) { - [self.KVOController observe:EZConfiguration.shared keyPath:@"from" options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew block:^(EZQueryModel *queryModel, EZConfiguration *config, NSDictionary *_Nonnull change) { + [self.KVOController observe:Configuration.shared keyPath:@"fromLanguage" options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew block:^(EZQueryModel *queryModel, Configuration *config, NSDictionary *_Nonnull change) { queryModel.userSourceLanguage = change[NSKeyValueChangeNewKey]; }]; - [self.KVOController observe:EZConfiguration.shared keyPath:@"to" options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew block:^(EZQueryModel *queryModel, EZConfiguration *config, NSDictionary *_Nonnull change) { + [self.KVOController observe:Configuration.shared keyPath:@"toLanguage" options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew block:^(EZQueryModel *queryModel, Configuration *config, NSDictionary *_Nonnull change) { queryModel.userTargetLanguage = change[NSKeyValueChangeNewKey]; }]; @@ -198,7 +199,7 @@ - (NSString *)handleInputText:(NSString *)inputText { } } - if (EZConfiguration.shared.isBeta) { + if (Configuration.shared.beta) { // Remove prefix [//,#,*,] and join texts. queryText = [queryText removeCommentBlockSymbols]; } diff --git a/Easydict/Feature/ViewController/View/EZQueryMenuTextView/EZQueryMenuTextView.m b/Easydict/Feature/ViewController/View/EZQueryMenuTextView/EZQueryMenuTextView.m index 6a88cde89..ab46a8a8b 100644 --- a/Easydict/Feature/ViewController/View/EZQueryMenuTextView/EZQueryMenuTextView.m +++ b/Easydict/Feature/ViewController/View/EZQueryMenuTextView/EZQueryMenuTextView.m @@ -12,6 +12,7 @@ #import "EZCoordinateUtils.h" #import "EZLog.h" #import "NSString+EZUtils.h" +#import "Easydict-Swift.h" @interface EZQueryMenuTextView () @@ -54,10 +55,10 @@ - (void)queryInApp:(id)sender { EZWindowManager *windowManager = [EZWindowManager shared]; EZWindowType floatingWindowType = windowManager.floatingWindowType; - if (EZConfiguration.shared.mouseSelectTranslateWindowType == floatingWindowType) { - anotherWindowType = EZConfiguration.shared.shortcutSelectTranslateWindowType; + if (Configuration.shared.mouseSelectTranslateWindowType == floatingWindowType) { + anotherWindowType = Configuration.shared.shortcutSelectTranslateWindowType; } else { - anotherWindowType = EZConfiguration.shared.mouseSelectTranslateWindowType; + anotherWindowType = Configuration.shared.mouseSelectTranslateWindowType; } if (anotherWindowType != floatingWindowType) { diff --git a/Easydict/Feature/ViewController/View/QueryView/EZQueryView.m b/Easydict/Feature/ViewController/View/QueryView/EZQueryView.m index 964cd6483..a99a4d73a 100644 --- a/Easydict/Feature/ViewController/View/QueryView/EZQueryView.m +++ b/Easydict/Feature/ViewController/View/QueryView/EZQueryView.m @@ -74,7 +74,7 @@ - (void)setup { textView.delegate = self; textView.textStorage.delegate = self; textView.textContainerInset = CGSizeMake(6, 8); - textView.font = [NSFont systemFontOfSize:14 * EZConfiguration.shared.fontSizeRatio]; + textView.font = [NSFont systemFontOfSize:14 * Configuration.shared.fontSizeRatio]; mm_weakify(self); [textView setPasteTextBlock:^(NSString *_Nonnull text) { @@ -87,7 +87,7 @@ - (void)setup { [[NSNotificationCenter defaultCenter] addObserverForName:ChangeFontSizeView.changeFontSizeNotificationName object:nil queue:NSOperationQueue.mainQueue usingBlock:^(NSNotification * _Nonnull notification) { mm_strongify(self); - self.textView.font = [NSFont systemFontOfSize:14 * EZConfiguration.shared.fontSizeRatio]; + self.textView.font = [NSFont systemFontOfSize:14 * Configuration.shared.fontSizeRatio]; }]; // When programatically setting the text, like auto select text, or OCR text. diff --git a/Easydict/Feature/ViewController/View/Titlebar/EZTitlebar.m b/Easydict/Feature/ViewController/View/Titlebar/EZTitlebar.m index e6cb2d6e7..2b2c364aa 100644 --- a/Easydict/Feature/ViewController/View/Titlebar/EZTitlebar.m +++ b/Easydict/Feature/ViewController/View/Titlebar/EZTitlebar.m @@ -13,6 +13,7 @@ #import "NSObject+EZDarkMode.h" #import "EZBaseQueryWindow.h" #import "EZConfiguration.h" +#import "Easydict-Swift.h" @interface EZTitlebar () @@ -92,7 +93,7 @@ - (void)updateConstraints { // TODO: We should refactor it later. // Google - if (EZConfiguration.shared.showGoogleQuickLink) { + if (Configuration.shared.showGoogleQuickLink) { EZOpenLinkButton *googleButton = [[EZOpenLinkButton alloc] init]; [self addSubview:googleButton]; self.googleButton = googleButton; @@ -116,7 +117,7 @@ - (void)updateConstraints { } // Apple Dictionary - if (EZConfiguration.shared.showAppleDictionaryQuickLink) { + if (Configuration.shared.showAppleDictionaryQuickLink) { EZOpenLinkButton *appleDictButton = [[EZOpenLinkButton alloc] init]; [self addSubview:appleDictButton]; self.appleDictionaryButton = appleDictButton; @@ -140,7 +141,7 @@ - (void)updateConstraints { } // Eudic - if (EZConfiguration.shared.showEudicQuickLink) { + if (Configuration.shared.showEudicQuickLink) { EZOpenLinkButton *eudicButton = [[EZOpenLinkButton alloc] init]; // !!!: Note that some applications have multiple channel versions. Ref: https://github.com/tisfeng/Raycast-Easydict/issues/16 diff --git a/Easydict/Feature/ViewController/View/WordResultView/EZWebViewManager.m b/Easydict/Feature/ViewController/View/WordResultView/EZWebViewManager.m index aafe9b446..7c32f3634 100644 --- a/Easydict/Feature/ViewController/View/WordResultView/EZWebViewManager.m +++ b/Easydict/Feature/ViewController/View/WordResultView/EZWebViewManager.m @@ -8,6 +8,7 @@ #import "EZWebViewManager.h" #import "EZConfiguration.h" +#import "Easydict-Swift.h" static NSString *kObjcHandler = @"objcHandler"; static NSString *kMethod = @"method"; @@ -57,7 +58,7 @@ - (void)userContentController:(WKUserContentController *)userContentController d #pragma mark - WebView evaluateJavaScript - (void)updateAllIframe { - CGFloat fontSize = EZConfiguration.shared.fontSizeRatio; // 1.4 --> 140% + CGFloat fontSize = Configuration.shared.fontSizeRatio; // 1.4 --> 140% NSString *script = [NSString stringWithFormat:@"changeIframeBodyFontSize(%.1f); updateAllIframeStyle();", fontSize]; [self.webView evaluateJavaScript:script completionHandler:^(id _Nullable result, NSError *_Nullable error) { if (!error) { diff --git a/Easydict/Feature/ViewController/View/WordResultView/EZWordResultView.m b/Easydict/Feature/ViewController/View/WordResultView/EZWordResultView.m index 10268c06b..0bf1f2b72 100644 --- a/Easydict/Feature/ViewController/View/WordResultView/EZWordResultView.m +++ b/Easydict/Feature/ViewController/View/WordResultView/EZWordResultView.m @@ -58,7 +58,7 @@ - (instancetype)initWithFrame:(NSRect)frame { if (self) { self.wantsLayer = YES; self.layer.cornerRadius = EZCornerRadius_8; - self.fontSizeRatio = EZConfiguration.shared.fontSizeRatio; + self.fontSizeRatio = Configuration.shared.fontSizeRatio; [self.layer excuteLight:^(CALayer *layer) { layer.backgroundColor = [NSColor ez_resultViewBgLightColor].CGColor; } dark:^(CALayer *layer) { @@ -71,7 +71,7 @@ - (instancetype)initWithFrame:(NSRect)frame { // TODO: This method is too long, need to refactor. - (void)refreshWithResult:(EZQueryResult *)result { self.result = result; - self.fontSizeRatio = EZConfiguration.shared.fontSizeRatio; + self.fontSizeRatio = Configuration.shared.fontSizeRatio; EZTranslateWordResult *wordResult = result.wordResult; self.webView = result.webViewManager.webView; @@ -826,7 +826,7 @@ - (void)refreshWithResult:(EZQueryResult *)result { language = result.to; } - EZServiceType defaultTTSServiceType = EZConfiguration.shared.defaultTTSServiceType; + EZServiceType defaultTTSServiceType = Configuration.shared.defaultTTSServiceType; EZQueryService *defaultTTSService = [EZServiceTypes.shared serviceWithType:defaultTTSServiceType]; [result.service.audioPlayer playTextAudio:text @@ -1324,7 +1324,7 @@ - (void)getTextWithHref:(NSString *)href completionHandler:(void (^_Nullable)(NS } - (void)updateWebViewAllIframeFontSize { - CGFloat fontSize = EZConfiguration.shared.fontSizeRatio * 100; + CGFloat fontSize = Configuration.shared.fontSizeRatio * 100; NSString *jsCode = [NSString stringWithFormat: @"var iframes = document.querySelectorAll('iframe');" diff --git a/Easydict/Feature/ViewController/Window/BaseQueryWindow/EZBaseQueryViewController.m b/Easydict/Feature/ViewController/Window/BaseQueryWindow/EZBaseQueryViewController.m index 58d48a8a3..c1bb5cc13 100644 --- a/Easydict/Feature/ViewController/Window/BaseQueryWindow/EZBaseQueryViewController.m +++ b/Easydict/Feature/ViewController/Window/BaseQueryWindow/EZBaseQueryViewController.m @@ -192,7 +192,7 @@ - (void)setupServices { NSMutableArray *services = [NSMutableArray array]; self.youdaoService = nil; - EZServiceType defaultTTSServiceType = EZConfiguration.shared.defaultTTSServiceType; + EZServiceType defaultTTSServiceType = Configuration.shared.defaultTTSServiceType; NSArray *allServices = [EZLocalStorage.shared allServices:self.windowType]; for (EZQueryService *service in allServices) { @@ -352,7 +352,7 @@ - (NSString *)queryText { } - (EZQueryService *)defaultTTSService { - EZServiceType defaultTTSServiceType = EZConfiguration.shared.defaultTTSServiceType; + EZServiceType defaultTTSServiceType = Configuration.shared.defaultTTSServiceType; if (![_defaultTTSService.serviceType isEqualToString:defaultTTSServiceType]) { _defaultTTSService = [EZServiceTypes.shared serviceWithType:defaultTTSServiceType]; } @@ -480,7 +480,7 @@ - (void)startOCRImage:(NSImage *)image actionType:(EZActionType)actionType { return; } - if (EZConfiguration.shared.autoCopyOCRText) { + if (Configuration.shared.autoCopyOCRText) { [inputText copyToPasteboardSafely]; } @@ -493,7 +493,7 @@ - (void)startOCRImage:(NSImage *)image actionType:(EZActionType)actionType { return; } - BOOL autoSnipTranslate = EZConfiguration.shared.autoQueryOCRText; + BOOL autoSnipTranslate = Configuration.shared.autoQueryOCRText; if (autoSnipTranslate && queryModel.autoQuery) { [self startQueryText]; } @@ -1199,7 +1199,7 @@ - (EZQueryView *)createQueryView { [queryView setPasteTextBlock:^(NSString *_Nonnull text) { mm_strongify(self); [self detectQueryText:^(NSString *_Nonnull language) { - if ([EZConfiguration.shared autoQueryPastedText]) { + if ([Configuration.shared autoQueryPastedText]) { [self startQueryWithType:EZActionTypeInputQuery]; } }]; @@ -1484,7 +1484,7 @@ - (CGFloat)miniQueryViewHeight { #pragma mark - Auto play English word - (void)autoPlayEnglishWordAudio { - if (!EZConfiguration.shared.autoPlayAudio) { + if (!Configuration.shared.autoPlayAudio) { return; } @@ -1502,7 +1502,7 @@ - (void)autoPlayEnglishWordAudio { /// Auto copy translated text. - (void)autoCopyTranslatedTextOfService:(EZQueryService *)service { - if (![EZConfiguration.shared autoCopyFirstTranslatedText]) { + if (![Configuration.shared autoCopyFirstTranslatedText]) { service.autoCopyTranslatedTextBlock = nil; return; } diff --git a/Easydict/Feature/ViewController/Window/WindowManager/EZLayoutManager.m b/Easydict/Feature/ViewController/Window/WindowManager/EZLayoutManager.m index 0fecef8c3..3b8490d02 100644 --- a/Easydict/Feature/ViewController/Window/WindowManager/EZLayoutManager.m +++ b/Easydict/Feature/ViewController/Window/WindowManager/EZLayoutManager.m @@ -9,6 +9,7 @@ #import "EZLayoutManager.h" #import "EZBaseQueryWindow.h" #import "EZConfiguration.h" +#import "Easydict-Swift.h" @interface EZLayoutManager () @@ -46,7 +47,7 @@ - (void)commonInitialize { self.screen = NSScreen.mainScreen; self.minimumWindowSize = CGSizeMake(300, 70); - EZConfiguration *configuration = [EZConfiguration shared]; + Configuration *configuration = [Configuration shared]; self.miniWindowFrame = [configuration windowFrameWithType:EZWindowTypeMini]; if (CGRectEqualToRect(self.miniWindowFrame, CGRectZero)) { @@ -207,7 +208,7 @@ - (void)updateWindowFrame:(EZBaseQueryWindow *)window { break; } - [EZConfiguration.shared setWindowFrame:window.frame windowType:windowType]; + [Configuration.shared setWindowFrame:window.frame windowType:windowType]; } @end diff --git a/Easydict/Feature/ViewController/Window/WindowManager/EZWindowManager.m b/Easydict/Feature/ViewController/Window/WindowManager/EZWindowManager.m index 24204c5e4..dd2c18664 100644 --- a/Easydict/Feature/ViewController/Window/WindowManager/EZWindowManager.m +++ b/Easydict/Feature/ViewController/Window/WindowManager/EZWindowManager.m @@ -15,6 +15,7 @@ #import "EZPreferencesWindowController.h" #import "EZConfiguration.h" #import "EZLog.h" +#import "Easydict-Swift.h" @interface EZWindowManager () @@ -154,7 +155,7 @@ - (void)updatePopButtonQueryAction { mm_weakify(self); EZButton *popButton = self.popButtonWindow.popButton; - EZConfiguration *config = [EZConfiguration shared]; + Configuration *config = [Configuration shared]; if (config.hideMainWindow) { // FIXME: Click pop button will also show preferences window. @@ -182,7 +183,7 @@ - (void)updatePopButtonQueryAction { } - (void)popButtonWindowClicked { - EZWindowType windowType = EZConfiguration.shared.mouseSelectTranslateWindowType; + EZWindowType windowType = Configuration.shared.mouseSelectTranslateWindowType; self.actionType = EZActionTypeAutoSelectQuery; [self showFloatingWindowType:windowType queryText:self.selectedText]; [self->_popButtonWindow close]; @@ -291,7 +292,7 @@ - (void)showFloatingWindowType:(EZWindowType)windowType queryText:(nullable NSSt - (void)showFloatingWindowType:(EZWindowType)windowType queryText:(nullable NSString *)queryText actionType:(EZActionType)actionType { - BOOL autoQuery = [EZConfiguration.shared autoQuerySelectedText]; + BOOL autoQuery = [Configuration.shared autoQuerySelectedText]; [self showFloatingWindowType:windowType queryText:queryText autoQuery:autoQuery actionType:actionType]; } @@ -308,7 +309,7 @@ - (void)showFloatingWindowType:(EZWindowType)windowType actionType:(EZActionType)actionType atPoint:(CGPoint)point completionHandler:(nullable void (^)(void))completionHandler { - BOOL autoQuery = [EZConfiguration.shared autoQuerySelectedText]; + BOOL autoQuery = [Configuration.shared autoQuerySelectedText]; [self showFloatingWindowType:windowType queryText:queryText autoQuery:autoQuery actionType:actionType atPoint:point completionHandler:completionHandler]; } @@ -361,7 +362,7 @@ - (void)showFloatingWindowType:(EZWindowType)windowType } // TODO: Maybe we should remove this option, it seems useless. - if ([EZConfiguration.shared autoCopySelectedText]) { + if ([Configuration.shared autoCopySelectedText]) { [queryText copyToPasteboard]; } @@ -517,7 +518,7 @@ - (CGPoint)getPopButtonWindowLocation { // NSLog(@"start point: %@", NSStringFromPoint(startLocation)); // NSLog(@"end point: %@", NSStringFromPoint(endLocation)); - if (EZConfiguration.shared.adjustPopButtomOrigin) { + if (Configuration.shared.adjustPopButtomOrigin) { // Since the pop button may cover selected text, we need to move it to the left. CGFloat horizontalOffset = 20; @@ -539,7 +540,7 @@ - (CGPoint)getPopButtonWindowLocation { - (CGPoint)getMiniWindowLocation { CGPoint position = [self getShowingMouseLocation]; - if (EZConfiguration.shared.adjustPopButtomOrigin) { + if (Configuration.shared.adjustPopButtomOrigin) { position.y = position.y - 8; } @@ -587,7 +588,7 @@ - (CGPoint)getMouseLocation:(BOOL)offsetFlag { /// !!!: This return value is top-left point. - (CGPoint)getFixedWindowLocation { CGPoint position = CGPointZero; - EZShowWindowPosition windowPosition = EZConfiguration.shared.fixedWindowPosition; + EZShowWindowPosition windowPosition = Configuration.shared.fixedWindowPosition; switch (windowPosition) { case EZShowWindowPositionRight: { position = [self getFloatingWindowInRightSideOfScreenPoint:self.fixedWindow]; @@ -651,7 +652,7 @@ - (void)saveFrontmostApplication { } - (void)showMainWindowIfNedded { - BOOL showFlag = !EZConfiguration.shared.hideMainWindow; + BOOL showFlag = !Configuration.shared.hideMainWindow; NSApplicationActivationPolicy activationPolicy = showFlag ? NSApplicationActivationPolicyRegular : NSApplicationActivationPolicyAccessory; [NSApp setActivationPolicy:activationPolicy]; @@ -689,7 +690,7 @@ - (void)selectTextTranslate { return; } - EZWindowType windowType = EZConfiguration.shared.shortcutSelectTranslateWindowType; + EZWindowType windowType = Configuration.shared.shortcutSelectTranslateWindowType; NSLog(@"selectTextTranslate windowType: %@", @(windowType)); self.eventMonitor.actionType = EZActionTypeShortcutQuery; [self.eventMonitor getSelectedText:^(NSString *_Nullable text) { @@ -715,7 +716,7 @@ - (void)snipTranslate { } // Since ocr detect may be inaccurate, sometimes need to set sourceLanguage manually, so show Fixed window. - EZWindowType windowType = EZConfiguration.shared.shortcutSelectTranslateWindowType; + EZWindowType windowType = Configuration.shared.shortcutSelectTranslateWindowType; EZBaseQueryWindow *window = [self windowWithType:windowType]; // Wait to close floating window if need. @@ -755,7 +756,7 @@ - (void)inputTranslate { return; } - EZWindowType windowType = EZConfiguration.shared.shortcutSelectTranslateWindowType; + EZWindowType windowType = Configuration.shared.shortcutSelectTranslateWindowType; if (self.floatingWindowType == windowType) { [self closeFloatingWindow]; @@ -763,7 +764,7 @@ - (void)inputTranslate { } NSString *queryText = nil; - if ([EZConfiguration.shared clearInput]) { + if ([Configuration.shared clearInput]) { queryText = @""; } @@ -775,7 +776,7 @@ - (void)inputTranslate { - (void)showMiniFloatingWindow { MMLogInfo(@"showMiniFloatingWindow"); - EZWindowType windowType = EZConfiguration.shared.mouseSelectTranslateWindowType; + EZWindowType windowType = Configuration.shared.mouseSelectTranslateWindowType; if (self.floatingWindowType == windowType) { [self closeFloatingWindow]; diff --git a/Easydict/NewApp/Configuration/Configuration.swift b/Easydict/NewApp/Configuration/Configuration.swift index 6af419287..ea32d77c2 100644 --- a/Easydict/NewApp/Configuration/Configuration.swift +++ b/Easydict/NewApp/Configuration/Configuration.swift @@ -60,6 +60,11 @@ extension Defaults.Keys { return .init(key, default: EZQueryTextType(rawValue: 7)) } + static func queryTextType(for serviceType: ServiceType) -> Key { + let key = EZConstKey.constkey("QueryTextType", serviceType: serviceType) + return .init(key, default: EZQueryTextType(rawValue: 0)) + } + static func windorFrame(for windowType: EZWindowType) -> Key { let key = "EZConfiguration_kWindowFrameKey_\(windowType)" return .init(key, default: .zero) @@ -155,5 +160,4 @@ extension Defaults.Keys { // ALI static let aliAccessKeyId = Key("EZAliAccessKeyId") static let aliAccessKeySecret = Key("EZAliAccessKeySecret") - }