Skip to content

Commit d8be7c7

Browse files
authored
Merge pull request #345 from swiftbar/firstclass_shortcuts
First class Shortcuts support
2 parents 14f508d + 93ef2f2 commit d8be7c7

23 files changed

+633
-91
lines changed

SwiftBar.xcodeproj/project.pbxproj

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@
105105
39E1549F2569A2D700287D8A /* ImageVIew.swift in Sources */ = {isa = PBXBuildFile; fileRef = 39E1549E2569A2D700287D8A /* ImageVIew.swift */; };
106106
ABF91B7D2589C7920020590A /* NSFont+Offset.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABF91B7C2589C7920020590A /* NSFont+Offset.swift */; };
107107
FA06104625F0564400B08B6E /* PluginEntryView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA06104525F0564400B08B6E /* PluginEntryView.swift */; };
108+
FA136A542917EE0700A7D712 /* PluginUtilities.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA136A532917EE0700A7D712 /* PluginUtilities.swift */; };
108109
FA57F2A4272A307900817A79 /* XbarAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 39B64C3E26152F5E00B7FA63 /* XbarAPI.swift */; };
109110
FA57F2A5272A308F00817A79 /* DisablePluginIntentHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAA14A142728C6FC0052FDB8 /* DisablePluginIntentHandler.swift */; };
110111
FA57F2A6272A308F00817A79 /* EnablePluginIntentHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAA14A102728C6E90052FDB8 /* EnablePluginIntentHandler.swift */; };
@@ -115,6 +116,8 @@
115116
FA64C9DF25CF691D00C4E5C5 /* GeneralPreferencesView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA64C9DE25CF691D00C4E5C5 /* GeneralPreferencesView.swift */; };
116117
FA64C9E225CF696D00C4E5C5 /* PluginsPreferencesView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA64C9E125CF696D00C4E5C5 /* PluginsPreferencesView.swift */; };
117118
FA69F5BC2791145E00D6DDC6 /* WebView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA69F5BB2791145E00D6DDC6 /* WebView.swift */; };
119+
FA6E13862915B70E00BA4594 /* ShortcutPlugin.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA6E13852915B70E00BA4594 /* ShortcutPlugin.swift */; };
120+
FA6E13882915B81400BA4594 /* ShortcutsManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA6E13872915B81400BA4594 /* ShortcutsManager.swift */; };
118121
FA8518CC258DAAAB008AD21C /* Binding+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA8518CB258DAAAB008AD21C /* Binding+Extension.swift */; };
119122
FA8518F52598E786008AD21C /* SwifCron in Frameworks */ = {isa = PBXBuildFile; productRef = FA8518F42598E786008AD21C /* SwifCron */; };
120123
FA90185927C318A700D72E63 /* Sparkle in Frameworks */ = {isa = PBXBuildFile; productRef = FA90185827C318A700D72E63 /* Sparkle */; };
@@ -124,7 +127,8 @@
124127
FAA14A152728C6FC0052FDB8 /* DisablePluginIntentHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAA14A142728C6FC0052FDB8 /* DisablePluginIntentHandler.swift */; };
125128
FAA14A172728C79B0052FDB8 /* GetPluginsIntentHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAA14A162728C79B0052FDB8 /* GetPluginsIntentHandler.swift */; };
126129
FAA14A192728C7FC0052FDB8 /* AppDelegate+Intents.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAA14A182728C7FC0052FDB8 /* AppDelegate+Intents.swift */; };
127-
FABE059728C4035200093A83 /* AppCenterCrashes in Frameworks */ = {isa = PBXBuildFile; productRef = FABE059628C4035200093A83 /* AppCenterCrashes */; };
130+
FAC3F2ED2915D88300D8F346 /* ShortcutPluginsPreferencesView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAC3F2EC2915D88300D8F346 /* ShortcutPluginsPreferencesView.swift */; };
131+
FAC3F2F12916A61800D8F346 /* AboutSettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAC3F2F02916A61800D8F346 /* AboutSettingsView.swift */; };
128132
FAD14C052585AE1800CB7BBE /* String+ANSIColor.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAD14C042585AE1800CB7BBE /* String+ANSIColor.swift */; };
129133
FAD1BC9B25D22E9400B761E8 /* PluginDetailsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAD1BC9A25D22E9400B761E8 /* PluginDetailsView.swift */; };
130134
FAD1BC9E25D22EEA00B761E8 /* AnimatableWindow.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAD1BC9D25D22EEA00B761E8 /* AnimatableWindow.swift */; };
@@ -197,20 +201,25 @@
197201
39E1549E2569A2D700287D8A /* ImageVIew.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageVIew.swift; sourceTree = "<group>"; };
198202
ABF91B7C2589C7920020590A /* NSFont+Offset.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSFont+Offset.swift"; sourceTree = "<group>"; };
199203
FA06104525F0564400B08B6E /* PluginEntryView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PluginEntryView.swift; sourceTree = "<group>"; };
204+
FA136A532917EE0700A7D712 /* PluginUtilities.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PluginUtilities.swift; sourceTree = "<group>"; };
200205
FA3C3793281EB2760003DEDE /* es */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = es; path = es.lproj/Localizable.strings; sourceTree = "<group>"; };
201206
FA3C3794281EB27B0003DEDE /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/Localizable.strings"; sourceTree = "<group>"; };
202207
FA58E39927AD855D0034837F /* SystemNotificationName.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SystemNotificationName.swift; sourceTree = "<group>"; };
203208
FA60506726B593FA001A939A /* ru */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ru; path = ru.lproj/Localizable.strings; sourceTree = "<group>"; };
204209
FA64C9DE25CF691D00C4E5C5 /* GeneralPreferencesView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GeneralPreferencesView.swift; sourceTree = "<group>"; };
205210
FA64C9E125CF696D00C4E5C5 /* PluginsPreferencesView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PluginsPreferencesView.swift; sourceTree = "<group>"; };
206211
FA69F5BB2791145E00D6DDC6 /* WebView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WebView.swift; sourceTree = "<group>"; };
212+
FA6E13852915B70E00BA4594 /* ShortcutPlugin.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShortcutPlugin.swift; sourceTree = "<group>"; };
213+
FA6E13872915B81400BA4594 /* ShortcutsManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShortcutsManager.swift; sourceTree = "<group>"; };
207214
FA8518CB258DAAAB008AD21C /* Binding+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Binding+Extension.swift"; sourceTree = "<group>"; };
208215
FAA14A0D2728C65D0052FDB8 /* Intents.intentdefinition */ = {isa = PBXFileReference; lastKnownFileType = file.intentdefinition; path = Intents.intentdefinition; sourceTree = "<group>"; };
209216
FAA14A102728C6E90052FDB8 /* EnablePluginIntentHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EnablePluginIntentHandler.swift; sourceTree = "<group>"; };
210217
FAA14A122728C6F20052FDB8 /* ReloadPluginIntentHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReloadPluginIntentHandler.swift; sourceTree = "<group>"; };
211218
FAA14A142728C6FC0052FDB8 /* DisablePluginIntentHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DisablePluginIntentHandler.swift; sourceTree = "<group>"; };
212219
FAA14A162728C79B0052FDB8 /* GetPluginsIntentHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GetPluginsIntentHandler.swift; sourceTree = "<group>"; };
213220
FAA14A182728C7FC0052FDB8 /* AppDelegate+Intents.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AppDelegate+Intents.swift"; sourceTree = "<group>"; };
221+
FAC3F2EC2915D88300D8F346 /* ShortcutPluginsPreferencesView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShortcutPluginsPreferencesView.swift; sourceTree = "<group>"; };
222+
FAC3F2F02916A61800D8F346 /* AboutSettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AboutSettingsView.swift; sourceTree = "<group>"; };
214223
FAD14C042585AE1800CB7BBE /* String+ANSIColor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "String+ANSIColor.swift"; sourceTree = "<group>"; };
215224
FAD1BC9A25D22E9400B761E8 /* PluginDetailsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PluginDetailsView.swift; sourceTree = "<group>"; };
216225
FAD1BC9D25D22EEA00B761E8 /* AnimatableWindow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnimatableWindow.swift; sourceTree = "<group>"; };
@@ -224,7 +233,6 @@
224233
buildActionMask = 2147483647;
225234
files = (
226235
FA90185927C318A700D72E63 /* Sparkle in Frameworks */,
227-
FABE059728C4035200093A83 /* AppCenterCrashes in Frameworks */,
228236
3989359625896DF9007CF2E8 /* LaunchAtLogin in Frameworks */,
229237
39B64C29260F70D900B7FA63 /* Preferences in Frameworks */,
230238
FA8518F52598E786008AD21C /* SwifCron in Frameworks */,
@@ -358,6 +366,7 @@
358366
39AF7771254612BF001D76E5 /* PluginMetadata.swift */,
359367
39AF7774254613C9001D76E5 /* PluginManger.swift */,
360368
3990DCE02602BB5B002CDCD5 /* PluginDebugInfo.swift */,
369+
FA6E13852915B70E00BA4594 /* ShortcutPlugin.swift */,
361370
);
362371
path = Plugin;
363372
sourceTree = "<group>";
@@ -395,6 +404,8 @@
395404
39224DD425F414F500BABF21 /* Notification+Extension.swift */,
396405
39224E5B25F530AF00BABF21 /* Environment.swift */,
397406
FA58E39927AD855D0034837F /* SystemNotificationName.swift */,
407+
FA6E13872915B81400BA4594 /* ShortcutsManager.swift */,
408+
FA136A532917EE0700A7D712 /* PluginUtilities.swift */,
398409
);
399410
path = Utility;
400411
sourceTree = "<group>";
@@ -406,6 +417,8 @@
406417
FA64C9DE25CF691D00C4E5C5 /* GeneralPreferencesView.swift */,
407418
FA64C9E125CF696D00C4E5C5 /* PluginsPreferencesView.swift */,
408419
FAD1BC9A25D22E9400B761E8 /* PluginDetailsView.swift */,
420+
FAC3F2EC2915D88300D8F346 /* ShortcutPluginsPreferencesView.swift */,
421+
FAC3F2F02916A61800D8F346 /* AboutSettingsView.swift */,
409422
);
410423
path = Preferences;
411424
sourceTree = "<group>";
@@ -463,7 +476,6 @@
463476
FA8518F42598E786008AD21C /* SwifCron */,
464477
39B64C28260F70D900B7FA63 /* Preferences */,
465478
FA90185827C318A700D72E63 /* Sparkle */,
466-
FABE059628C4035200093A83 /* AppCenterCrashes */,
467479
);
468480
productName = SwiftBar;
469481
productReference = 3920747A25460FD000213DBE /* SwiftBar.app */;
@@ -715,6 +727,8 @@
715727
3990DCDA2602BB32002CDCD5 /* DebugView.swift in Sources */,
716728
39E1549C25699C8F00287D8A /* URLTextView.swift in Sources */,
717729
FAD1BC9B25D22E9400B761E8 /* PluginDetailsView.swift in Sources */,
730+
FAC3F2ED2915D88300D8F346 /* ShortcutPluginsPreferencesView.swift in Sources */,
731+
FAC3F2F12916A61800D8F346 /* AboutSettingsView.swift in Sources */,
718732
39224DCF25F3E6DE00BABF21 /* AppDelegate+Menu.swift in Sources */,
719733
3920747E25460FD000213DBE /* AppDelegate.swift in Sources */,
720734
393375E725507ADE0050AC28 /* Log.swift in Sources */,
@@ -726,12 +740,14 @@
726740
398DAE7A25537DAF00747D90 /* PluginErrorView.swift in Sources */,
727741
396257262569667000341A19 /* PluginRepositoryView.swift in Sources */,
728742
39AF7778254613FB001D76E5 /* ExecutablePlugin.swift in Sources */,
743+
FA6E13862915B70E00BA4594 /* ShortcutPlugin.swift in Sources */,
729744
396E6CB0258E8D47002C735D /* Localizable.swift in Sources */,
730745
FA58E39A27AD855D0034837F /* SystemNotificationName.swift in Sources */,
731746
39AF77842547750E001D76E5 /* AppShared.swift in Sources */,
732747
FAA14A0E2728C65D0052FDB8 /* Intents.intentdefinition in Sources */,
733748
39641EA1254DD32100713DAF /* AboutPluginView.swift in Sources */,
734749
39AF7793254B5834001D76E5 /* NSColor.swift in Sources */,
750+
FA136A542917EE0700A7D712 /* PluginUtilities.swift in Sources */,
735751
398B86C4254DA85300DEA027 /* URL+Extension.swift in Sources */,
736752
FAA14A192728C7FC0052FDB8 /* AppDelegate+Intents.swift in Sources */,
737753
39AF778D2548EBA3001D76E5 /* MenuLineParameters.swift in Sources */,
@@ -741,6 +757,7 @@
741757
ABF91B7D2589C7920020590A /* NSFont+Offset.swift in Sources */,
742758
398B86CA254DB5D200DEA027 /* DirectoryObserver.swift in Sources */,
743759
39B84A22257D63F700FA012E /* NSMutableAttributedString+SFSymbols.swift in Sources */,
760+
FA6E13882915B81400BA4594 /* ShortcutsManager.swift in Sources */,
744761
39224E5C25F530AF00BABF21 /* Environment.swift in Sources */,
745762
FAA14A112728C6E90052FDB8 /* EnablePluginIntentHandler.swift in Sources */,
746763
39224DD225F3F19B00BABF21 /* AppDelegate+Toolbar.swift in Sources */,
@@ -963,7 +980,7 @@
963980
CODE_SIGN_IDENTITY = "Apple Development";
964981
CODE_SIGN_STYLE = Automatic;
965982
COMBINE_HIDPI_IMAGES = YES;
966-
CURRENT_PROJECT_VERSION = 445;
983+
CURRENT_PROJECT_VERSION = 461;
967984
DEVELOPMENT_ASSET_PATHS = "\"SwiftBar/Preview Content\"";
968985
DEVELOPMENT_TEAM = X93LWC49WV;
969986
ENABLE_HARDENED_RUNTIME = YES;
@@ -974,7 +991,7 @@
974991
"@executable_path/../Frameworks",
975992
);
976993
MACOSX_DEPLOYMENT_TARGET = 10.15;
977-
MARKETING_VERSION = 1.4.4;
994+
MARKETING_VERSION = 1.5.0;
978995
PRODUCT_BUNDLE_IDENTIFIER = com.ameba.SwiftBar;
979996
PRODUCT_NAME = "$(TARGET_NAME)";
980997
SWIFT_VERSION = 5.0;
@@ -990,7 +1007,7 @@
9901007
CODE_SIGN_IDENTITY = "Apple Development";
9911008
CODE_SIGN_STYLE = Automatic;
9921009
COMBINE_HIDPI_IMAGES = YES;
993-
CURRENT_PROJECT_VERSION = 445;
1010+
CURRENT_PROJECT_VERSION = 461;
9941011
DEVELOPMENT_ASSET_PATHS = "\"SwiftBar/Preview Content\"";
9951012
DEVELOPMENT_TEAM = X93LWC49WV;
9961013
ENABLE_HARDENED_RUNTIME = YES;
@@ -1001,7 +1018,7 @@
10011018
"@executable_path/../Frameworks",
10021019
);
10031020
MACOSX_DEPLOYMENT_TARGET = 10.15;
1004-
MARKETING_VERSION = 1.4.4;
1021+
MARKETING_VERSION = 1.5.0;
10051022
PRODUCT_BUNDLE_IDENTIFIER = com.ameba.SwiftBar;
10061023
PRODUCT_NAME = "$(TARGET_NAME)";
10071024
SWIFT_VERSION = 5.0;
@@ -1218,11 +1235,6 @@
12181235
package = FA90185727C318A700D72E63 /* XCRemoteSwiftPackageReference "Sparkle" */;
12191236
productName = Sparkle;
12201237
};
1221-
FABE059628C4035200093A83 /* AppCenterCrashes */ = {
1222-
isa = XCSwiftPackageProductDependency;
1223-
package = FABE059528C4035200093A83 /* XCRemoteSwiftPackageReference "appcenter-sdk-apple" */;
1224-
productName = AppCenterCrashes;
1225-
};
12261238
/* End XCSwiftPackageProductDependency section */
12271239
};
12281240
rootObject = 3920747225460FD000213DBE /* Project object */;

