Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce Defaults package into project and implement Setting - General with SwiftUI #323

Merged
merged 13 commits into from
Jan 14, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions Easydict.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,8 @@
DC3C643F2B187119008EEDD8 /* ChangeFontSizeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC3C643E2B187119008EEDD8 /* ChangeFontSizeView.swift */; };
DC6D9C872B352EBC0055EFFC /* FontSizeHintView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC6D9C862B352EBC0055EFFC /* FontSizeHintView.swift */; };
DC6D9C892B3969510055EFFC /* Appearance.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC6D9C882B3969510055EFFC /* Appearance.swift */; };
EA3B81F92B5254AA004C0E8B /* EZConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA3B81F82B5254AA004C0E8B /* EZConfiguration.swift */; };
EA3B81FC2B52555C004C0E8B /* Defaults in Frameworks */ = {isa = PBXBuildFile; productRef = EA3B81FB2B52555C004C0E8B /* Defaults */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -737,6 +739,7 @@
DC3C643E2B187119008EEDD8 /* ChangeFontSizeView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ChangeFontSizeView.swift; sourceTree = "<group>"; };
DC6D9C862B352EBC0055EFFC /* FontSizeHintView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FontSizeHintView.swift; sourceTree = "<group>"; };
DC6D9C882B3969510055EFFC /* Appearance.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Appearance.swift; sourceTree = "<group>"; };
EA3B81F82B5254AA004C0E8B /* EZConfiguration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EZConfiguration.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -778,6 +781,7 @@
03A830922B4073E700112834 /* AppCenterCrashes in Frameworks */,
03022F1C2B35DEBA00B63209 /* Hue in Frameworks */,
03A830952B4076FC00112834 /* FirebaseAnalyticsSwift in Frameworks */,
EA3B81FC2B52555C004C0E8B /* Defaults in Frameworks */,
03CF27FE2B3DA7D500E19B57 /* Realm in Frameworks */,
03A830902B4073E700112834 /* AppCenterAnalytics in Frameworks */,
03B63ABF2A86967800E155ED /* CoreServices.framework in Frameworks */,
Expand Down Expand Up @@ -1994,6 +1998,7 @@
27FE98032B3DCA9F000AD654 /* NewApp */ = {
isa = PBXGroup;
children = (
EA3B81F72B52549B004C0E8B /* Configuration */,
27FE95262B3DC55F000AD654 /* EasydictApp.swift */,
27FE98042B3DCB09000AD654 /* NewAppManager.swift */,
27FE98062B3DD525000AD654 /* View */,
Expand Down Expand Up @@ -2143,6 +2148,14 @@
path = ChangeFontSizeView;
sourceTree = "<group>";
};
EA3B81F72B52549B004C0E8B /* Configuration */ = {
isa = PBXGroup;
children = (
EA3B81F82B5254AA004C0E8B /* EZConfiguration.swift */,
);
path = Configuration;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand Down Expand Up @@ -2234,6 +2247,7 @@
038030962B4106800009230C /* CocoaLumberjackSwift */,
038EA1A92B41169C008A6DD1 /* ZipArchive */,
038EA1AC2B41282F008A6DD1 /* MJExtension */,
EA3B81FB2B52555C004C0E8B /* Defaults */,
);
productName = Bob;
productReference = C99EEB182385796700FEE666 /* Easydict-debug.app */;
Expand Down Expand Up @@ -2292,6 +2306,7 @@
038030932B4106800009230C /* XCRemoteSwiftPackageReference "CocoaLumberjack" */,
038EA1A82B41169C008A6DD1 /* XCRemoteSwiftPackageReference "ZipArchive" */,
038EA1AB2B41282F008A6DD1 /* XCRemoteSwiftPackageReference "MJExtension" */,
EA3B81FA2B52555C004C0E8B /* XCRemoteSwiftPackageReference "Defaults" */,
);
productRefGroup = C99EEB192385796700FEE666 /* Products */;
projectDirPath = "";
Expand Down Expand Up @@ -2591,6 +2606,7 @@
03B0233229231FA6001C7E63 /* MMLog.swift in Sources */,
03DC7C5E2A3ABE28000BF7C9 /* EZConstKey.m in Sources */,
62E2BF4C2B4082BA00E42D38 /* AliTranslateType.swift in Sources */,
EA3B81F92B5254AA004C0E8B /* EZConfiguration.swift in Sources */,
03E3E7C22ADE318800812C84 /* EZQueryMenuTextView.m in Sources */,
03B0231829231FA6001C7E63 /* SnipWindowController.m in Sources */,
03542A342936F70F00C34C33 /* EZLanguageManager.m in Sources */,
Expand Down Expand Up @@ -3251,6 +3267,14 @@
minimumVersion = 5.8.1;
};
};
EA3B81FA2B52555C004C0E8B /* XCRemoteSwiftPackageReference "Defaults" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/sindresorhus/Defaults.git";
requirement = {
branch = main;
kind = branch;
CanglongCl marked this conversation as resolved.
Show resolved Hide resolved
};
};
/* End XCRemoteSwiftPackageReference section */

