Skip to content

Commit

Permalink
pref: optimize the use of MenuBarIconType
Browse files Browse the repository at this point in the history
  • Loading branch information
choykarl committed Jan 29, 2024
1 parent 107510d commit 527ca13
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 30 deletions.
4 changes: 2 additions & 2 deletions Easydict/App/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -1805,7 +1805,7 @@
}
}
},
"modify_menu_bar_icon" : {
"modify_menubar_icon" : {
"extractionState" : "manual",
"localizations" : {
"en" : {
Expand All @@ -1817,7 +1817,7 @@
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "修改菜单栏图标"
"value" : "菜单栏图标"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Easydict/NewApp/Configuration/Configuration+Defaults.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ extension Defaults.Keys {

static let appearanceType = Key<AppearenceType>("EZConfiguration_kApperanceKey", default: .followSystem)
static let fontSizeOptionIndex = Key<UInt>("EZConfiguration_kTranslationControllerFontKey", default: 0)
static let selectedMenuBarIcon = Key<UInt>("EZConfiguration_kSelectedMenuBarIconKey", default: 0)
static let selectedMenuBarIcon = Key<MenuBarIconType>("EZConfiguration_kSelectedMenuBarIconKey", default: .classical)
}

extension Defaults.Keys {
Expand Down
25 changes: 4 additions & 21 deletions Easydict/NewApp/EasydictApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,6 @@ struct EasydictApp: App {
@Default(.selectedMenuBarIcon)
private var menuBarIcon

private var menuBarImage: String {
#if DEBUG
MenuBarIconType.debug.imageName
#else
menuBarIcon == MenuBarIconType.classical.rawValue ? MenuBarIconType.classical.imageName : MenuBarIconType.debug.imageName
#endif
}

var body: some Scene {
if #available(macOS 13, *) {
MenuBarExtra(isInserted: $hideMenuBar.toggledValue) {
Expand All @@ -50,7 +42,7 @@ struct EasydictApp: App {
Label {
Text("Easydict")
} icon: {
Image(menuBarImage)
Image(menuBarIcon.rawValue)
.resizable()
.renderingMode(.template)
.scaledToFit()
Expand All @@ -71,18 +63,9 @@ extension Bool {
}
}

enum MenuBarIconType: UInt, CaseIterable, Identifiable {
enum MenuBarIconType: String, CaseIterable, Defaults.Serializable, Identifiable {
var id: Self { self }

case classical = 0
case debug = 1

var imageName: String {
switch self {
case .classical:
return "status_icon"
case .debug:
return "status_icon_debug"
}
}
case classical = "status_icon"
case debug = "status_icon_debug"
}
12 changes: 6 additions & 6 deletions Easydict/NewApp/View/SettingView/Tabs/GeneralTab.swift
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,12 @@ struct GeneralTab: View {
Text("hide_menu_bar_icon")
}
Picker(
"modify_menu_bar_icon",
selection: $selectedMenuBarIcon) {
ForEach(MenuBarIconType.allCases, id: \.rawValue) { option in
Image(option.imageName)
.tag(option)
}
"modify_menubar_icon",
selection: $selectedMenuBarIcon
) {
ForEach(MenuBarIconType.allCases) { option in
Image(option.rawValue)
}
}
} header: {
Text("setting.general.other.header")
Expand Down

0 comments on commit 527ca13

Please sign in to comment.