SwiftBar/AppDelegate.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import UserNotifications
88
#else
99
import Sparkle
1010
#endif
11-
import AppCenter
12-
import AppCenterCrashes
11+
// import AppCenter
12+
// import AppCenterCrashes
1313

1414
class AppDelegate: NSObject, NSApplicationDelegate, SPUStandardUserDriverDelegate, SPUUpdaterDelegate, UNUserNotificationCenterDelegate, NSWindowDelegate {
1515
var repositoryWindowController: NSWindowController? {
@@ -35,9 +35,9 @@ class AppDelegate: NSObject, NSApplicationDelegate, SPUStandardUserDriverDelegat
3535
func applicationDidFinishLaunching(_: Notification) {
3636
if prefs.collectCrashReports {
3737
// Not cool to have the KEY here, but since this is for crash reporting I don't care
38-
AppCenter.start(withAppSecret: "40e6c2fa-2383-40a7-bfbd-75662a7d92a9", services: [
39-
Crashes.self,
40-
])
38+
// AppCenter.start(withAppSecret: "40e6c2fa-2383-40a7-bfbd-75662a7d92a9", services: [
39+
// Crashes.self,
40+
// ])
4141
}
4242
preferencesWindowController.window?.delegate = self
4343
setupToolbar()
@@ -102,7 +102,6 @@ class AppDelegate: NSObject, NSApplicationDelegate, SPUStandardUserDriverDelegat
102102
}
103103

104104
func setDefaultShelf() {
105-
// let out = try? runScript(to: "dscl", args: [".", "-read", "~/", "UserShell", "|", "awk", "'{print $2}'"])
106105
let out = try? runScript(to: "echo", args: ["$SHELL"])
107106
if let shell = out?.out, shell != "" {
108107
sharedEnv.userLoginShell = shell.trimmingCharacters(in: .newlines)
@@ -144,6 +143,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, SPUStandardUserDriverDelegat
144143
pluginManager.refreshAllPlugins()
145144
case "refreshplugin":
146145
if let plugin = getPluginFromURL(url: url) {
146+
pluginManager.menuBarItems[plugin.id]?.dimOnManualRefresh()
147147
plugin.refresh()
148148
return
149149
}

SwiftBar/Plugin/ExecutablePlugin.swift

Lines changed: 5 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ class ExecutablePlugin: Plugin {
1313
var lastUpdated: Date?
1414
var lastState: PluginState
1515
var contentUpdatePublisher = PassthroughSubject<String?, Never>()
16-
var operation: ExecutablePluginOperation?
16+
var operation: RunPluginOperation<ExecutablePlugin>?
1717

1818
var content: String? = "..." {
1919
didSet {
2020
contentUpdatePublisher.send(content)
2121
}
2222
}
2323

24-
var error: ShellOutError?
24+
var error: Error?
2525
var debugInfo = PluginDebugInfo()
2626

2727
lazy var invokeQueue: OperationQueue = delegate.pluginManager.pluginInvokeQueue
@@ -47,36 +47,13 @@ class ExecutablePlugin: Plugin {
4747
refreshPluginMetadata()
4848

4949
if metadata?.nextDate == nil, nameComponents.count > 2 {
50-
updateInterval = nameComponents.dropFirst().compactMap { parseRefreshInterval(intervalStr: $0) }.reduce(updateInterval, min)
50+
updateInterval = nameComponents.dropFirst().compactMap { parseRefreshInterval(intervalStr: $0, baseUpdateinterval: updateInterval) }.reduce(updateInterval, min)
5151
}
5252
createSupportDirs()
5353
os_log("Initialized executable plugin\n%{public}@", log: Log.plugin, description)
5454
refresh()
5555
}
5656

57-
func parseRefreshInterval(intervalStr: String) -> Double? {
58-
guard let interval = Double(intervalStr.filter("0123456789.".contains)) else { return nil }
59-
var updateInterval: Double = self.updateInterval
60-
61-
if intervalStr.hasSuffix("s") {
62-
updateInterval = interval
63-
if intervalStr.hasSuffix("ms") {
64-
updateInterval = interval / 1000
65-
}
66-
}
67-
if intervalStr.hasSuffix("m") {
68-
updateInterval = interval * 60
69-
}
70-
if intervalStr.hasSuffix("h") {
71-
updateInterval = interval * 60 * 60
72-
}
73-
if intervalStr.hasSuffix("d") {
74-
updateInterval = interval * 60 * 60 * 24
75-
}
76-
77-
return updateInterval
78-
}
79-
8057
// this function called each time plugin updated(manual or scheduled)
8158
func enableTimer() {
8259
// handle cron scheduled plugins
@@ -93,7 +70,7 @@ class ExecutablePlugin: Plugin {
9370
.autoconnect()
9471
.receive(on: invokeQueue)
9572
.sink(receiveValue: { [weak self] _ in
96-
self?.invokeQueue.addOperation(ExecutablePluginOperation(plugin: self!))
73+
self?.invokeQueue.addOperation(RunPluginOperation<ExecutablePlugin>(plugin: self!))
9774
}).store(in: &cancellable)
9875
}
9976

@@ -132,7 +109,7 @@ class ExecutablePlugin: Plugin {
132109
operation?.cancel()
133110

134111
refreshPluginMetadata()
135-
operation = ExecutablePluginOperation(plugin: self)
112+
operation = RunPluginOperation<ExecutablePlugin>(plugin: self)
136113
invokeQueue.addOperation(operation!)
137114
}
138115

@@ -165,18 +142,3 @@ class ExecutablePlugin: Plugin {
165142
refresh()
166143
}
167144
}
168-
169-
final class ExecutablePluginOperation: Operation {
170-
weak var plugin: ExecutablePlugin?
171-
172-
init(plugin: ExecutablePlugin) {
173-
self.plugin = plugin
174-
super.init()
175-
}
176-
177-
override func main() {
178-
guard !isCancelled else { return }
179-
plugin?.content = plugin?.invoke()
180-
plugin?.enableTimer()
181-
}
182-
}

SwiftBar/Plugin/Plugin.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import os
55
enum PluginType: String {
66
case Executable
77
case Streamable
8+
case Shortcut
89
}
910

1011
enum PluginState {
@@ -29,7 +30,7 @@ protocol Plugin: AnyObject {
2930
var lastUpdated: Date? { get set }
3031
var lastState: PluginState { get set }
3132
var content: String? { get set }
32-
var error: ShellOutError? { get set }
33+
var error: Error? { get set }
3334
var debugInfo: PluginDebugInfo { get set }
3435
func refresh()
3536
func enable()

0 commit comments

Comments
 (0)