-
-
Notifications
You must be signed in to change notification settings - Fork 38
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
Removing queues from UI #79
Changes from 5 commits
8a1e93a
4274266
344e953
f9298c7
d9f5179
098c169
6e00759
e551fdd
5a1a15e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,19 +34,16 @@ class Menu: NSMenu { | |
} | ||
|
||
func getDevices() { | ||
DispatchQueue.global(qos: .userInitiated).async { | ||
do { | ||
var devicesArray: [Device] = [] | ||
if UserDefaults.standard.enableiOSSimulators { | ||
try devicesArray.append(contentsOf: DeviceService.getIOSDevices()) | ||
} | ||
if UserDefaults.standard.enableAndroidEmulators && UserDefaults.standard.androidHome != nil { | ||
try devicesArray.append(contentsOf: DeviceService.getAndroidDevices()) | ||
} | ||
self.devices = devicesArray | ||
} catch { | ||
let userDefaults = UserDefaults.standard | ||
DeviceService.getAllDevices( | ||
android: userDefaults.enableAndroidEmulators && userDefaults.androidHome != nil, | ||
iOS: userDefaults.enableiOSSimulators | ||
) { devices, error in | ||
if let error = error { | ||
okwasniewski marked this conversation as resolved.
Show resolved
Hide resolved
|
||
NSAlert.showError(message: error.localizedDescription) | ||
return | ||
} | ||
self.devices = devices | ||
} | ||
} | ||
|
||
|
@@ -75,22 +72,14 @@ class Menu: NSMenu { | |
|
||
@objc private func deviceItemClick(_ sender: NSMenuItem) { | ||
guard let device = getDeviceByName(name: sender.title) else { return } | ||
guard let tag = DeviceMenuItem(rawValue: sender.tag) else { return } | ||
|
||
if device.booted { | ||
DeviceService.focusDevice(device) | ||
return | ||
} | ||
|
||
DispatchQueue.global(qos: .userInitiated).async { | ||
do { | ||
switch tag { | ||
case .launchAndroid: | ||
try DeviceService.launchDevice(name: device.name) | ||
case .launchIOS: | ||
try DeviceService.launchDevice(uuid: device.ID ?? "") | ||
} | ||
} catch { | ||
DeviceService.launch(device: device) { error in | ||
if let error = error { | ||
okwasniewski marked this conversation as resolved.
Show resolved
Hide resolved
|
||
NSAlert.showError(message: error.localizedDescription) | ||
} | ||
} | ||
|
@@ -116,9 +105,7 @@ class Menu: NSMenu { | |
private func assignKeyEquivalent(devices: [NSMenuItem]) { | ||
for (index, item) in devices.enumerated() { | ||
if index > maxKeyEquivalent { | ||
DispatchQueue.main.async { | ||
item.keyEquivalent = "" | ||
} | ||
item.keyEquivalent = "" | ||
okwasniewski marked this conversation as resolved.
Show resolved
Hide resolved
|
||
continue | ||
} | ||
|
||
|
@@ -128,10 +115,8 @@ class Menu: NSMenu { | |
continue | ||
} | ||
|
||
DispatchQueue.main.async { | ||
if self.items.contains(item) { | ||
item.keyEquivalent = keyEquivalent | ||
} | ||
if self.items.contains(item) { | ||
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. Here we are still missing the 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've added it back here. 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. We need to check if item exists inside of the |
||
item.keyEquivalent = keyEquivalent | ||
} | ||
} | ||
} | ||
|
@@ -142,11 +127,9 @@ class Menu: NSMenu { | |
for (index, device) in sortedDevices.enumerated() { | ||
let isAndroid = device.platform == .android | ||
if let itemIndex = items.firstIndex(where: { $0.title == device.displayName }) { | ||
DispatchQueue.main.async { [self] in | ||
let item = self.items.get(at: itemIndex) | ||
item?.state = device.booted ? .on : .off | ||
item?.submenu = isAndroid ? populateAndroidSubMenu(booted: device.booted) : populateIOSSubMenu(booted: device.booted) | ||
} | ||
let item = self.items.get(at: itemIndex) | ||
item?.state = device.booted ? .on : .off | ||
item?.submenu = isAndroid ? populateAndroidSubMenu(booted: device.booted) : populateIOSSubMenu(booted: device.booted) | ||
continue | ||
} | ||
|
||
|
@@ -162,11 +145,8 @@ class Menu: NSMenu { | |
menuItem.submenu = isAndroid ? populateAndroidSubMenu(booted: device.booted) : populateIOSSubMenu(booted: device.booted) | ||
menuItem.state = device.booted ? .on : .off | ||
|
||
DispatchQueue.main.async { | ||
let iosDevicesCount = self.devices.filter({ $0.platform == .ios }).count | ||
self.safeInsertItem(menuItem, at: isAndroid && UserDefaults.standard.enableiOSSimulators ? (isFirst ? index : iosDevicesCount) + 3 : 1) | ||
} | ||
|
||
let iosDevicesCount = self.devices.filter({ $0.platform == .ios }).count | ||
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. Also here we are missing the jump back to the main thread. You could add the |
||
self.safeInsertItem(menuItem, at: isAndroid && UserDefaults.standard.enableiOSSimulators ? (isFirst ? index : iosDevicesCount) + 3 : 1) | ||
} | ||
} | ||
|
||
|
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.
This code was the root cause of everything being not in the main queue. And that's the most important change in the PR. New
DeviceService.getAllDevices
executes callback closure on the main queue by default. This allows us to remove anyDispatchQueue.main
calls in theMenu
.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.
Okay, great thanks for the explanation!