Skip to content

Commit

Permalink
feat: add preference option to change MiniSim icon
Browse files Browse the repository at this point in the history
feat: implement menu icons with enum plus accomodations
  • Loading branch information
schrobingus authored and okwasniewski committed Sep 1, 2024
1 parent abe4b6e commit 86d76ba
Show file tree
Hide file tree
Showing 13 changed files with 269 additions and 173 deletions.
4 changes: 4 additions & 0 deletions MiniSim.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -165,6 +166,7 @@
76AC9AF52A0EA82C00864A8B /* CustomCommands.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomCommands.swift; sourceTree = "<group>"; };
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 = "<group>"; };
76C139692C849A3F006CD80C /* MenuIcons.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MenuIcons.swift; sourceTree = "<group>"; };
76E4451129D4391000039025 /* Onboarding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Onboarding.swift; sourceTree = "<group>"; };
76E4451329D4403F00039025 /* NSNotificationName.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NSNotificationName.swift; sourceTree = "<group>"; };
76F04A10298A5AE000BF9CA3 /* ADB.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ADB.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -225,6 +227,7 @@
762CF1E12981DDD400099999 /* Extensions */ = {
isa = PBXGroup;
children = (
76C139692C849A3F006CD80C /* MenuIcons.swift */,
762CF1DF2981968F00099999 /* String+match.swift */,
7645D5022983186100019227 /* NSMenuItem+ImageInit.swift */,
7630B26C2986B4FD00D8B57D /* KeyboardShortcuts.swift */,
Expand Down Expand Up @@ -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 */,
Expand Down
Binary file removed MiniSim/.DS_Store
Binary file not shown.
Binary file removed MiniSim/Assets.xcassets/.DS_Store
Binary file not shown.
21 changes: 21 additions & 0 deletions MiniSim/Assets.xcassets/box.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "[email protected]",
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions MiniSim/Assets.xcassets/ipad.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "[email protected]",
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"scale" : "1x"
},
{
"filename" : "menu_icon.png",
"filename" : "iphone@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
Expand Down
28 changes: 28 additions & 0 deletions MiniSim/Extensions/MenuIcons.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import AppKit
import Foundation

enum MenuImage: String, CaseIterable {
case iphone = "iphone"

Check warning on line 5 in MiniSim/Extensions/MenuIcons.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Redundant String Enum Value Violation: String enum values can be omitted when they are equal to the enumcase name (redundant_string_enum_value)

Check warning on line 5 in MiniSim/Extensions/MenuIcons.swift

View workflow job for this annotation

GitHub Actions / build

Redundant String Enum Value Violation: String enum values can be omitted when they are equal to the enumcase name (redundant_string_enum_value)
case ipad = "ipad"

Check warning on line 6 in MiniSim/Extensions/MenuIcons.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Redundant String Enum Value Violation: String enum values can be omitted when they are equal to the enumcase name (redundant_string_enum_value)
case box = "box"

Check warning on line 7 in MiniSim/Extensions/MenuIcons.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Redundant String Enum Value Violation: String enum values can be omitted when they are equal to the enumcase name (redundant_string_enum_value)

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)
}
}
}
6 changes: 6 additions & 0 deletions MiniSim/Extensions/UserDefaults+Configuration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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? {
Expand All @@ -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) }
Expand Down
Loading

0 comments on commit 86d76ba

Please sign in to comment.