mirror of
https://github.com/swiftbar/SwiftBar.git
synced 2024-08-17 12:00:27 +03:00
Adding URL Scheme for plagin enable/disable #239
This commit is contained in:
parent
68bcd11caa
commit
20b91dfaa8
@ -263,6 +263,9 @@ You can mark a plugin as streamable with a special metadata property `<swiftbar.
|
||||
| refreshallplugins | none | Force refresh all loaded plugins | `swiftbar://refreshallplugins` |
|
||||
| refreshplugin | `name` plugin [name](#plugin-naming) | Force refresh plugin by name | `swiftbar://refreshplugin?name=myplugin` |
|
||||
| refreshplugin | `index` plugin index in menubar, starting from `0` | Force refresh plugin by its position in menubar | `swiftbar://refreshplugin?index=1` |
|
||||
| enableplugin | `name` plugin [name](#plugin-naming) | Enable plugin by name | `swiftbar://enableplugin?name=myplugin` |
|
||||
| disableplugin | `name` plugin [name](#plugin-naming) | Disable plugin by name | `swiftbar://disableplugin?name=myplugin` |
|
||||
| toggleplugin | `name` plugin [name](#plugin-naming) | Toggle(enable\disable) plugin by name | `swiftbar://toggleplugin?name=myplugin` |
|
||||
| addplugin | `src` source URL to plugin file | Add plugin to Swiftbar from URL | `swiftbar://addplugin?src=https://coolplugin` |
|
||||
| notify | `plugin` plugin [name](#plugin-naming). Notification fields: `title`, `subtitle`, `body`. `href` to open an URL on click (including custom URL schemes). `silent=true` to disable sound | Show notification | `swiftbar://notify?plugin=MyPlugin&title=title&subtitle=subtitle&body=body&silent=true` |
|
||||
|
||||
|
@ -130,6 +130,7 @@
|
||||
FAD1BC9B25D22E9400B761E8 /* PluginDetailsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAD1BC9A25D22E9400B761E8 /* PluginDetailsView.swift */; };
|
||||
FAD1BC9E25D22EEA00B761E8 /* AnimatableWindow.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAD1BC9D25D22EEA00B761E8 /* AnimatableWindow.swift */; };
|
||||
FAD571A325A0071700623B57 /* StreamablePlugin.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAD571A225A0071700623B57 /* StreamablePlugin.swift */; };
|
||||
FAFF1285273837EA00B3993B /* README.md in Resources */ = {isa = PBXBuildFile; fileRef = FAFF1284273837EA00B3993B /* README.md */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXCopyFilesBuildPhase section */
|
||||
@ -221,6 +222,7 @@
|
||||
FAD1BC9A25D22E9400B761E8 /* PluginDetailsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PluginDetailsView.swift; sourceTree = "<group>"; };
|
||||
FAD1BC9D25D22EEA00B761E8 /* AnimatableWindow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnimatableWindow.swift; sourceTree = "<group>"; };
|
||||
FAD571A225A0071700623B57 /* StreamablePlugin.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StreamablePlugin.swift; sourceTree = "<group>"; };
|
||||
FAFF1284273837EA00B3993B /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
/* Begin PBXFrameworksBuildPhase section */
|
||||
@ -253,6 +255,7 @@
|
||||
3920747125460FD000213DBE = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
FAFF1284273837EA00B3993B /* README.md */,
|
||||
FA3864EA2589AAF2000C6C97 /* BuildTools */,
|
||||
3920747C25460FD000213DBE /* SwiftBar */,
|
||||
3920747B25460FD000213DBE /* Products */,
|
||||
@ -560,6 +563,7 @@
|
||||
files = (
|
||||
3920748525460FD300213DBE /* Preview Assets.xcassets in Resources */,
|
||||
396E6CA9258E8C5C002C735D /* Localizable.strings in Resources */,
|
||||
FAFF1285273837EA00B3993B /* README.md in Resources */,
|
||||
393375EC25508B320050AC28 /* Credits.rtf in Resources */,
|
||||
3920748225460FD300213DBE /* Assets.xcassets in Resources */,
|
||||
);
|
||||
|
@ -117,6 +117,18 @@ class AppDelegate: NSObject, NSApplicationDelegate, SPUStandardUserDriverDelegat
|
||||
pluginManager.refreshPlugin(with: index)
|
||||
return
|
||||
}
|
||||
case "disableplugin":
|
||||
if let name = url.queryParameters?["name"] {
|
||||
pluginManager.disablePlugin(named: name)
|
||||
}
|
||||
case "enableplugin":
|
||||
if let name = url.queryParameters?["name"] {
|
||||
pluginManager.enablePlugin(named: name)
|
||||
}
|
||||
case "toggleplugin":
|
||||
if let name = url.queryParameters?["name"] {
|
||||
pluginManager.togglePlugin(named: name)
|
||||
}
|
||||
case "addplugin":
|
||||
if let src = url.queryParameters?["src"], let url = URL(string: src) {
|
||||
pluginManager.importPlugin(from: url)
|
||||
|
@ -79,11 +79,26 @@ class PluginManager: ObservableObject {
|
||||
os_log("Disabling plugin \n%{public}@", log: Log.plugin, plugin.description)
|
||||
plugin.disable()
|
||||
}
|
||||
|
||||
func disablePlugin(named name: String) {
|
||||
guard let plugin = plugins.first(where: { $0.name.lowercased() == name.lowercased() }) else { return }
|
||||
disablePlugin(plugin: plugin)
|
||||
}
|
||||
|
||||
func enablePlugin(plugin: Plugin) {
|
||||
os_log("Enabling plugin \n%{public}@", log: Log.plugin, plugin.description)
|
||||
plugin.enable()
|
||||
}
|
||||
|
||||
func enablePlugin(named name: String) {
|
||||
guard let plugin = plugins.first(where: { $0.name.lowercased() == name.lowercased() }) else { return }
|
||||
enablePlugin(plugin: plugin)
|
||||
}
|
||||
|
||||
func togglePlugin(named name: String) {
|
||||
guard let plugin = plugins.first(where: { $0.name.lowercased() == name.lowercased() }) else { return }
|
||||
plugin.enabled ? disablePlugin(plugin: plugin):enablePlugin(plugin: plugin)
|
||||
}
|
||||
|
||||
func disableAllPlugins() {
|
||||
os_log("Disabling all plugins.", log: Log.plugin)
|
||||
@ -197,6 +212,7 @@ class PluginManager: ObservableObject {
|
||||
guard plugins.indices.contains(index) else { return }
|
||||
plugins[index].refresh()
|
||||
}
|
||||
|
||||
|
||||
enum ImportPluginError: Error {
|
||||
case badURL
|
||||
|
Loading…
Reference in New Issue
Block a user