Skip to content

Commit 1da8800

Browse files
committed
fix: use enum and it's accomodations for menu icons
1 parent b904ddb commit 1da8800

File tree

13 files changed

+35
-24
lines changed

13 files changed

+35
-24
lines changed

MiniSim.xcodeproj/project.pbxproj

+6-2
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
76F2A9172991B7B6002D4EF6 /* ViewModifiers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76F2A9162991B7B6002D4EF6 /* ViewModifiers.swift */; };
7777
76F2A91929924242002D4EF6 /* AndroidSubMenuItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76F2A91829924242002D4EF6 /* AndroidSubMenuItem.swift */; };
7878
76FCABAB29B390D5003BBF9A /* Collection+get.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76FCABAA29B390D5003BBF9A /* Collection+get.swift */; };
79+
84B1A6B42AE4532B00803FA7 /* MenuIcons.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84B1A6B32AE4532B00803FA7 /* MenuIcons.swift */; };
7980
/* End PBXBuildFile section */
8081

8182
/* Begin PBXFileReference section */
@@ -144,6 +145,7 @@
144145
76F2A9162991B7B6002D4EF6 /* ViewModifiers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewModifiers.swift; sourceTree = "<group>"; };
145146
76F2A91829924242002D4EF6 /* AndroidSubMenuItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AndroidSubMenuItem.swift; sourceTree = "<group>"; };
146147
76FCABAA29B390D5003BBF9A /* Collection+get.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Collection+get.swift"; sourceTree = "<group>"; };
148+
84B1A6B32AE4532B00803FA7 /* MenuIcons.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MenuIcons.swift; sourceTree = "<group>"; };
147149
/* End PBXFileReference section */
148150

149151
/* Begin PBXFrameworksBuildPhase section */
@@ -178,6 +180,7 @@
178180
76FCABAA29B390D5003BBF9A /* Collection+get.swift */,
179181
76E4451329D4403F00039025 /* NSNotificationName.swift */,
180182
767F713129D574EF004159A6 /* UNUserNotificationCenter+showNotification.swift */,
183+
84B1A6B32AE4532B00803FA7 /* MenuIcons.swift */,
181184
);
182185
path = Extensions;
183186
sourceTree = "<group>";
@@ -493,6 +496,7 @@
493496
763121902A12B45000EE7F48 /* CustomCommandFormViewModel.swift in Sources */,
494497
7630B2772986D65800D8B57D /* Bundle+appName.swift in Sources */,
495498
763121892A12AF9C00EE7F48 /* Command.swift in Sources */,
499+
84B1A6B42AE4532B00803FA7 /* MenuIcons.swift in Sources */,
496500
767DDF6829D32ABC005E6F32 /* ReadyPopOver.swift in Sources */,
497501
764BA3E92A5AD418003A78AF /* GetDevicesCommand.swift in Sources */,
498502
76059BF92AD558C30008D38B /* SetupItemView.swift in Sources */,
@@ -646,7 +650,7 @@
646650
CURRENT_PROJECT_VERSION = 12;
647651
DEAD_CODE_STRIPPING = YES;
648652
DEVELOPMENT_ASSET_PATHS = "\"MiniSim/Preview Content\"";
649-
DEVELOPMENT_TEAM = Z3M9P6G4WY;
653+
DEVELOPMENT_TEAM = S5FW7JRR79;
650654
ENABLE_HARDENED_RUNTIME = YES;
651655
ENABLE_PREVIEWS = YES;
652656
GENERATE_INFOPLIST_FILE = YES;
@@ -682,7 +686,7 @@
682686
CURRENT_PROJECT_VERSION = 12;
683687
DEAD_CODE_STRIPPING = YES;
684688
DEVELOPMENT_ASSET_PATHS = "\"MiniSim/Preview Content\"";
685-
DEVELOPMENT_TEAM = Z3M9P6G4WY;
689+
DEVELOPMENT_TEAM = S5FW7JRR79;
686690
ENABLE_HARDENED_RUNTIME = YES;
687691
ENABLE_PREVIEWS = YES;
688692
GENERATE_INFOPLIST_FILE = YES;

MiniSim/.DS_Store

-6 KB
Binary file not shown.

MiniSim/Assets.xcassets/.DS_Store

-10 KB
Binary file not shown.

MiniSim/Extensions/MenuIcons.swift

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import Foundation
2+
3+
enum MenuImage: String, CaseIterable {
4+
case iphone = "iphone"
5+
case ipad = "ipad"
6+
case box = "box"
7+
}

