mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-04-04 04:42:05 -04:00
Right-Click to set Rules on Notifications directly
This commit is contained in:
@@ -2140,6 +2140,9 @@ Singleton {
|
||||
saveSettings();
|
||||
}
|
||||
|
||||
property bool _pendingExpandNotificationRules: false
|
||||
property int _pendingNotificationRuleIndex: -1
|
||||
|
||||
function addNotificationRule() {
|
||||
var rules = JSON.parse(JSON.stringify(notificationRules || []));
|
||||
rules.push({
|
||||
@@ -2154,6 +2157,27 @@ Singleton {
|
||||
saveSettings();
|
||||
}
|
||||
|
||||
function addNotificationRuleForNotification(appName, desktopEntry) {
|
||||
var rules = JSON.parse(JSON.stringify(notificationRules || []));
|
||||
var pattern = (desktopEntry && desktopEntry !== "") ? desktopEntry : (appName || "");
|
||||
var field = (desktopEntry && desktopEntry !== "") ? "desktopEntry" : "appName";
|
||||
var rule = {
|
||||
enabled: true,
|
||||
field: pattern ? field : "appName",
|
||||
pattern: pattern || "",
|
||||
matchType: pattern ? "exact" : "contains",
|
||||
action: "default",
|
||||
urgency: "default"
|
||||
};
|
||||
rules.push(rule);
|
||||
notificationRules = rules;
|
||||
saveSettings();
|
||||
var index = rules.length - 1;
|
||||
_pendingExpandNotificationRules = true;
|
||||
_pendingNotificationRuleIndex = index;
|
||||
return index;
|
||||
}
|
||||
|
||||
function addMuteRuleForApp(appName, desktopEntry) {
|
||||
var rules = JSON.parse(JSON.stringify(notificationRules || []));
|
||||
var pattern = (desktopEntry && desktopEntry !== "") ? desktopEntry : (appName || "");
|
||||
|
||||
@@ -873,7 +873,7 @@ Rectangle {
|
||||
|
||||
Menu {
|
||||
id: notificationCardContextMenu
|
||||
width: 300
|
||||
width: 220
|
||||
closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutside
|
||||
|
||||
background: Rectangle {
|
||||
@@ -883,6 +883,31 @@ Rectangle {
|
||||
border.color: Qt.rgba(Theme.outline.r, Theme.outline.g, Theme.outline.b, 0.12)
|
||||
}
|
||||
|
||||
MenuItem {
|
||||
id: setNotificationRulesItem
|
||||
text: I18n.tr("Set notification rules")
|
||||
|
||||
contentItem: StyledText {
|
||||
text: parent.text
|
||||
font.pixelSize: Theme.fontSizeSmall
|
||||
color: Theme.surfaceText
|
||||
leftPadding: Theme.spacingS
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
}
|
||||
|
||||
background: Rectangle {
|
||||
color: parent.hovered ? Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.08) : "transparent"
|
||||
radius: Theme.cornerRadius / 2
|
||||
}
|
||||
|
||||
onTriggered: {
|
||||
const appName = notificationGroup?.appName || "";
|
||||
const desktopEntry = notificationGroup?.latestNotification?.desktopEntry || "";
|
||||
SettingsData.addNotificationRuleForNotification(appName, desktopEntry);
|
||||
PopoutService.openSettingsWithTab("notifications");
|
||||
}
|
||||
}
|
||||
|
||||
MenuItem {
|
||||
id: muteUnmuteItem
|
||||
readonly property bool isMuted: SettingsData.isAppMuted(notificationGroup?.appName || "", notificationGroup?.latestNotification?.desktopEntry || "")
|
||||
|
||||
@@ -835,7 +835,10 @@ PanelWindow {
|
||||
|
||||
Menu {
|
||||
id: popupContextMenu
|
||||
width: 300
|
||||
width: 220
|
||||
contentHeight: 130
|
||||
margins: -1
|
||||
popupType: Popup.Window
|
||||
closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutside
|
||||
|
||||
background: Rectangle {
|
||||
@@ -845,6 +848,31 @@ PanelWindow {
|
||||
border.color: Qt.rgba(Theme.outline.r, Theme.outline.g, Theme.outline.b, 0.12)
|
||||
}
|
||||
|
||||
MenuItem {
|
||||
id: setNotificationRulesItem
|
||||
text: I18n.tr("Set notification rules")
|
||||
|
||||
contentItem: StyledText {
|
||||
text: parent.text
|
||||
font.pixelSize: Theme.fontSizeSmall
|
||||
color: Theme.surfaceText
|
||||
leftPadding: Theme.spacingS
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
}
|
||||
|
||||
background: Rectangle {
|
||||
color: parent.hovered ? Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.08) : "transparent"
|
||||
radius: Theme.cornerRadius / 2
|
||||
}
|
||||
|
||||
onTriggered: {
|
||||
const appName = notificationData?.appName || "";
|
||||
const desktopEntry = notificationData?.desktopEntry || "";
|
||||
SettingsData.addNotificationRuleForNotification(appName, desktopEntry);
|
||||
PopoutService.openSettingsWithTab("notifications");
|
||||
}
|
||||
}
|
||||
|
||||
MenuItem {
|
||||
id: muteUnmuteItem
|
||||
readonly property bool isMuted: SettingsData.isAppMuted(notificationData?.appName || "", notificationData?.desktopEntry || "")
|
||||
|
||||
@@ -6,6 +6,15 @@ import qs.Modules.Settings.Widgets
|
||||
Item {
|
||||
id: root
|
||||
|
||||
Component.onCompleted: {
|
||||
if (SettingsData._pendingExpandNotificationRules) {
|
||||
SettingsData._pendingExpandNotificationRules = false;
|
||||
notificationRulesCard.userToggledCollapse = true;
|
||||
notificationRulesCard.expanded = true;
|
||||
SettingsData._pendingNotificationRuleIndex = -1;
|
||||
}
|
||||
}
|
||||
|
||||
readonly property var mutedRules: {
|
||||
var rules = SettingsData.notificationRules || [];
|
||||
var out = [];
|
||||
|
||||
Reference in New Issue
Block a user