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

Modify menu bar icon #370

Merged
merged 19 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from 12 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
23 changes: 20 additions & 3 deletions Easydict/App/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -1405,7 +1405,7 @@
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Hide Menu Bar Icon"
"value" : "Hide menubar icon"
tisfeng marked this conversation as resolved.
Show resolved Hide resolved
}
},
"zh-Hans" : {
Expand Down Expand Up @@ -1696,7 +1696,7 @@
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Menu bar icon:"
"value" : "Menubar icon:"
}
},
"zh-Hans" : {
Expand Down Expand Up @@ -1805,6 +1805,23 @@
}
}
},
"modify_menubar_icon" : {
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Menubar icon"
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "菜单栏图标"
}
}
}
},
"mouse_select_translate_window_type" : {
"localizations" : {
"en" : {
Expand Down Expand Up @@ -3467,4 +3484,4 @@
}
},
"version" : "1.0"
}
}
1 change: 1 addition & 0 deletions Easydict/NewApp/Configuration/Configuration+Defaults.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +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<MenuBarIconType>("EZConfiguration_kSelectedMenuBarIconKey", default: .classical)
}

extension Defaults.Keys {
Expand Down
18 changes: 10 additions & 8 deletions Easydict/NewApp/EasydictApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,8 @@ struct EasydictApp: App {
@AppStorage(Defaults.Key<Bool>.hideMenuBarIcon.name)
private var hideMenuBar = Defaults.Key<Bool>.hideMenuBarIcon.defaultValue

private var menuBarImage: String {
#if DEBUG
"status_icon_debug"
#else
"status_icon"
#endif
}
@Default(.selectedMenuBarIcon)
private var menuBarIcon

var body: some Scene {
if #available(macOS 13, *) {
Expand All @@ -47,7 +42,7 @@ struct EasydictApp: App {
Label {
Text("Easydict")
} icon: {
Image(menuBarImage)
Image(menuBarIcon.rawValue)
.resizable()
.renderingMode(.template)
.scaledToFit()
tisfeng marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -67,3 +62,10 @@ extension Bool {
mutating set { self = newValue.toggledValue }
}
}

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

case classical = "status_icon"
case debug = "status_icon_debug"
}
13 changes: 13 additions & 0 deletions Easydict/NewApp/View/SettingView/Tabs/GeneralTab.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import SwiftUI

@available(macOS 13, *)
struct GeneralTab: View {
@Environment(\.colorScheme) var colorScheme

var body: some View {
Form {
Section {
Expand Down Expand Up @@ -136,6 +138,16 @@ struct GeneralTab: View {
Toggle(isOn: $hideMenuBarIcon) {
Text("hide_menu_bar_icon")
}
Picker(
"modify_menubar_icon",
selection: $selectedMenuBarIcon
) {
ForEach(MenuBarIconType.allCases) { option in
Image(option.rawValue)
.renderingMode(.template)
.foregroundStyle(.primary)
}
}
} header: {
Text("setting.general.other.header")
}
Expand Down Expand Up @@ -180,6 +192,7 @@ struct GeneralTab: View {
@Default(.appearanceType) private var appearanceType

@Default(.fontSizeOptionIndex) private var fontSizeOptionIndex
@Default(.selectedMenuBarIcon) private var selectedMenuBarIcon
}

@available(macOS 13, *)
Expand Down