updates plug with all sorts of awesome improvements
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import AppKit
|
||||
import PlakCore
|
||||
import PlakServices
|
||||
import PlakUI
|
||||
|
||||
@@ -29,7 +30,8 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
shortcut = GlobalShortcut { [weak self] in self?.togglePlak() }
|
||||
statusMenu = StatusMenu(
|
||||
show: { [weak self] in self?.showPlak() },
|
||||
hide: { [weak self] in self?.hidePlak() }
|
||||
hide: { [weak self] in self?.hidePlak() },
|
||||
help: { [weak self] in self?.append(HelpText.text) }
|
||||
)
|
||||
}
|
||||
|
||||
@@ -38,6 +40,31 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
return true
|
||||
}
|
||||
|
||||
/// Runs the `plak://` commands of other apps; on a cold launch they come after applicationDidFinishLaunching.
|
||||
func application(_ application: NSApplication, open urls: [URL]) {
|
||||
for url in urls {
|
||||
switch URLCommand(url) {
|
||||
case let .append(text):
|
||||
append(text)
|
||||
case .paste:
|
||||
open(atEnd: true)
|
||||
windowController?.page.append(from: .general)
|
||||
case nil:
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Opens plak at the end and appends the text as ⌘V would paste it; an empty text only opens plak.
|
||||
private func append(_ text: String) {
|
||||
open(atEnd: true)
|
||||
guard !text.isEmpty, let page = windowController?.page else { return }
|
||||
let pasteboard = NSPasteboard(name: .init("nl.blijnder.plak.append"))
|
||||
pasteboard.clearContents()
|
||||
pasteboard.setString(text, forType: .string)
|
||||
page.append(from: pasteboard)
|
||||
}
|
||||
|
||||
func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
|
||||
false
|
||||
}
|
||||
@@ -72,7 +99,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
|
||||
private func open(atEnd: Bool) {
|
||||
if NSApp.isHidden { NSApp.unhideWithoutActivation() }
|
||||
// NSApp.activate() is cooperative since macOS 14 and loses to the app in front on ⌘P.
|
||||
// NSApp.activate() is cooperative since macOS 14 and loses to the app in front on ⌘N.
|
||||
(NSApp as ForcedActivation).activate(ignoringOtherApps: true)
|
||||
if atEnd {
|
||||
windowController?.showAtEnd()
|
||||
|
||||
Reference in New Issue
Block a user