diff --git a/MiniSim.xcodeproj/project.pbxproj b/MiniSim.xcodeproj/project.pbxproj index ea7a113..89d643a 100644 --- a/MiniSim.xcodeproj/project.pbxproj +++ b/MiniSim.xcodeproj/project.pbxproj @@ -75,6 +75,7 @@ 76AC9AF62A0EA82C00864A8B /* CustomCommands.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76AC9AF52A0EA82C00864A8B /* CustomCommands.swift */; }; 76AC9AF92A0EB50800864A8B /* SymbolPicker in Frameworks */ = {isa = PBXBuildFile; productRef = 76AC9AF82A0EB50800864A8B /* SymbolPicker */; }; 76B70F7E2B0D361A009D87A4 /* UserDefaultsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76B70F7D2B0D361A009D87A4 /* UserDefaultsTests.swift */; }; + 76C1396A2C849A3F006CD80C /* MenuIcons.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76C139692C849A3F006CD80C /* MenuIcons.swift */; }; 76E4451229D4391000039025 /* Onboarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76E4451129D4391000039025 /* Onboarding.swift */; }; 76E4451429D4403F00039025 /* NSNotificationName.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76E4451329D4403F00039025 /* NSNotificationName.swift */; }; 76F04A11298A5AE000BF9CA3 /* ADB.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76F04A10298A5AE000BF9CA3 /* ADB.swift */; }; @@ -165,6 +166,7 @@ 76AC9AF52A0EA82C00864A8B /* CustomCommands.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomCommands.swift; sourceTree = ""; }; 76B70F742B0D359D009D87A4 /* MiniSimTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = MiniSimTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 76B70F7D2B0D361A009D87A4 /* UserDefaultsTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserDefaultsTests.swift; sourceTree = ""; }; + 76C139692C849A3F006CD80C /* MenuIcons.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MenuIcons.swift; sourceTree = ""; }; 76E4451129D4391000039025 /* Onboarding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Onboarding.swift; sourceTree = ""; }; 76E4451329D4403F00039025 /* NSNotificationName.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NSNotificationName.swift; sourceTree = ""; }; 76F04A10298A5AE000BF9CA3 /* ADB.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ADB.swift; sourceTree = ""; }; @@ -225,6 +227,7 @@ 762CF1E12981DDD400099999 /* Extensions */ = { isa = PBXGroup; children = ( + 76C139692C849A3F006CD80C /* MenuIcons.swift */, 762CF1DF2981968F00099999 /* String+match.swift */, 7645D5022983186100019227 /* NSMenuItem+ImageInit.swift */, 7630B26C2986B4FD00D8B57D /* KeyboardShortcuts.swift */, @@ -629,6 +632,7 @@ 7630B26D2986B4FD00D8B57D /* KeyboardShortcuts.swift in Sources */, 76059BF52AD4361C0008D38B /* SetupPreferences.swift in Sources */, 7684FAAF29D202F500230BB0 /* AndroidHomeError.swift in Sources */, + 76C1396A2C849A3F006CD80C /* MenuIcons.swift in Sources */, 55CDB0782B1B6D24002418D7 /* TerminalApps.swift in Sources */, 7645D4BE2982A1B100019227 /* DeviceService.swift in Sources */, 765ABF382A8BECD900A063CB /* ExecuteCommand.swift in Sources */, diff --git a/MiniSim/.DS_Store b/MiniSim/.DS_Store deleted file mode 100644 index ac0456c..0000000 Binary files a/MiniSim/.DS_Store and /dev/null differ diff --git a/MiniSim/Assets.xcassets/.DS_Store b/MiniSim/Assets.xcassets/.DS_Store deleted file mode 100644 index ebde57b..0000000 Binary files a/MiniSim/Assets.xcassets/.DS_Store and /dev/null differ diff --git a/MiniSim/Assets.xcassets/box.imageset/Contents.json b/MiniSim/Assets.xcassets/box.imageset/Contents.json new file mode 100644 index 0000000..d0d8cc5 --- /dev/null +++ b/MiniSim/Assets.xcassets/box.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "idiom" : "universal", + "scale" : "1x" + }, + { + "filename" : "archivebox@2x.png", + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/MiniSim/Assets.xcassets/box.imageset/archivebox@2x.png b/MiniSim/Assets.xcassets/box.imageset/archivebox@2x.png new file mode 100644 index 0000000..90151e9 Binary files /dev/null and b/MiniSim/Assets.xcassets/box.imageset/archivebox@2x.png differ diff --git a/MiniSim/Assets.xcassets/ipad.imageset/Contents.json b/MiniSim/Assets.xcassets/ipad.imageset/Contents.json new file mode 100644 index 0000000..85e006c --- /dev/null +++ b/MiniSim/Assets.xcassets/ipad.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "idiom" : "universal", + "scale" : "1x" + }, + { + "filename" : "ipad.landscape@2x.png", + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/MiniSim/Assets.xcassets/ipad.imageset/ipad.landscape@2x.png b/MiniSim/Assets.xcassets/ipad.imageset/ipad.landscape@2x.png new file mode 100644 index 0000000..f1ebaf5 Binary files /dev/null and b/MiniSim/Assets.xcassets/ipad.imageset/ipad.landscape@2x.png differ diff --git a/MiniSim/Assets.xcassets/menu_icon.imageset/Contents.json b/MiniSim/Assets.xcassets/iphone.imageset/Contents.json similarity index 88% rename from MiniSim/Assets.xcassets/menu_icon.imageset/Contents.json rename to MiniSim/Assets.xcassets/iphone.imageset/Contents.json index 1ad9e47..1e89037 100644 --- a/MiniSim/Assets.xcassets/menu_icon.imageset/Contents.json +++ b/MiniSim/Assets.xcassets/iphone.imageset/Contents.json @@ -5,7 +5,7 @@ "scale" : "1x" }, { - "filename" : "menu_icon.png", + "filename" : "iphone@2x.png", "idiom" : "universal", "scale" : "2x" }, diff --git a/MiniSim/Assets.xcassets/menu_icon.imageset/menu_icon.png b/MiniSim/Assets.xcassets/iphone.imageset/iphone@2x.png similarity index 100% rename from MiniSim/Assets.xcassets/menu_icon.imageset/menu_icon.png rename to MiniSim/Assets.xcassets/iphone.imageset/iphone@2x.png diff --git a/MiniSim/Extensions/MenuIcons.swift b/MiniSim/Extensions/MenuIcons.swift new file mode 100644 index 0000000..72bb992 --- /dev/null +++ b/MiniSim/Extensions/MenuIcons.swift @@ -0,0 +1,28 @@ +import AppKit +import Foundation + +enum MenuImage: String, CaseIterable { + case iphone + case ipad + case box + + var image: NSImage? { + guard let itemImage = NSImage(named: self.rawValue) else { + return nil + } + itemImage.size = size + itemImage.isTemplate = true + return itemImage + } + + var size: NSSize { + switch self { + case .box: + return NSSize(width: 16.5, height: 15) + case .ipad: + return NSSize(width: 19, height: 14) + case .iphone: + return NSSize(width: 11, height: 19) + } + } +} diff --git a/MiniSim/Extensions/UserDefaults+Configuration.swift b/MiniSim/Extensions/UserDefaults+Configuration.swift index cdc0086..4685bd3 100644 --- a/MiniSim/Extensions/UserDefaults+Configuration.swift +++ b/MiniSim/Extensions/UserDefaults+Configuration.swift @@ -16,6 +16,7 @@ extension UserDefaults { static let enableiOSSimulators = "enableiOSSimulators" static let enableAndroidEmulators = "enableAndroidEmulators" static let preferedTerminal = "preferedTerminal" + static let menuImage = "menuImage" } @objc public dynamic var androidHome: String? { @@ -28,6 +29,11 @@ extension UserDefaults { set { set(newValue, forKey: Keys.isOnboardingFinished) } } + @objc public dynamic var menuImage: String { + get { string(forKey: Keys.menuImage) ?? "iphone" } + set { set(newValue, forKey: Keys.menuImage) } + } + public var parameters: Data? { get { object(forKey: Keys.parameters) as? Data } set { set(newValue, forKey: Keys.parameters) } diff --git a/MiniSim/MiniSim.swift b/MiniSim/MiniSim.swift index 152f145..9e8fbe2 100644 --- a/MiniSim/MiniSim.swift +++ b/MiniSim/MiniSim.swift @@ -16,6 +16,7 @@ class MiniSim: NSObject { @objc let statusItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.variableLength) private var isOnboardingFinishedObserver: NSKeyValueObservation? + private var menuImageObserver: NSKeyValueObservation? private lazy var onboarding = Onboarding() @@ -32,6 +33,7 @@ class MiniSim: NSObject { deinit { isOnboardingFinishedObserver?.invalidate() + menuImageObserver?.invalidate() NotificationCenter.default.removeObserver(self, name: .commandDidSucceed, object: nil) NotificationCenter.default.removeObserver(self, name: .deviceDeleted, object: nil) } @@ -98,6 +100,10 @@ class MiniSim: NSObject { self.onboarding.showPopOver(button: self.statusItem.button) } } + menuImageObserver = UserDefaults.standard.observe(\.menuImage, options: .new) { _, _ in + self.setMenuImage() + } + let notificationCenter = NotificationCenter.default notificationCenter.addObserver( self, @@ -123,11 +129,10 @@ class MiniSim: NSObject { private func setMenuImage() { if let button = statusItem.button { - button.toolTip = "MiniSim" - let itemImage = NSImage(named: "menu_icon") - itemImage?.size = NSSize(width: 9, height: 16) - itemImage?.isTemplate = true - button.image = itemImage + button.toolTip = "MiniSim" + let itemImage = MenuImage(rawValue: UserDefaults.standard.menuImage)?.image + itemImage?.isTemplate = true + button.image = itemImage } } diff --git a/MiniSim/Views/Preferences.swift b/MiniSim/Views/Preferences.swift index 00ed966..2dfe37a 100644 --- a/MiniSim/Views/Preferences.swift +++ b/MiniSim/Views/Preferences.swift @@ -10,7 +10,9 @@ import LaunchAtLogin import Settings import ShellOut import SwiftUI + struct Preferences: View { + @State var menuImageSelected: String = "iphone" @State private var preferedTerminal: Terminal init() { @@ -24,6 +26,20 @@ struct Preferences: View { var body: some View { Settings.Container(contentWidth: 400) { + Settings.Section(title: "Icon:") { + Picker("", selection: $menuImageSelected) { + ForEach(MenuImage.allCases, id: \.self) { image in + Image(nsImage: NSImage(imageLiteralResourceName: image.rawValue)) + .tag(image.rawValue) + } + } + .fixedSize(horizontal: true, vertical: false) + .onChange(of: menuImageSelected) { _ in + UserDefaults.standard.menuImage = menuImageSelected + } + Text("The icon displayed in the Menu Bar.") + .descriptionText() + } Settings.Section(title: "Preferred Terminal:") { Picker("", selection: $preferedTerminal) { let availableTerminal = Terminal.allCases.filter { checkAppIsInstalled(appName: $0) } @@ -57,6 +73,13 @@ struct Preferences: View { } } .frame(minWidth: 650, minHeight: 450) + .onAppear { + MenuImage.allCases.forEach { image in + if UserDefaults.standard.menuImage == image.rawValue { + menuImageSelected = image.rawValue + } + } + } } func checkAppIsInstalled(appName: Terminal) -> Bool {