feat: add setting to blacklist window by title (closes #5299)
This commit is contained in:
1 parent
28c4b121ca
commit
35eae11389
5 files changed
+53
-5
No files matched your search
@@ -611,6 +611,9 @@
|
|||||||
/* No comment provided by engineer. */
|
/* No comment provided by engineer. */
|
||||||
"Window Title" = "Window Title";
|
"Window Title" = "Window Title";
|
||||||
|
|
||||||
|
/* No comment provided by engineer. */
|
||||||
|
"Window title contains" = "Window title contains";
|
||||||
|
|
||||||
/* No comment provided by engineer. */
|
/* No comment provided by engineer. */
|
||||||
"Windows" = "Windows";
|
"Windows" = "Windows";
|
||||||
|
|
||||||
|
|||||||
@@ -526,12 +526,14 @@ enum BlacklistHidePreference: String/* required for jsonEncode */, CaseIterable,
|
|||||||
case none = "0"
|
case none = "0"
|
||||||
case always = "1"
|
case always = "1"
|
||||||
case whenNoOpenWindow = "2"
|
case whenNoOpenWindow = "2"
|
||||||
|
case windowTitleContains = "3"
|
||||||
|
|
||||||
var localizedString: LocalizedString {
|
var localizedString: LocalizedString {
|
||||||
switch self {
|
switch self {
|
||||||
case .none: return ""
|
case .none: return ""
|
||||||
case .always: return NSLocalizedString("Always", comment: "")
|
case .always: return NSLocalizedString("Always", comment: "")
|
||||||
case .whenNoOpenWindow: return NSLocalizedString("When no open window", comment: "")
|
case .whenNoOpenWindow: return NSLocalizedString("When no open window", comment: "")
|
||||||
|
case .windowTitleContains: return NSLocalizedString("Window title contains", comment: "")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -329,4 +329,5 @@ struct BlacklistEntry: Codable {
|
|||||||
var bundleIdentifier: String
|
var bundleIdentifier: String
|
||||||
var hide: BlacklistHidePreference
|
var hide: BlacklistHidePreference
|
||||||
var ignore: BlacklistIgnorePreference
|
var ignore: BlacklistIgnorePreference
|
||||||
|
var windowTitleContains: String?
|
||||||
}
|
}
|
||||||
+17
-2
@@ -163,12 +163,27 @@ class Windows {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static func shouldHideWindow(_ window: Window, _ entry: BlacklistEntry) -> Bool {
|
||||||
|
switch entry.hide {
|
||||||
|
case .none:
|
||||||
|
return false
|
||||||
|
case .always:
|
||||||
|
return true
|
||||||
|
case .whenNoOpenWindow:
|
||||||
|
return window.isWindowlessApp
|
||||||
|
case .windowTitleContains:
|
||||||
|
guard let titleFilter = entry.windowTitleContains, !titleFilter.isEmpty else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return window.title.contains(titleFilter)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static func refreshIfWindowShouldBeShownToTheUser(_ window: Window) {
|
private static func refreshIfWindowShouldBeShownToTheUser(_ window: Window) {
|
||||||
window.shouldShowTheUser =
|
window.shouldShowTheUser =
|
||||||
!(window.application.bundleIdentifier.flatMap { id in
|
!(window.application.bundleIdentifier.flatMap { id in
|
||||||
Preferences.blacklist.contains {
|
Preferences.blacklist.contains {
|
||||||
id.hasPrefix($0.bundleIdentifier) &&
|
id.hasPrefix($0.bundleIdentifier) && shouldHideWindow(window, $0)
|
||||||
($0.hide == .always || (window.isWindowlessApp && $0.hide != .none))
|
|
||||||
}
|
}
|
||||||
} ?? false) &&
|
} ?? false) &&
|
||||||
!(Preferences.appsToShow[App.app.shortcutIndex] == .active && window.application.pid != Applications.frontmostPid) &&
|
!(Preferences.appsToShow[App.app.shortcutIndex] == .active && window.application.pid != Applications.frontmostPid) &&
|
||||||
|
|||||||
@@ -86,6 +86,7 @@ class TableView: NSTableView {
|
|||||||
addHeaders([
|
addHeaders([
|
||||||
NSLocalizedString("App (BundleID starting with)", comment: ""),
|
NSLocalizedString("App (BundleID starting with)", comment: ""),
|
||||||
String(format: NSLocalizedString("Hide in %@", comment: "%@ is AltTab"), App.name),
|
String(format: NSLocalizedString("Hide in %@", comment: "%@ is AltTab"), App.name),
|
||||||
|
NSLocalizedString("Window title contains", comment: ""),
|
||||||
NSLocalizedString("Ignore shortcuts when active", comment: "")
|
NSLocalizedString("Ignore shortcuts when active", comment: "")
|
||||||
])
|
])
|
||||||
reloadData()
|
reloadData()
|
||||||
@@ -93,7 +94,7 @@ class TableView: NSTableView {
|
|||||||
|
|
||||||
func insertRow(_ bundleId: String) {
|
func insertRow(_ bundleId: String) {
|
||||||
if !(items.contains { $0.bundleIdentifier == bundleId }) {
|
if !(items.contains { $0.bundleIdentifier == bundleId }) {
|
||||||
items.append(BlacklistEntry(bundleIdentifier: bundleId, hide: .always, ignore: .none))
|
items.append(BlacklistEntry(bundleIdentifier: bundleId, hide: .always, ignore: .none, windowTitleContains: nil))
|
||||||
insertRows(at: [numberOfRows])
|
insertRows(at: [numberOfRows])
|
||||||
savePreferences()
|
savePreferences()
|
||||||
}
|
}
|
||||||
@@ -115,7 +116,7 @@ class TableView: NSTableView {
|
|||||||
column.headerToolTip = header
|
column.headerToolTip = header
|
||||||
column.headerCell = TableHeaderCell(header)
|
column.headerCell = TableHeaderCell(header)
|
||||||
if i == 0 {
|
if i == 0 {
|
||||||
column.width = 206
|
column.width = 180
|
||||||
}
|
}
|
||||||
addTableColumn(column)
|
addTableColumn(column)
|
||||||
}
|
}
|
||||||
@@ -127,6 +128,8 @@ class TableView: NSTableView {
|
|||||||
items[row].bundleIdentifier = LabelAndControl.getControlValue(control, nil)!
|
items[row].bundleIdentifier = LabelAndControl.getControlValue(control, nil)!
|
||||||
} else if colId == "col2" {
|
} else if colId == "col2" {
|
||||||
items[row].hide = BlacklistHidePreference.allCases[Int(LabelAndControl.getControlValue(control, nil)!)!]
|
items[row].hide = BlacklistHidePreference.allCases[Int(LabelAndControl.getControlValue(control, nil)!)!]
|
||||||
|
} else if colId == "col3" {
|
||||||
|
items[row].windowTitleContains = LabelAndControl.getControlValue(control, nil)
|
||||||
} else {
|
} else {
|
||||||
items[row].ignore = BlacklistIgnorePreference.allCases[Int(LabelAndControl.getControlValue(control, nil)!)!]
|
items[row].ignore = BlacklistIgnorePreference.allCases[Int(LabelAndControl.getControlValue(control, nil)!)!]
|
||||||
}
|
}
|
||||||
@@ -154,6 +157,23 @@ class TableView: NSTableView {
|
|||||||
return parent
|
return parent
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func titleText(_ item: BlacklistEntry) -> NSView {
|
||||||
|
let text = TextField(item.windowTitleContains ?? "")
|
||||||
|
text.isEditable = true
|
||||||
|
text.allowsExpansionToolTips = true
|
||||||
|
text.drawsBackground = false
|
||||||
|
text.isBordered = false
|
||||||
|
text.lineBreakMode = .byTruncatingTail
|
||||||
|
text.usesSingleLineMode = true
|
||||||
|
text.cell!.sendsActionOnEndEditing = true
|
||||||
|
text.onAction = { self.wasUpdated("col3", $0) }
|
||||||
|
let parent = NSView()
|
||||||
|
parent.addSubview(text)
|
||||||
|
text.centerYAnchor.constraint(equalTo: parent.centerYAnchor).isActive = true
|
||||||
|
text.widthAnchor.constraint(equalTo: parent.widthAnchor).isActive = true
|
||||||
|
return parent
|
||||||
|
}
|
||||||
|
|
||||||
private func dropdown(_ item: BlacklistEntry, _ colId: String) -> NSView {
|
private func dropdown(_ item: BlacklistEntry, _ colId: String) -> NSView {
|
||||||
let isHidePref = colId == "col2"
|
let isHidePref = colId == "col2"
|
||||||
let button = NSPopUpButton()
|
let button = NSPopUpButton()
|
||||||
@@ -186,7 +206,14 @@ extension TableView: NSTableViewDataSource {
|
|||||||
extension TableView: NSTableViewDelegate {
|
extension TableView: NSTableViewDelegate {
|
||||||
func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? {
|
func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? {
|
||||||
let item = items[row]
|
let item = items[row]
|
||||||
return tableColumn!.identifier.rawValue == "col1" ? text(item) : dropdown(item, tableColumn!.identifier.rawValue)
|
let colId = tableColumn!.identifier.rawValue
|
||||||
|
if colId == "col1" {
|
||||||
|
return text(item)
|
||||||
|
} else if colId == "col3" {
|
||||||
|
return titleText(item)
|
||||||
|
} else {
|
||||||
|
return dropdown(item, colId)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user