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

feature: pin emulator to the top of the list #91

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

dnafication
Copy link

This pull request introduces the ability to pin simulators/emulators to the top of the list. It includes changes to the UserDefaults extension to store pinned devices, modifications to the SubMenuItem structure to add a "TogglePinToTop" action, updates to the Device model to include a "pinned" Bool property, and adjustments to the DeviceService for toggling the pinned status.

  • Users can now pin/unpin simulators and emulators.
  • The pinned status is persistent across application sessions.

Note that the menu items are not being sorted currently. I just wanted to create the PR to get an initial feedback on if I am going in the right direction.

Some thoughts:

  • It would nice to be able to change SubMenuActionItem or the content of SubMenuActionItem based on the state of the Device. Example: Pin to top label and icon could change to Unpin to top based on the device state.
  • It would be nice if we could store the device list in a state and updating the state would automatically update the UI.

Please provide your feedback @okwasniewski @Garfeild

Closes #70

Copy link
Contributor

@Garfeild Garfeild left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, good start! I have couple of comments and one big question 😉

I know it was mentioned in the feature description. But do we really need Device to keep this flag? Are we going to use anywhere else, where this model is passed? Mainly question to @okwasniewski.

Maybe it's time to create another model specifically for Menu?

EDIT: Looks like it's inline with your last question @dnafication 😉

@@ -46,4 +48,15 @@ extension UserDefaults {
get { bool(forKey: Keys.enableAndroidEmulators) }
set { set(newValue, forKey: Keys.enableAndroidEmulators) }
}

public var pinnediOSSimulators: [String]? {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can store everything under one key. This will simplify logic in DeviceService.

@@ -216,18 +240,21 @@ extension DeviceService {
static private func parseIOSDevices(result: [String]) -> [Device] {
var devices: [Device] = []
var osVersion = ""
let pinnediOSSimulators: [String] = UserDefaults.standard.pinnediOSSimulators ?? []
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would say it's quite invasive to the parsing function. Maybe you can move it to getIOSDevices?

@okwasniewski
Copy link
Owner

Thanks for opening the PR!

Storing this inside of Device model would be beneficial for Raycast extension as it could also sort devices according to pinned ones first. So I think keeping it that way makes sense.

It would nice to be able to change SubMenuActionItem or the content of SubMenuActionItem based on the state of the Device. Example: Pin to top label and icon could change to Unpin to top based on the device state.

I'm not really sure how to achieve this with current refactor of menus. Maybe we could pass the current device to its menu item?

I've quickly launched the app - what I've noticed is that although pinned items are correctly persisted across app launches, they are not sorted. You need to take that into account in populateDevicesMenu method.

I was also thinking about the appearance - maybe we could leverage the mixedStateImage https://developer.apple.com/documentation/appkit/nsmenuitem/1514827-mixedstateimage?language=objc and display pin when device is not launched (because when its launched it has a checkmark).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

New feature: pin emulator to the top of the list
3 participants