Scoop API

scoop:scoop.window:0.1.0

src/owner/shutdown.scoop

Selected production source · src/owner/shutdown.scoop

1package scoop.window
3internal fun ApplicationOwner.cleanupEvent(event: ApplicationEvent) {
4 dispatchDepth += 1
5 try {
6 handler!!.onEvent(active, event)
7 }
8 catch (error: Throwable) {
9 recordFailure(error)
10 beginExit()
11 }
12 finally {
13 dispatchDepth -= 1
14 }
17internal fun ApplicationOwner.drainShutdown() {
18 if (dispatchDepth != 0)
19 return
20 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 = true
30 cleanupEvent(ApplicationEvent.Exiting)
31 }
32 for (window in windows.toArray()) {
33 if (window.phase == WindowState.Closing && !window.closingDelivered) {
34 window.closingDelivered = true
35 cleanupEvent(ApplicationEvent.Window(window.id, WindowEvent.Closing))
36 }
37 }
38 if (exiting && !attachmentCloseRequested) {
39 attachmentCloseRequested = true
40 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 = 0L
50 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 @Unsafe
61 {
62 nativeWindowDestroy(window.pointer!!)
63 }
64 window.pointer = None
65 window.phase = WindowState.Destroyed
66 windows.removeAt(index)
67 cleanupEvent(ApplicationEvent.Window(window.id, WindowEvent.Destroyed))
68 didDestroyWindow()
69 index = 0L
70 } else
71 index += 1L
72 }
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 = true
96 @Unsafe
97 {
98 nativeApplicationStop(native!!)
99 }
100 }