Skip to content

Commit 87651d8

Browse files
committed
feat(disable-quit): new argument to prevent cmd+q effect
1 parent 8e51650 commit 87651d8

File tree

7 files changed

+27
-9
lines changed

7 files changed

+27
-9
lines changed

Notification Agent Core/Controllers/HelpBuilder.swift

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ public final class HelpBuilder {
4545
"-popup_reminder".yellow(),
4646
"-retain_values".yellow(),
4747
"-background_panel".yellow(),
48-
"-unmovable".yellow()]
48+
"-unmovable".yellow(),
49+
"-disable_quit".yellow()]
4950
static let bannerArguments: [String] = ["-type".green(),
5051
"-title".yellow(),
5152
"-subtitle".yellow(),
@@ -65,7 +66,8 @@ public final class HelpBuilder {
6566
"-hide_title_bar_buttons".yellow(),
6667
"-background_panel".yellow(),
6768
"-unmovable".yellow(),
68-
"-timeout".yellow()]
69+
"-timeout".yellow(),
70+
"-disable_quit".yellow()]
6971
static let systemAlertArguments: [String] = ["-type".green(),
7072
"-title".yellow(),
7173
"-subtitle".yellow(),
@@ -132,8 +134,8 @@ public final class HelpBuilder {
132134
"\n A text payload to define the behavior of an optional reminder for the pop-up. The reminder is basically a timer at the end of which the pop-up is pushed again on top of the view hierarchy on screen. The payload format is: " + "\"/timeinterval <TIME_IN_SECONDS> /silent /repeat\" ".green() + "\n Example: -popup_reminder \"/timeinterval 300\"",
133135
"\n Flag that tells the agent to print the available accessory view outputs on any exit (main or secondary button clicked).",
134136
"[ opaque | translucent ]".red() + "\n The style for the background panel that will cover all the screens.\n Example: -background_panel opaque",
135-
"\n Flag that make the UI unmovable for the user.\n Example: -unmovable"]
136-
137+
"\n Flag that make the UI unmovable for the user.\n Example: -unmovable",
138+
"\n Flag that tells the agent to ignore cmd+q shortcut.\n Example: -disable_quit"]
137139
static let bannerDescriptions: [String] = ["[ banner | alert ]".red() + "\n The UI type of the notification.\n Example: -type banner",
138140
"\n The title of the notification.\n Example: -title \"Title\"",
139141
"\n The subtitle of the notification. It supports MarkDown text.\n Example: -subtitle \"Subtitle\"",
@@ -153,7 +155,8 @@ public final class HelpBuilder {
153155
"\n Flag that tells the agent to remove the title bar buttons for the Onbording UI.\n Example: -hide_title_bar_buttons",
154156
"[ opaque | translucent ]".red() + "\n The style for the background panel that will cover all the screens.\n Example: -background_panel opaque",
155157
"\n Flag that make the UI unmovable for the user.\n Example: -unmovable",
156-
"\n The timeout for the onboarding. After this amount of seconds the agent exit with the timeout exit code.\n Example: -timeout 300"]
158+
"\n The timeout for the onboarding. After this amount of seconds the agent exit with the timeout exit code.\n Example: -timeout 300",
159+
"\n Flag that tells the agent to ignore cmd+q shortcut.\n Example: -disable_quit"]
157160
static let systemAlertDescriptions: [String] = ["[ systemAlert ]".red() + "\n The UI type of the notification.\n Example: -type systemAlert",
158161
"\n The title of the notification.\n Example: -title \"Title\"",
159162
"\n The subtitle of the notification.\n Example: -subtitle \"Subtitle\"",

Notification Agent Onboarding/AppDelegate.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
3535
NSEvent.addLocalMonitorForEvents(matching: .keyDown) { event in
3636
switch event.modifierFlags.intersection(.deviceIndependentFlagsMask) {
3737
case [.command] where event.characters == "q":
38+
guard !self.context.disableQuit else { return .none }
3839
Utils.applicationExit(withReason: .userDismissedOnboarding)
3940
default:
4041
return event

Notification Agent Popups/AppDelegate.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
3535
NSEvent.addLocalMonitorForEvents(matching: .keyDown) { event in
3636
switch event.modifierFlags.intersection(.deviceIndependentFlagsMask) {
3737
case [.command] where event.characters == "q":
38+
guard !self.context.disableQuit else { return .none }
3839
Utils.applicationExit(withReason: .userDismissedPopup)
3940
default:
4041
return event

Shared/Controllers/Context.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,5 @@ final class Context {
3535
}
3636
}
3737
var backgroundPanelsController: BackPanelController?
38+
var disableQuit: Bool = false
3839
}

Shared/Controllers/EFCLController.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ class EFCLController {
3535
"hide_title_bar_buttons",
3636
"retain_values",
3737
"show_suppression_button",
38-
"unmovable"]
38+
"unmovable",
39+
"disable_quit"]
3940
// MARK: - Variables
4041

4142
let context = Context.main

Shared/Extensions/EFCLController-Extension.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ extension EFCLController {
2424
}
2525
let taskObject = try JSONDecoder().decode(TaskObject.self, from: data)
2626
context.sharedSettings = taskObject.settings
27+
context.disableQuit = taskObject.notification.disableQuit
2728
NotificationCenter.default.post(name: .showNotification,
2829
object: self,
2930
userInfo: ["object": taskObject.notification])

Shared/Model/UIObjects/NotificationObject.swift

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ public final class NotificationObject: NSObject, Codable, NSSecureCoding {
107107
var backgroundPanel: BackgroundPanelStyle?
108108
/// A boolean value that define if the UI should be movable for the user.
109109
var isMovable: Bool = true
110+
/// A boolean value that define if the UI should ignore cmd+q shortcut.
111+
var disableQuit: Bool = false
110112

111113
// MARK: - Initializers
112114

@@ -243,6 +245,9 @@ public final class NotificationObject: NSObject, Codable, NSSecureCoding {
243245
if let isNotMovable = dict["unmovable"] as? String {
244246
self.isMovable = !(isNotMovable.lowercased() == "true")
245247
}
248+
if let disableQuit = dict["disable_quit"] as? String {
249+
self.disableQuit = disableQuit.lowercased() == "true"
250+
}
246251
super.init()
247252
try checkObjectConsistency()
248253
}
@@ -341,6 +346,7 @@ public final class NotificationObject: NSObject, Codable, NSSecureCoding {
341346
case workflow
342347
case backgroundPanel
343348
case isMovable
349+
case disableQuit
344350
}
345351

346352
required public init(from decoder: Decoder) throws {
@@ -385,6 +391,7 @@ public final class NotificationObject: NSObject, Codable, NSSecureCoding {
385391
self.backgroundPanel = BackgroundPanelStyle(rawValue: backgroundPanelRawValue)
386392
}
387393
self.isMovable = try container.decode(Bool.self, forKey: .isMovable)
394+
self.disableQuit = try container.decode(Bool.self, forKey: .disableQuit)
388395
}
389396

390397
public func encode(to encoder: Encoder) throws {
@@ -421,7 +428,7 @@ public final class NotificationObject: NSObject, Codable, NSSecureCoding {
421428
try container.encodeIfPresent(self.workflow?.rawValue, forKey: .workflow)
422429
try container.encodeIfPresent(self.backgroundPanel?.rawValue, forKey: .backgroundPanel)
423430
try container.encodeIfPresent(self.isMovable, forKey: .isMovable)
424-
431+
try container.encodeIfPresent(self.disableQuit, forKey: .disableQuit)
425432
}
426433

427434
// MARK: Codable protocol conformity - END
@@ -518,8 +525,10 @@ public final class NotificationObject: NSObject, Codable, NSSecureCoding {
518525
if let backgroundPanelRawValue = self.backgroundPanel?.rawValue {
519526
coder.encode(backgroundPanelRawValue, forKey: NOCodingKeys.backgroundPanel.rawValue)
520527
}
521-
let number = NSNumber(booleanLiteral: isMovable)
522-
coder.encode(number, forKey: NOCodingKeys.isMovable.rawValue)
528+
let nIsMovable = NSNumber(booleanLiteral: isMovable)
529+
coder.encode(nIsMovable, forKey: NOCodingKeys.isMovable.rawValue)
530+
let nDisableQuit = NSNumber(booleanLiteral: disableQuit)
531+
coder.encode(nDisableQuit, forKey: NOCodingKeys.disableQuit.rawValue)
523532
}
524533

525534
// swiftlint:enable function_body_length
@@ -562,6 +571,7 @@ public final class NotificationObject: NSObject, Codable, NSSecureCoding {
562571
self.backgroundPanel = BackgroundPanelStyle(rawValue: backgroundPanelRawValue as String)
563572
}
564573
self.isMovable = coder.decodeObject(of: NSNumber.self, forKey: NOCodingKeys.isMovable.rawValue) as? Bool ?? true
574+
self.disableQuit = coder.decodeObject(of: NSNumber.self, forKey: NOCodingKeys.disableQuit.rawValue) as? Bool ?? true
565575
}
566576

567577
// MARK: - NSSecureCoding protocol conformity - END

0 commit comments

Comments
 (0)