Skip to content

Commit beb933f

Browse files
committed
App and Environment: stylistic changes for ApplicationDelegate
Add missing documentation and merge the notification names into the appropriate extensions. Increase coverage of expected notification names.
1 parent 1c8ccd7 commit beb933f

File tree

1 file changed

+72
-30
lines changed

1 file changed

+72
-30
lines changed

Sources/SwiftWin32/App and Environment/ApplicationDelegate.swift

Lines changed: 72 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,19 @@ public protocol ApplicationDelegate: AnyObject, _TriviallyConstructible {
123123
/// Informs the delegate that the application is about to terminate.
124124
func applicationWillTerminate(_ application: Application)
125125

126-
/// Responding to Environment Changes
126+
// MARK - Responding to Environment Changes
127+
128+
/// Tells the delegate that protected files are available now.
127129
func applicationProtectedDataDidBecomeAavailable(_ application: Application)
130+
131+
/// Tells the delegate that the protected files are about to become
132+
/// unavailable.
128133
func applicationProtectedDataWillBecomeUnavailable(_ application: Application)
134+
135+
/// Tells the delegate when the app receives a memory warning from the system.
129136
func applicationDidRecieveMemoryWarning(_ application: Application)
137+
138+
/// Tells the delegate when there is a significant change in the time.
130139
func applicationSignificantTimeChange(_ application: Application)
131140

132141
// MARK - Configuring and Discarding Scenes
@@ -142,18 +151,23 @@ public protocol ApplicationDelegate: AnyObject, _TriviallyConstructible {
142151
didDiscardSceneSessions sceneSessions: Set<SceneSession>)
143152
}
144153

145-
public extension ApplicationDelegate {
146-
func application(_ application: Application,
147-
willFinishLaunchingWithOptions options: [Application.LaunchOptionsKey:Any]?)
154+
extension ApplicationDelegate {
155+
public func application(_ application: Application,
156+
willFinishLaunchingWithOptions options: [Application.LaunchOptionsKey:Any]?)
148157
-> Bool {
149158
return true
150159
}
151160

152-
func application(_ application: Application,
153-
didFinishLaunchingWithOptions options: [Application.LaunchOptionsKey:Any]?)
161+
public func application(_ application: Application,
162+
didFinishLaunchingWithOptions options: [Application.LaunchOptionsKey:Any]?)
154163
-> Bool {
155164
return true
156165
}
166+
167+
/// A notification that posts immediately after the app finishes launching.
168+
public static var didFinishLaunchingNotification: NSNotification.Name {
169+
NSNotification.Name(rawValue: "UIApplicationDidFinishLaunchingNotification")
170+
}
157171
}
158172

159173
extension ApplicationDelegate {
@@ -171,6 +185,33 @@ extension ApplicationDelegate {
171185

172186
public func applicationWillTerminate(_: Application) {
173187
}
188+
189+
/// A notification that posts when the app becomes active.
190+
public static var didBecomeActiveNotification: NSNotification.Name {
191+
NSNotification.Name(rawValue: "UIApplicationDidBecomeActiveNotification")
192+
}
193+
194+
/// A notification that posts when the app is no longer active and loses
195+
/// focus.
196+
public static var willResignActiveNotification: NSNotification.Name {
197+
NSNotification.Name(rawValue: "UIApplicationWillResignActiveNotification")
198+
}
199+
200+
/// A notification that posts when the app enters the background.
201+
public static var didEnterBackgroundNotification: NSNotification.Name {
202+
NSNotification.Name(rawValue: "UIApplicationDidEnterBackgroundNotification")
203+
}
204+
205+
/// A notification that posts shortly before an app leaves the background
206+
/// state on its way to becoming the active app.
207+
public static var willEnterForegroundNotification: NSNotification.Name {
208+
NSNotification.Name(rawValue: "UIApplicationWillEnterForegroundNotification")
209+
}
210+
211+
/// A notification that posts when the app is about to terminate.
212+
public static var willTerminateNotification: NSNotification.Name {
213+
NSNotification.Name(rawValue: "UIApplicationWillTerminateNotification")
214+
}
174215
}
175216

176217
extension ApplicationDelegate {
@@ -185,6 +226,31 @@ extension ApplicationDelegate {
185226

186227
public func applicationSignificantTimeChange(_ application: Application) {
187228
}
229+
230+
/// A notification that posts when the protected files become available for
231+
/// your code to access.
232+
public static var protectedDataDidBecomeAvailableNotification: NSNotification.Name {
233+
NSNotification.Name(rawValue: "UIApplicationProtectedDataDidBecomeAvailableNotification")
234+
}
235+
236+
/// A notification that posts shortly before protected files are locked down
237+
/// and become inaccessible.
238+
public static var protectedDataWillBecomeUnavailableNotification: NSNotification.Name {
239+
NSNotification.Name(rawValue: "UIApplicationProtectedDataWillBecomeUnavailableNotification")
240+
}
241+
242+
/// A notification that posts when the app receives a warning from the
243+
/// operating system about low memory availability.
244+
public static var didReceiveMemoryWarningNotification: NSNotification.Name {
245+
NSNotification.Name(rawValue: "UIApplicationDidReceiveMemoryWarningNotification")
246+
}
247+
248+
/// A notification that posts when there is a significant change in time, for
249+
/// example, change to a new day (midnight), carrier time update, and change
250+
/// to or from daylight savings time.
251+
public static var significantTimeChangeNotification: NSNotification.Name {
252+
NSNotification.Name(rawValue: "UIApplicationSignificantTimeChangeNotification")
253+
}
188254
}
189255

190256
extension ApplicationDelegate {
@@ -203,27 +269,3 @@ extension ApplicationDelegate {
203269
}
204270
}
205271
}
206-
207-
extension ApplicationDelegate {
208-
public static var didFinishLaunchingNotification: NSNotification.Name {
209-
NSNotification.Name(rawValue: "UIApplicationDidFinishLaunchingNotification")
210-
}
211-
}
212-
213-
extension ApplicationDelegate {
214-
public static var didBecomeActiveNotification: NSNotification.Name {
215-
NSNotification.Name(rawValue: "UIApplicationDidBecomeActiveNotification")
216-
}
217-
public static var didEnterBackgroundNotification: NSNotification.Name {
218-
NSNotification.Name(rawValue: "UIApplicationDidEnterBackgroundNotification")
219-
}
220-
public static var willEnterForegroundNotification: NSNotification.Name {
221-
NSNotification.Name(rawValue: "UIApplicationWillEnterForegroundNotification")
222-
}
223-
public static var willResignActiveNotification: NSNotification.Name {
224-
NSNotification.Name(rawValue: "UIApplicationWillResignActiveNotification")
225-
}
226-
public static var willTerminateNotification: NSNotification.Name {
227-
NSNotification.Name(rawValue: "UIApplicationWillTerminateNotification")
228-
}
229-
}

0 commit comments

Comments
 (0)