mirror of
https://github.com/Ranchero-Software/NetNewsWire.git
synced 2025-01-28 01:39:47 +01:00
Fix deprecation warning. Make launchIfNeeded
async.
This commit is contained in:
parent
12637aa850
commit
d52e53d2e8
@ -63,19 +63,17 @@ public final class UserApp {
|
|||||||
path = bundleURL.path
|
path = bundleURL.path
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
path = NSWorkspace.shared.absolutePathForApplication(withBundleIdentifier: bundleID)
|
path = NSWorkspace.shared.urlForApplication(withBundleIdentifier: bundleID)?.path
|
||||||
}
|
}
|
||||||
if icon == nil, let path = path {
|
if icon == nil, let path {
|
||||||
icon = NSWorkspace.shared.icon(forFile: path)
|
icon = NSWorkspace.shared.icon(forFile: path)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
path = NSWorkspace.shared.absolutePathForApplication(withBundleIdentifier: bundleID)
|
path = NSWorkspace.shared.urlForApplication(withBundleIdentifier: bundleID)?.path
|
||||||
if let path = path {
|
if icon == nil, let path {
|
||||||
if icon == nil {
|
|
||||||
icon = NSWorkspace.shared.icon(forFile: path)
|
icon = NSWorkspace.shared.icon(forFile: path)
|
||||||
}
|
|
||||||
existsOnDisk = true
|
existsOnDisk = true
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -84,7 +82,7 @@ public final class UserApp {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public func launchIfNeeded() -> Bool {
|
public func launchIfNeeded() async -> Bool {
|
||||||
|
|
||||||
// Return true if already running.
|
// Return true if already running.
|
||||||
// Return true if not running and successfully gets launched.
|
// Return true if not running and successfully gets launched.
|
||||||
@ -99,21 +97,30 @@ public final class UserApp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let url = URL(fileURLWithPath: path)
|
let url = URL(fileURLWithPath: path)
|
||||||
if let app = try? NSWorkspace.shared.launchApplication(at: url, options: [.withErrorPresentation], configuration: [:]) {
|
|
||||||
|
do {
|
||||||
|
let configuration = NSWorkspace.OpenConfiguration()
|
||||||
|
configuration.promptsUserIfNeeded = true
|
||||||
|
|
||||||
|
let app = try await NSWorkspace.shared.openApplication(at: url, configuration: configuration)
|
||||||
runningApplication = app
|
runningApplication = app
|
||||||
|
|
||||||
if app.isFinishedLaunching {
|
if app.isFinishedLaunching {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
Thread.sleep(forTimeInterval: 1.0) // Give the app time to launch. This is ugly.
|
|
||||||
if app.isFinishedLaunching {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
Thread.sleep(forTimeInterval: 1.0) // Give it some *more* time.
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
|
try? await Task.sleep(for: .seconds(1)) // Give the app time to launch. This is ugly.
|
||||||
|
if app.isFinishedLaunching {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
try? await Task.sleep(for: .seconds(1)) // Give it some *more* time.
|
||||||
|
return true
|
||||||
|
|
||||||
|
} catch {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public func bringToFront() -> Bool {
|
public func bringToFront() -> Bool {
|
||||||
|
|
||||||
|
@ -44,6 +44,6 @@ public protocol SendToCommand {
|
|||||||
/// - Parameters:
|
/// - Parameters:
|
||||||
/// - object: The object whose data to send.
|
/// - object: The object whose data to send.
|
||||||
/// - selectedText: The currently selected text.
|
/// - selectedText: The currently selected text.
|
||||||
func sendObject(_ object: Any?, selectedText: String?)
|
@MainActor func sendObject(_ object: Any?, selectedText: String?)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,13 +30,19 @@ final class SendToMarsEditCommand: SendToCommand {
|
|||||||
guard let article = (object as? ArticlePasteboardWriter)?.article else {
|
guard let article = (object as? ArticlePasteboardWriter)?.article else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
guard let app = appToUse(), app.launchIfNeeded(), app.bringToFront() else {
|
guard let app = appToUse() else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
Task { @MainActor in
|
||||||
|
guard await app.launchIfNeeded(), app.bringToFront() else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
send(article, to: app)
|
send(article, to: app)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private extension SendToMarsEditCommand {
|
private extension SendToMarsEditCommand {
|
||||||
|
|
||||||
|
@ -38,7 +38,9 @@ final class SendToMicroBlogCommand: SendToCommand {
|
|||||||
guard let article = (object as? ArticlePasteboardWriter)?.article else {
|
guard let article = (object as? ArticlePasteboardWriter)?.article else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
guard microBlogApp.launchIfNeeded(), microBlogApp.bringToFront() else {
|
|
||||||
|
Task { @MainActor in
|
||||||
|
guard await microBlogApp.launchIfNeeded(), microBlogApp.bringToFront() else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,6 +60,7 @@ final class SendToMicroBlogCommand: SendToCommand {
|
|||||||
NSWorkspace.shared.open(url)
|
NSWorkspace.shared.open(url)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private extension Article {
|
private extension Article {
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user