-
-
Notifications
You must be signed in to change notification settings - Fork 31
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
dnafication
wants to merge
5
commits into
okwasniewski:main
Choose a base branch
from
dnafication:feature/pin-emulator-to-the-top-of-the-list
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8e87b4a
add pinnediOSSimulators and pinnedAndroidEmulators in UserDefaults
dnafication fce64dc
add pinned field to Device
dnafication 18f5848
add submenu item to toggle pinned state
dnafication dd8917c
Update DeviceService.swift
dnafication 62c1944
Merge remote-tracking branch 'upstream/main' into feature/pin-emulato…
dnafication File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -208,6 +208,30 @@ class DeviceService: DeviceServiceProtocol { | |
} | ||
} | ||
} | ||
|
||
static func togglePinned(device: Device) { | ||
var pinnedDevices: [String]? | ||
switch device.platform { | ||
case .android: | ||
pinnedDevices = UserDefaults.standard.pinnedAndroidEmulators | ||
var dedupedPinnedDevices = Set(pinnedDevices ?? []) | ||
if dedupedPinnedDevices.contains(device.name) { | ||
dedupedPinnedDevices.remove(device.name) | ||
} else { | ||
dedupedPinnedDevices.insert(device.name) | ||
} | ||
UserDefaults.standard.pinnedAndroidEmulators = Array(dedupedPinnedDevices) | ||
case .ios: | ||
pinnedDevices = UserDefaults.standard.pinnediOSSimulators | ||
var dedupedPinnedDevices = Set(pinnedDevices ?? []) | ||
if dedupedPinnedDevices.contains(device.name) { | ||
dedupedPinnedDevices.remove(device.name) | ||
} else { | ||
dedupedPinnedDevices.insert(device.name) | ||
} | ||
UserDefaults.standard.pinnediOSSimulators = Array(dedupedPinnedDevices) | ||
} | ||
} | ||
} | ||
|
||
// MARK: iOS Methods | ||
|
@@ -216,18 +240,21 @@ extension DeviceService { | |
static private func parseIOSDevices(result: [String]) -> [Device] { | ||
var devices: [Device] = [] | ||
var osVersion = "" | ||
let pinnediOSSimulators: [String] = UserDefaults.standard.pinnediOSSimulators ?? [] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
result.forEach { line in | ||
if let currentOs = line.match("-- (.*?) --").first, currentOs.count > 0 { | ||
osVersion = currentOs[1] | ||
} | ||
if let device = line.match("(.*?) (\\(([0-9.]+)\\) )?\\(([0-9A-F-]+)\\) (\\(.*?)\\)").first { | ||
let deviceName = device[1].trimmingCharacters(in: .whitespacesAndNewlines) | ||
devices.append( | ||
Device( | ||
name: device[1].trimmingCharacters(in: .whitespacesAndNewlines), | ||
name: deviceName, | ||
version: osVersion, | ||
ID: device[4], | ||
booted: device[5].contains("Booted"), | ||
platform: .ios | ||
platform: .ios, | ||
pinned: pinnediOSSimulators.contains(deviceName) | ||
) | ||
) | ||
} | ||
|
@@ -295,6 +322,9 @@ extension DeviceService { | |
NSPasteboard.general.copyToPasteboard(text: deviceID) | ||
DeviceService.showSuccessMessage(title: "Device ID copied to clipboard!", message: deviceID) | ||
} | ||
case .togglePinned: | ||
DeviceService.togglePinned(device: device) | ||
|
||
case .delete: | ||
guard let deviceID = device.ID else { return } | ||
if !NSAlert.showQuestionDialog(title: "Are you sure?", message: "Are you sure you want to delete this Simulator?") { | ||
|
@@ -366,10 +396,11 @@ extension DeviceService { | |
let adbPath = try ADB.getAdbPath() | ||
let output = try shellOut(to: emulatorPath, arguments: ["-list-avds"]) | ||
let splitted = output.components(separatedBy: "\n") | ||
let pinnedAndroidEmulators: [String] = UserDefaults.standard.pinnedAndroidEmulators ?? [] | ||
|
||
return splitted.filter({ !$0.isEmpty }).map { | ||
let adbId = try? ADB.getAdbId(for: $0, adbPath: adbPath) | ||
return Device(name: $0, ID: adbId, booted: adbId != nil, platform: .android) | ||
return Device(name: $0, ID: adbId, booted: adbId != nil, platform: .android, pinned: pinnedAndroidEmulators.contains($0)) | ||
} | ||
} | ||
|
||
|
@@ -420,6 +451,9 @@ extension DeviceService { | |
NSPasteboard.general.copyToPasteboard(text: device.name) | ||
DeviceService.showSuccessMessage(title: "Device name copied to clipboard!", message: device.name) | ||
|
||
case .togglePinned: | ||
DeviceService.togglePinned(device: device) | ||
|
||
case .paste: | ||
guard let clipboard = NSPasteboard.general.pasteboardItems?.first?.string(forType: .string) else { break } | ||
try DeviceService.sendText(device: device, text: clipboard) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
.