/* Begin XCSwiftPackageProductDependency section */
Expand Down Expand Up @@ -3329,6 +3353,11 @@
package = 2721E4CE2AFE920700A059AC /* XCRemoteSwiftPackageReference "Alamofire" */;
productName = Alamofire;
};
EA3B81FB2B52555C004C0E8B /* Defaults */ = {
isa = XCSwiftPackageProductDependency;
package = EA3B81FA2B52555C004C0E8B /* XCRemoteSwiftPackageReference "Defaults" */;
productName = Defaults;
};
/* End XCSwiftPackageProductDependency section */
};
rootObject = C99EEB102385796700FEE666 /* Project object */;
Expand Down
11 changes: 10 additions & 1 deletion Easydict.xcworkspace/xcshareddata/swiftpm/Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
{
"identity" : "alamofire",
"kind" : "remoteSourceControl",
"location" : "https://github.com/Alamofire/Alamofire",
"location" : "https://github.com/Alamofire/Alamofire.git",
"state" : {
"revision" : "3dc6a42c7727c49bf26508e29b0a0b35f9c7e1ad",
"version" : "5.8.1"
Expand Down Expand Up @@ -54,6 +54,15 @@
"version" : "1.8.0"
}
},
{
"identity" : "defaults",
"kind" : "remoteSourceControl",
"location" : "https://github.com/sindresorhus/Defaults.git",
"state" : {
"branch" : "main",
"revision" : "d8a9f5105607c85b544558e7f5b51d6c360ba88b"
}
},
{
"identity" : "firebase-ios-sdk",
"kind" : "remoteSourceControl",
Expand Down
36 changes: 36 additions & 0 deletions Easydict/App/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -2172,6 +2172,42 @@
}
}
}
},
"setting.general.advance.header" : {

},
"setting.general.auto_copy.header" : {

},
"setting.general.auto_query.header" : {

},
"setting.general.input.header" : {

},
"setting.general.language.header" : {

},
"setting.general.mouse_query.adjust_pop_button_origin" : {

},
"setting.general.mouse_query.header" : {

},
"setting.general.quick_link.header" : {

},
"setting.general.voice.auto_play_word_audio" : {

},
"setting.general.voice.disable_empty_copy_beep_msg" : {

},
"setting.general.voice.header" : {

},
"setting.general.windows.header" : {

},
"Settings..." : {
"localizations" : {
Expand Down
43 changes: 43 additions & 0 deletions Easydict/NewApp/Configuration/EZConfiguration.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//
// EZConfiguration.swift
CanglongCl marked this conversation as resolved.
Show resolved Hide resolved
// Easydict
//
// Created by 戴藏龙 on 2024/1/12.
// Copyright © 2024 izual. All rights reserved.
//

import Defaults
import Foundation

extension Defaults.Keys {
// static let firstLanguage = Key<EZLanguage>("EZConfiguration_kFirstLanguageKey", default: true)

static let autoSelectText = Key<Bool>("EZConfiguration_kAutoSelectTextKey", default: true)
static let forceAutoGetSelectedText = Key<Bool>("EZConfiguration_kForceAutoGetSelectedText", default: false)

static let disableEmptyCopyBeep = Key<Bool>("EZConfiguration_kDisableEmptyCopyBeepKey", default: true)
static let clickQuery = Key<Bool>("EZConfiguration_kClickQueryKey", default: false)
static let autoPlayAudio = Key<Bool>("EZConfiguration_kAutoPlayAudioKey", default: true)
static let launchAtStartup = Key<Bool>("EZConfiguration_kLaunchAtStartupKey", default: false)
static let hideMainWindow = Key<Bool>("EZConfiguration_kHideMainWindowKey", default: true)
static let autoQueryOCRText = Key<Bool>("EZConfiguration_kAutoQueryOCTTextKey", default: true)
static let autoQuerySelectedText = Key<Bool>("EZConfiguration_kAutoQuerySelectedTextKey", default: true)
static let autoQueryPastedText = Key<Bool>("EZConfiguration_kAutoQueryPastedTextKey", default: false)
static let autoCopyOCRText = Key<Bool>("EZConfiguration_kAutoCopyOCRTextKey", default: false)
static let autoCopySelectedText = Key<Bool>("EZConfiguration_kAutoCopySelectedTextKey", default: false)
static let autoCopyFirstTranslatedText = Key<Bool>("EZConfiguration_kAutoCopyFirstTranslatedTextKey", default: false)
// static let languageDetectOptimize = Key<EZLanguageDetectOptimize>("EZConfiguration_kLanguageDetectOptimizeTypeKey", default: EZLanguageDetectOptimize.none)
// static let defaultTTSServiceType = Key<Bool>("EZConfiguration_kDefaultTTSServiceTypeKey", default: )
static let showGoogleQuickLink = Key<Bool>("EZConfiguration_kShowGoogleLinkKey", default: true)
static let showEudicQuickLink = Key<Bool>("EZConfiguration_kShowEudicLinkKey", default: true)
static let showAppleDictionaryQuickLink = Key<Bool>("EZConfiguration_kShowAppleDictionaryLinkKey", default: true)
static let hideMenuBarIcon = Key<Bool>("EZConfiguration_kHideMenuBarIconKey", default: false)
// static let fixedWindowPosition = Key<Bool>("EZConfiguration_kShowFixedWindowPositionKey", default: )
// static let mouseSelectTranslateWindowType = Key<Bool>("EZConfiguration_kMouseSelectTranslateWindowTypeKey", default: )
// static let shortcutSelectTranslateWindowType = Key<Bool>("EZConfiguration_kShortcutSelectTranslateWindowTypeKey", default: )
static let adjustPopButtonOrigin = Key<Bool>("EZConfiguration_kAdjustPopButtomOriginKey", default: false)
static let allowCrashLog = Key<Bool>("EZConfiguration_kAllowCrashLogKey", default: true)
static let allowAnalytics = Key<Bool>("EZConfiguration_kAllowAnalyticsKey", default: true)
static let clearInput = Key<Bool>("EZConfiguration_kClearInputKey", default: true)
static let enableBetaNewApp = Key<Bool>("EZConfiguration_kEnableBetaNewAppKey", default: false)
}
129 changes: 104 additions & 25 deletions Easydict/NewApp/View/SettingView/Tabs/GeneralTab.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,48 +6,127 @@
// Copyright © 2023 izual. All rights reserved.
//

import Defaults
import SwiftUI

@available(macOS 13, *)
struct GeneralTab: View {
var body: some View {
Form {
Section {
HStack {
Text("show_main_window")
Toggle(isOn: $hideMainWindow) {
Text("hide_main_window")
}
}
HStack {
Text("launch")
Toggle(isOn: $launchAtStartup) {
Text("launch_at_startup")
}
Text("first_language")
Text("second_language")
Text("language_detect_optimize")
} header: {
Text("setting.general.language.header")
}

Section {
Toggle("auto_show_query_icon", isOn: $autoSelectText)
Toggle("force_auto_get_selected_text", isOn: $forceAutoGetSelectedText)
Toggle("click_icon_query_info", isOn: $clickQuery)
Toggle("setting.general.mouse_query.adjust_pop_button_origin", isOn: $adjustPopButtonOrigin) // 调整查询图标位置:
} header: {
Text("setting.general.mouse_query.header")
}

Section {
Toggle("setting.general.voice.disable_empty_copy_beep_msg", isOn: $disableEmptyCopyBeep) // 禁用提示音:划词内容为空时生效
Toggle("setting.general.voice.auto_play_word_audio", isOn: $autoPlayAudio) // 查询英语单词后自动播放发音
} header: {
Text("setting.general.voice.header")
}

Section {
Toggle(isOn: $hideMainWindow) {
Text("hide_main_window")
}
HStack {
Text("menu_bar_icon")
Toggle(isOn: $hideMenuBarIcon) {
Text("hide_menu_bar_icon")
}
Text("mouse_select_translate_window_type")
Text("shortcut_select_translate_window_type")
Text("fixed_window_position")
} header: {
Text("setting.general.windows.header")
}

Section {
Toggle("clear_input_when_translating", isOn: $clearInput)
} header: {
Text("setting.general.input.header")
}

Section {
Toggle("auto_query_ocr_text", isOn: $autoQueryOCRText)
Toggle("auto_query_selected_text", isOn: $autoQuerySelectedText)
Toggle("auto_query_pasted_text", isOn: $autoQueryPastedText)
} header: {
Text("setting.general.auto_query.header")
}

Section {
Toggle("auto_copy_ocr_text", isOn: $autoCopyOCRText)
Toggle("auto_copy_selected_text", isOn: $autoCopySelectedText)
Toggle("auto_copy_first_translated_text", isOn: $autoCopyFirstTranslatedText)
} header: {
Text("setting.general.auto_copy.header")
}

Section {
Toggle("show_google_quick_link", isOn: $showGoogleQuickLink)
Toggle("show_eudic_quick_link", isOn: $showEudicQuickLink)
Toggle("show_apple_dictionary_quick_link", isOn: $showAppleDictionaryQuickLink)
} header: {
Text("setting.general.quick_link.header")
}

Section {
Toggle(isOn: $launchAtStartup) {
Text("launch_at_startup")
}
HStack {
Text("beta_new_app")
Toggle(isOn: $enableBetaNewApp) {
Text("enable_beta_new_app")
}
Toggle(isOn: $hideMenuBarIcon) {
Text("hide_menu_bar_icon")
}
} header: {
Text("other")
}

Section {
Text("default_tts_service")
Toggle(isOn: $enableBetaNewApp) {
Text("enable_beta_new_app")
}
} header: {
Text("setting.general.advance.header")
}
}
.formStyle(.grouped)
}

@AppStorage(kHideMainWindowKey) private var hideMainWindow = false
@AppStorage(kLaunchAtStartupKey) private var launchAtStartup = false
@AppStorage(kHideMenuBarIconKey) private var hideMenuBarIcon = false
@AppStorage(kEnableBetaNewAppKey) private var enableBetaNewApp = false
@Default(.autoSelectText) private var autoSelectText
@Default(.forceAutoGetSelectedText) private var forceAutoGetSelectedText
@Default(.clickQuery) private var clickQuery
@Default(.adjustPopButtonOrigin) private var adjustPopButtonOrigin

@Default(.clearInput) private var clearInput

@Default(.disableEmptyCopyBeep) private var disableEmptyCopyBeep
@Default(.autoPlayAudio) private var autoPlayAudio

@Default(.autoQueryOCRText) private var autoQueryOCRText
@Default(.autoQuerySelectedText) private var autoQuerySelectedText
@Default(.autoQueryPastedText) private var autoQueryPastedText

@Default(.autoCopyOCRText) private var autoCopyOCRText
@Default(.autoCopySelectedText) private var autoCopySelectedText
@Default(.autoCopyFirstTranslatedText) private var autoCopyFirstTranslatedText

@Default(.showGoogleQuickLink) private var showGoogleQuickLink
@Default(.showEudicQuickLink) private var showEudicQuickLink
@Default(.showAppleDictionaryQuickLink) private var showAppleDictionaryQuickLink

@Default(.hideMainWindow) private var hideMainWindow
@Default(.launchAtStartup) private var launchAtStartup
@Default(.hideMenuBarIcon) private var hideMenuBarIcon
@Default(.enableBetaNewApp) private var enableBetaNewApp
}

@available(macOS 13, *)
Expand Down
Loading