Skip to content

Commit

Permalink
Feat: add quit app button to preview window (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
ShlomoCode authored Jul 3, 2024
1 parent 57a2077 commit 8fd795b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
21 changes: 21 additions & 0 deletions DockDoor/Utilities/WindowUtil.swift
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,27 @@ final class WindowUtil {
}
}

/// Terminates the window's application.
static func quitApp(windowInfo: WindowInfo, force: Bool) {
guard let pid = windowInfo.window?.owningApplication?.processID else {
print("Application not found")
NSSound.beep()
return
}

guard let app = NSRunningApplication(processIdentifier: pid) else {
print("No running application associated with PID \(pid)")
NSSound.beep()
return
}

if force {
app.forceTerminate()
} else {
app.terminate()
}
}

// MARK: - Minimized Window Handling

/// Retrieves minimized windows' information for a given process ID, bundle ID, and app name.
Expand Down
15 changes: 15 additions & 0 deletions DockDoor/Views/HoverWindow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,21 @@ struct WindowPreview: View {

if !windowInfo.isMinimized, let closeButton = windowInfo.closeButton {
HStack(alignment:.top, spacing: 6) {
Button(action: {
WindowUtil.quitApp(windowInfo: windowInfo, force: NSEvent.modifierFlags.contains(.option))
onTap?()
}) {
ZStack {
Image(systemName: "circle.fill")
.foregroundStyle(.secondary)
Image(systemName: "power.circle.fill")
}
}
.buttonBorderShape(.roundedRectangle)
.foregroundStyle(.purple)
.buttonStyle(.plain)
.font(.system(size: 13))

Button(action: {
WindowUtil.closeWindow(closeButton: closeButton)
onTap?()
Expand Down

0 comments on commit 8fd795b

Please sign in to comment.