Skip to content

Commit

Permalink
fixes #3: quit apps after 2 seconds delay (checking again for no wind…
Browse files Browse the repository at this point in the history
…ows)
  • Loading branch information
incanus committed Jan 17, 2023
1 parent e990bce commit b60c735
Showing 1 changed file with 6 additions and 21 deletions.
27 changes: 6 additions & 21 deletions Swift Quit/SwiftQuit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,11 @@ class SwiftQuit {
@objc class func activateAutomaticAppClosing(){
swindler.on { (event: WindowDestroyedEvent) in
let processIdentifier = event.window.application.processIdentifier
closeApplication(pid:processIdentifier)
closeApplication(pid:processIdentifier, eventApp:event.window.application)
}
}

@objc class func closeApplication(pid:Int32){
class func closeApplication(pid:Int32, eventApp:Swindler.Application){
let myAppPid = ProcessInfo.processInfo.processIdentifier

let app = AppKit.NSRunningApplication.init(processIdentifier: pid)!
Expand All @@ -143,27 +143,12 @@ class SwiftQuit {
if(swiftQuitSettings["quitWhen"] == "anyWindowClosed"){
app.terminate()
}
else{

var openWindows = 0
if let windowList = CGWindowListCopyWindowInfo(.optionOnScreenOnly, kCGNullWindowID) as? [[ String : Any]]{

for window in windowList {
if let windowName = window[kCGWindowOwnerName as String] as? String {
//print(windowName)
if windowName == app.localizedName!{
openWindows += 1
//closeApp = false
}
}
else {
DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(2)) {
if eventApp.knownWindows.isEmpty {
app.terminate()
}
}


if(openWindows == 1){
app.terminate()
}

}

}
Expand Down

0 comments on commit b60c735

Please sign in to comment.