updates plug with all sorts of awesome improvements

This commit is contained in:
2026-11-09 13:09:09 +01:00
parent a92d6f8871
commit 3afdb6d67f
553 changed files with 22780 additions and 13155 deletions
+29 -2
View File
@@ -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()
+2 -2
View File
@@ -1,7 +1,7 @@
import AppKit
import Carbon.HIToolbox
/// The system-wide ⌘P that shows or hides Plak from any app; no Accessibility permission needed.
/// The system-wide ⌘N that shows or hides Plak from any app; no Accessibility permission needed.
final class GlobalShortcut {
private let onPress: @MainActor () -> Void
private var hotKey: EventHotKeyRef?
@@ -18,7 +18,7 @@ final class GlobalShortcut {
return noErr
}, 1, &pressed, Unmanaged.passUnretained(self).toOpaque(), &handler)
let id = EventHotKeyID(signature: OSType(0x506C_616B), id: 1)
RegisterEventHotKey(UInt32(kVK_ANSI_P), UInt32(cmdKey), id, GetApplicationEventTarget(), 0, &hotKey)
RegisterEventHotKey(UInt32(kVK_ANSI_N), UInt32(cmdKey), id, GetApplicationEventTarget(), 0, &hotKey)
}
deinit {
+4
View File
@@ -63,6 +63,10 @@ enum MainMenu {
equals.allowsKeyEquivalentWhenHidden = true
menu.addItem(withTitle: "Smaller", action: #selector(PageViewController.makeTextSmaller(_:)), keyEquivalent: "-")
menu.addItem(withTitle: "Default Size", action: #selector(PageViewController.makeTextStandardSize(_:)), keyEquivalent: "0")
menu.addItem(.separator())
// The menu takes ⌘. before the key view turns it into cancelOperation, so it never ends an object edit.
menu.addItem(withTitle: "Wider Column", action: #selector(PageViewController.makeColumnWider(_:)), keyEquivalent: ".")
menu.addItem(withTitle: "Narrower Column", action: #selector(PageViewController.makeColumnNarrower(_:)), keyEquivalent: ",")
return menu
}
+11 -3
View File
@@ -1,23 +1,27 @@
import AppKit
/// The menu bar icon with Show, Hide and Quit.
/// The menu bar icon with Show, Hide, Help and Quit.
@MainActor
final class StatusMenu: NSObject {
private let item = NSStatusBar.system.statusItem(withLength: NSStatusItem.squareLength)
private let show: () -> Void
private let hide: () -> Void
private let help: () -> Void
init(show: @escaping () -> Void, hide: @escaping () -> Void) {
init(show: @escaping () -> Void, hide: @escaping () -> Void, help: @escaping () -> Void) {
self.show = show
self.hide = hide
self.help = help
super.init()
let image = NSImage(systemSymbolName: "note.text", accessibilityDescription: "Plak")
image?.isTemplate = true
item.button?.image = image
let menu = NSMenu()
menu.addItem(withTitle: "Show Plak", action: #selector(showPlak), keyEquivalent: "p").target = self
menu.addItem(withTitle: "Show Plak", action: #selector(showPlak), keyEquivalent: "n").target = self
menu.addItem(withTitle: "Hide Plak", action: #selector(hidePlak), keyEquivalent: "").target = self
menu.addItem(.separator())
menu.addItem(withTitle: "Plak Help", action: #selector(plakHelp), keyEquivalent: "").target = self
menu.addItem(.separator())
menu.addItem(withTitle: "Quit Plak", action: #selector(NSApplication.terminate(_:)), keyEquivalent: "q")
item.menu = menu
}
@@ -29,4 +33,8 @@ final class StatusMenu: NSObject {
@objc private func hidePlak() {
hide()
}
@objc private func plakHelp() {
help()
}
}