Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: add quit app button to preview window #51

Merged
merged 1 commit into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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