mirror of
https://github.com/noctalia-dev/noctalia-shell.git
synced 2026-05-11 17:08:27 +08:00
fix(notification-rules): do not allow empty patterns
This commit is contained in:
@@ -1505,7 +1505,6 @@
|
||||
"rules-delete": "Delete rule",
|
||||
"rules-description": "Match app name or content. First match wins.",
|
||||
"rules-edit": "Edit rule",
|
||||
"rules-empty-pattern": "(empty)",
|
||||
"rules-label": "Filter rules",
|
||||
"rules-pattern-label": "Pattern",
|
||||
"rules-pattern-placeholder": "firefox, discord, or /regex/",
|
||||
|
||||
@@ -110,6 +110,7 @@ Popup {
|
||||
icon: "check"
|
||||
backgroundColor: Color.mPrimary
|
||||
textColor: Color.mOnPrimary
|
||||
enabled: patternInput.text.trim() !== ""
|
||||
onClicked: {
|
||||
root.saved(patternInput.text.trim(), _selectedAction || "block");
|
||||
root.close();
|
||||
|
||||
@@ -37,8 +37,11 @@ ColumnLayout {
|
||||
} catch (e) {}
|
||||
|
||||
editPopup._savedSlot = function (pattern, action) {
|
||||
const trimmed = (pattern || "").trim();
|
||||
if (trimmed === "")
|
||||
return;
|
||||
var arr = (NotificationRulesService.rules || []).slice();
|
||||
var rule = { "pattern": pattern, "action": action };
|
||||
var rule = { "pattern": trimmed, "action": action };
|
||||
if (index >= 0 && index < arr.length) {
|
||||
arr[index] = rule;
|
||||
} else {
|
||||
@@ -80,7 +83,7 @@ ColumnLayout {
|
||||
|
||||
NLabel {
|
||||
Layout.fillWidth: true
|
||||
label: (entryDelegate.isRegex ? "regex: " : "") + (entryDelegate.pattern || I18n.tr("panels.notifications.rules-empty-pattern"))
|
||||
label: (entryDelegate.isRegex ? "regex: " : "") + entryDelegate.pattern
|
||||
description: entryDelegate.action === "block" ? I18n.tr("panels.notifications.rules-action-block") : (entryDelegate.action === "mute" ? I18n.tr("panels.notifications.rules-action-mute") : I18n.tr("panels.notifications.rules-action-hide"))
|
||||
labelColor: entryDelegate.pattern ? Color.mPrimary : Color.mOnSurface
|
||||
}
|
||||
|
||||
@@ -26,7 +26,8 @@ Singleton {
|
||||
onLoaded: {
|
||||
try {
|
||||
const parsed = JSON.parse(rulesFileView.text());
|
||||
root.rules = Array.isArray(parsed.rules) ? parsed.rules : [];
|
||||
const raw = Array.isArray(parsed.rules) ? parsed.rules : [];
|
||||
root.rules = raw.filter(r => (r.pattern || "").trim() !== "");
|
||||
} catch (e) {
|
||||
root.rules = [];
|
||||
}
|
||||
@@ -42,6 +43,7 @@ Singleton {
|
||||
|
||||
function save() {
|
||||
Quickshell.execDetached(["mkdir", "-p", Settings.configDir]);
|
||||
root.rules = root.rules.filter(r => (r.pattern || "").trim() !== "");
|
||||
rulesAdapter.rules = root.rules;
|
||||
rulesFileView.writeAdapter();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user