mirror of
https://github.com/swiftbar/SwiftBar.git
synced 2024-09-11 07:55:23 +03:00
Rework web popover persistence #359
Signed-off-by: Alex Mazanov <alexandr.mazanov@gmail.com>
This commit is contained in:
parent
9c1e1267ed
commit
e32a11b34d
@ -375,9 +375,10 @@ extension MenubarItem {
|
||||
startPopupMonitor()
|
||||
}
|
||||
|
||||
guard webPopover.contentViewController == nil || refreshOnOpen else {
|
||||
guard webPopover.contentViewController == nil || plugin?.metadata?.persistentWebView == false else {
|
||||
return
|
||||
}
|
||||
|
||||
let urlRequest = URLRequest(url: url)
|
||||
webPopover.behavior = .transient
|
||||
webPopover.contentViewController = NSHostingController(rootView: WebPanelView(request: urlRequest, name: plugin?.name ?? ""))
|
||||
@ -386,9 +387,16 @@ extension MenubarItem {
|
||||
|
||||
func hideWebPopover(_ sender: AnyObject?) {
|
||||
webPopover.performClose(sender)
|
||||
if plugin?.metadata?.persistentWebView == false {
|
||||
resetWebPopoverContent()
|
||||
}
|
||||
stopPopupMonitor()
|
||||
}
|
||||
|
||||
func resetWebPopoverContent() {
|
||||
webPopover.contentViewController = nil
|
||||
}
|
||||
|
||||
func popoverHideHandler(_ event: NSEvent?) {
|
||||
if aboutPopover.isShown {
|
||||
hideAboutPopover(event)
|
||||
@ -443,6 +451,7 @@ extension MenubarItem {
|
||||
func _updateMenu(content: String?) {
|
||||
barItem.button?.appearsDisabled = false
|
||||
statusBarMenu.removeAllItems()
|
||||
resetWebPopoverContent()
|
||||
show()
|
||||
|
||||
if plugin?.lastState == .Failed {
|
||||
|
@ -28,13 +28,14 @@ enum PluginMetadataOption: String, CaseIterable {
|
||||
case environment
|
||||
case runInBash
|
||||
case refreshOnOpen
|
||||
case persistentWebView
|
||||
case useTrailingStreamSeparator
|
||||
|
||||
var optionType: [PluginMetadataType] {
|
||||
switch self {
|
||||
case .title, .version, .author, .github, .desc, .about, .image, .dependencies:
|
||||
return [.bitbar, .xbar]
|
||||
case .runInBash, .environment, .droptypes, .schedule, .type, .hideAbout, .hideRunInTerminal, .hideLastUpdated, .hideDisablePlugin, .hideSwiftBar, .refreshOnOpen, .useTrailingStreamSeparator:
|
||||
case .runInBash, .environment, .droptypes, .schedule, .type, .hideAbout, .hideRunInTerminal, .hideLastUpdated, .hideDisablePlugin, .hideSwiftBar, .refreshOnOpen, .persistentWebView, .useTrailingStreamSeparator:
|
||||
return [.swiftbar]
|
||||
}
|
||||
}
|
||||
@ -60,6 +61,7 @@ class PluginMetadata: ObservableObject {
|
||||
@Published var environment: [String: String]
|
||||
@Published var runInBash: Bool
|
||||
@Published var refreshOnOpen: Bool
|
||||
@Published var persistentWebView: Bool
|
||||
@Published var useTrailingStreamSeparator: Bool
|
||||
|
||||
var isEmpty: Bool {
|
||||
@ -79,7 +81,7 @@ class PluginMetadata: ObservableObject {
|
||||
return date == Date.distantFuture ? nil : date
|
||||
}
|
||||
|
||||
init(name: String = "", version: String = "", author: String = "", github: String = "", desc: String = "", previewImageURL: URL? = nil, dependencies: [String] = [], aboutURL: URL? = nil, dropTypes: [String] = [], schedule: String = "", type: PluginType = .Executable, hideAbout: Bool = false, hideRunInTerminal: Bool = false, hideLastUpdated: Bool = false, hideDisablePlugin: Bool = false, hideSwiftBar: Bool = false, environment: [String: String] = [:], runInBash: Bool = true, refreshOnOpen: Bool = false, useTrailingStreamSeparator: Bool = false) {
|
||||
init(name: String = "", version: String = "", author: String = "", github: String = "", desc: String = "", previewImageURL: URL? = nil, dependencies: [String] = [], aboutURL: URL? = nil, dropTypes: [String] = [], schedule: String = "", type: PluginType = .Executable, hideAbout: Bool = false, hideRunInTerminal: Bool = false, hideLastUpdated: Bool = false, hideDisablePlugin: Bool = false, hideSwiftBar: Bool = false, environment: [String: String] = [:], runInBash: Bool = true, refreshOnOpen: Bool = false, persistentWebView: Bool = false, useTrailingStreamSeparator: Bool = false) {
|
||||
self.name = name
|
||||
self.version = version
|
||||
self.author = author
|
||||
@ -99,6 +101,7 @@ class PluginMetadata: ObservableObject {
|
||||
self.environment = environment
|
||||
self.runInBash = runInBash
|
||||
self.refreshOnOpen = refreshOnOpen
|
||||
self.persistentWebView = persistentWebView
|
||||
self.useTrailingStreamSeparator = useTrailingStreamSeparator
|
||||
}
|
||||
|
||||
@ -158,6 +161,7 @@ class PluginMetadata: ObservableObject {
|
||||
environment: environment,
|
||||
runInBash: getTagValue(tag: .runInBash) == "false" ? false : true,
|
||||
refreshOnOpen: getTagValue(tag: .refreshOnOpen) == "true" ? true : false,
|
||||
persistentWebView: getTagValue(tag: .persistentWebView) == "true" ? true : false,
|
||||
useTrailingStreamSeparator: getTagValue(tag: .useTrailingStreamSeparator) == "true" ? true : false)
|
||||
}
|
||||
|
||||
@ -230,6 +234,8 @@ class PluginMetadata: ObservableObject {
|
||||
value = runInBash ? "" : "false"
|
||||
case .refreshOnOpen:
|
||||
value = refreshOnOpen ? "true" : ""
|
||||
case .persistentWebView:
|
||||
value = persistentWebView ? "true" : ""
|
||||
case .useTrailingStreamSeparator:
|
||||
value = useTrailingStreamSeparator ? "true" : ""
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user