MiniSim/Extensions/UserDefaults+Configuration.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ extension UserDefaults {
1515
static let isOnboardingFinished = "isOnboardingFinished"
1616
static let enableiOSSimulators = "enableiOSSimulators"
1717
static let enableAndroidEmulators = "enableAndroidEmulators"
18-
static let menuImage = "menu_icon_1"
18+
static let menuImage = "menuImage"
1919
}
2020

2121
@objc dynamic public var androidHome: String? {
@@ -29,7 +29,7 @@ extension UserDefaults {
2929
}
3030

3131
@objc dynamic public var menuImage: String {
32-
get { string(forKey: Keys.menuImage) ?? "menu_icon_1" }
32+
get { string(forKey: Keys.menuImage) ?? "iphone" }
3333
set { set(newValue, forKey: Keys.menuImage) }
3434
}
3535

MiniSim/MiniSim.swift

+11-9
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ class MiniSim: NSObject {
1919
private var isOnboardingFinishedObserver: NSKeyValueObservation?
2020
private var menuImageObserver: NSKeyValueObservation?
2121

22-
private var menuImagesObserved: [String] = []
23-
2422
private lazy var onboarding = Onboarding()
2523

2624
override init() {
@@ -87,6 +85,7 @@ class MiniSim: NSObject {
8785
}
8886
menu = Menu()
8987
statusItem.menu = menu
88+
configureMenuImages()
9089
setMenuImage()
9190
populateSections()
9291

@@ -113,18 +112,21 @@ class MiniSim: NSObject {
113112
UserDefaults.Keys.enableiOSSimulators: true
114113
])
115114
}
115+
116+
private func configureMenuImages() {
117+
MenuImage.allCases.forEach { image in
118+
let itemImage = NSImage(imageLiteralResourceName: image.rawValue)
119+
itemImage.size = NSSize(
120+
width: (itemImage.size.width) * 0.78,
121+
height: (itemImage.size.height) * 0.78)
122+
itemImage.isTemplate = true
123+
}
124+
}
116125

117126
private func setMenuImage() {
118127
if let button = statusItem.button {
119128
button.toolTip = "MiniSim"
120129
let itemImage = NSImage(named: UserDefaults.standard.menuImage)
121-
if (!menuImagesObserved.contains(UserDefaults.standard.menuImage)) {
122-
itemImage?.size = NSSize(
123-
width: (itemImage?.size.width ?? 16) * 0.78,
124-
height: (itemImage?.size.height ?? 16) * 0.78)
125-
menuImagesObserved.append(UserDefaults.standard.menuImage)
126-
}
127-
itemImage?.isTemplate = true
128130
button.image = itemImage
129131
}
130132
}

MiniSim/Views/Preferences.swift

+9-11
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,20 @@ import KeyboardShortcuts
1111
import LaunchAtLogin
1212

1313
struct Preferences: View {
14-
var menuImages = [ "menu_icon_1", "menu_icon_2", "menu_icon_3" ]
15-
@State var menuImageSelected = 0
14+
@State var menuImageSelected: String = "iphone"
1615

1716
var body: some View {
1817
Settings.Container(contentWidth: 400) {
1918
Settings.Section(title: "Icon:") {
2019
Picker("", selection: $menuImageSelected) {
21-
ForEach(0 ..< menuImages.count, id: \.self) { image in
22-
Image(menuImages[image])
23-
.renderingMode(.template)
24-
.tag(image)
20+
ForEach(MenuImage.allCases, id: \.self) { image in
21+
Image(nsImage: NSImage(imageLiteralResourceName: image.rawValue))
22+
.tag(image.rawValue)
2523
}
2624
}
27-
.pickerStyle(.radioGroup)
25+
.fixedSize(horizontal: true, vertical: false)
2826
.onChange(of: menuImageSelected) { _ in
29-
UserDefaults.standard.menuImage = menuImages[menuImageSelected]
27+
UserDefaults.standard.menuImage = menuImageSelected
3028
}
3129
Text("The icon displayed in the Menu Bar.")
3230
.descriptionText()
@@ -50,9 +48,9 @@ struct Preferences: View {
5048
}
5149
.frame(minWidth: 650, minHeight: 450)
5250
.onAppear {
53-
for image in 0 ..< menuImages.count {
54-
if (UserDefaults.standard.menuImage == menuImages[image]) {
55-
menuImageSelected = image
51+
MenuImage.allCases.forEach { image in
52+
if (UserDefaults.standard.menuImage == image.rawValue) {
53+
menuImageSelected = image.rawValue
5654
}
5755
}
5856
}

0 commit comments

Comments
 (0)