scoop:scoop.window:0.1.0
src/owner/shutdown.scoop
Selected production source · src/owner/shutdown.scoop
1
package scoop.window3
internal fun ApplicationOwner.cleanupEvent(event: ApplicationEvent) {4
dispatchDepth += 15
try {6
handler!!.onEvent(active, event)7
}8
catch (error: Throwable) {9
recordFailure(error)10
beginExit()11
}12
finally {13
dispatchDepth -= 114
}15
}17
internal fun ApplicationOwner.drainShutdown() {18
if (dispatchDepth != 0)19
return20
drainFileDialogs()21
drainModals()22
drainMenus()23
if (exiting && !attached) {24
for (watch in watches)25
if (!watch.removing)26
watch.remove {}27
}28
if (exiting && !exitingDelivered) {29
exitingDelivered = true30
cleanupEvent(ApplicationEvent.Exiting)31
}32
for (window in windows.toArray()) {33
if (window.phase == WindowState.Closing && !window.closingDelivered) {34
window.closingDelivered = true35
cleanupEvent(ApplicationEvent.Window(window.id, WindowEvent.Closing))36
}37
}38
if (exiting && !attachmentCloseRequested) {39
attachmentCloseRequested = true40
when (attachment) {41
case Some(val value) -> try {42
value.requestClose()43
} catch (error: Throwable) {44
recordFailure(error)45
}46
case None -> {}47
}48
}49
var index = 0L50
while (index < windows.size) {51
val window = windows[index]52
if (53
window.phase ==54
WindowState.Closing &&55
window.closingDelivered &&56
window.leases ==57
0L &&58
!hasOwnedWindow(window)59
) {60
@Unsafe61
{62
nativeWindowDestroy(window.pointer!!)63
}64
window.pointer = None65
window.phase = WindowState.Destroyed66
windows.removeAt(index)67
cleanupEvent(ApplicationEvent.Window(window.id, WindowEvent.Destroyed))68
didDestroyWindow()69
index = 0L70
} else71
index += 1L72
}73
if (74
exiting &&75
exitingDelivered &&76
windows.size ==77
0L &&78
watches.size ==79
0L &&80
menus.size ==81
0L &&82
fileDialogs.size ==83
0L &&84
modals.size ==85
0L &&86
nativeResources.size ==87
0L &&88
nativeOperations.size ==89
0L &&90
nativeOperationDepth ==91
0 &&92
(!attached || attachmentComplete) &&93
mailbox.sealControlsIfEmpty()94
) {95
stopped = true96
@Unsafe97
{98
nativeApplicationStop(native!!)99
}100
}101
}