mirror of
https://github.com/swiftbar/SwiftBar.git
synced 2024-09-11 07:55:23 +03:00
Improve Shortcuts Plugins view
This commit is contained in:
parent
471082583e
commit
2e53a40529
@ -18,7 +18,7 @@ class PersistentShortcutPlugin: Codable, Identifiable {
|
||||
}
|
||||
}
|
||||
|
||||
class ShortcutPlugin: Plugin, Identifiable {
|
||||
class ShortcutPlugin: Plugin, Identifiable, ObservableObject {
|
||||
var id: PluginID
|
||||
var type: PluginType = .Shortcut
|
||||
var name: String
|
||||
@ -32,7 +32,7 @@ class ShortcutPlugin: Plugin, Identifiable {
|
||||
var shortcut: String
|
||||
var repeatString: String
|
||||
var cronString: String
|
||||
|
||||
@Published var enabled: Bool = true
|
||||
var operation: RunPluginOperation<ShortcutPlugin>?
|
||||
|
||||
var content: String? = "..." {
|
||||
@ -66,6 +66,7 @@ class ShortcutPlugin: Plugin, Identifiable {
|
||||
cronString = persistentItem.cronString
|
||||
lastState = .Loading
|
||||
updateInterval = parseRefreshInterval(intervalStr: repeatString, baseUpdateinterval: updateInterval) ?? updateInterval
|
||||
enabled = !prefs.disabledPlugins.contains(id)
|
||||
os_log("Initialized Shortcut plugin\n%{public}@", log: Log.plugin, description)
|
||||
refresh(reason: .FirstLaunch)
|
||||
}
|
||||
|
@ -20,16 +20,7 @@ struct ShortcutPluginsPreferencesView: View {
|
||||
HStack {
|
||||
Table(pluginManager.shortcutPlugins, selection: $selecting, sortOrder: $sorting) {
|
||||
TableColumn("") { plugin in
|
||||
VStack {
|
||||
Spacer()
|
||||
Button(action: {
|
||||
pluginManager.togglePlugin(plugin: plugin)
|
||||
}, label: {
|
||||
Circle()
|
||||
.foregroundColor(plugin.enabled ? .green : .red)
|
||||
}).help("Enable/Disable menu bar item")
|
||||
Spacer()
|
||||
}
|
||||
PluginStateView(plugin: plugin, pluginManager: pluginManager)
|
||||
}.width(15)
|
||||
TableColumn("Name", value: \.name) { plugin in
|
||||
Text(plugin.name).font(.title2)
|
||||
@ -42,13 +33,7 @@ struct ShortcutPluginsPreferencesView: View {
|
||||
}.width(60)
|
||||
|
||||
TableColumn("") { plugin in
|
||||
Button(action: {
|
||||
pluginManager.menuBarItems[plugin.id]?.dimOnManualRefresh()
|
||||
plugin.refresh(reason: .PluginSettings)
|
||||
}, label: {
|
||||
Image(systemName: "arrow.triangle.2.circlepath")
|
||||
}).buttonStyle(.link)
|
||||
.help("Refresh menu bar item")
|
||||
PluginStateRefreshView(plugin: plugin, pluginManager: pluginManager)
|
||||
}.width(40)
|
||||
}
|
||||
.onChange(of: sorting) { pluginManager.shortcutPlugins.sort(using: $0) }
|
||||
@ -81,6 +66,41 @@ struct ShortcutPluginsPreferencesView: View {
|
||||
}
|
||||
}
|
||||
|
||||
@available(macOS 12.0, *)
|
||||
struct PluginStateView: View {
|
||||
@ObservedObject var plugin: ShortcutPlugin
|
||||
var pluginManager: PluginManager
|
||||
var body: some View {
|
||||
VStack {
|
||||
Spacer()
|
||||
Button(action: {
|
||||
pluginManager.togglePlugin(plugin: plugin)
|
||||
plugin.enabled.toggle()
|
||||
}, label: {
|
||||
Circle()
|
||||
.foregroundColor($plugin.enabled.wrappedValue ? .green : .red)
|
||||
}).help("Enable/Disable menu bar item")
|
||||
Spacer()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@available(macOS 12.0, *)
|
||||
struct PluginStateRefreshView: View {
|
||||
@ObservedObject var plugin: ShortcutPlugin
|
||||
var pluginManager: PluginManager
|
||||
var body: some View {
|
||||
Button(action: {
|
||||
pluginManager.menuBarItems[plugin.id]?.dimOnManualRefresh()
|
||||
plugin.refresh(reason: .PluginSettings)
|
||||
}, label: {
|
||||
Image(systemName: "arrow.triangle.2.circlepath")
|
||||
}).buttonStyle(.link)
|
||||
.disabled(!$plugin.enabled.wrappedValue)
|
||||
.help("Refresh menu bar item")
|
||||
}
|
||||
}
|
||||
|
||||
@available(macOS 12.0, *)
|
||||
struct AddShortcutPluginView: View {
|
||||
@ObservedObject var pluginManager: PluginManager
|
||||
@ -100,9 +120,8 @@ struct AddShortcutPluginView: View {
|
||||
Group {
|
||||
VStack {
|
||||
HStack {
|
||||
Text("Name:")
|
||||
Text("Name: ")
|
||||
TextField("Unique Plugin Name...", text: $name)
|
||||
Spacer()
|
||||
}
|
||||
HStack {
|
||||
Picker("Folder:", selection: $prefs.shortcutsFolder, content: {
|
||||
|
Loading…
Reference in New Issue
Block a user