Index: src/OFApplication.h ================================================================== --- src/OFApplication.h +++ src/OFApplication.h @@ -14,10 +14,11 @@ */ #include #import "OFObject.h" +#import "OFNotification.h" OF_ASSUME_NONNULL_BEGIN /** @file */ @@ -26,10 +27,15 @@ @class OFMutableArray OF_GENERIC(ObjectType); @class OFMutableDictionary OF_GENERIC(KeyType, ObjectType); @class OFSandbox; @class OFString; +/** + * @brief A notification that will be sent when the application will terminate. + */ +extern const OFNotificationName OFApplicationWillTerminateNotification; + /** * @brief Specify the class to be used as the application delegate. * * An instance of this class will be created and act as the application * delegate. @@ -143,10 +149,14 @@ * @brief A class which represents the application as an object. * * In order to create a new OFApplication, you should create a class conforming * to the optional @ref OFApplicationDelegate protocol and put * `OF_APPLICATION_DELEGATE(NameOfYourClass)` in the .m file of that class. + * + * When the application is about to be terminated, + * @ref OFApplicationDelegate#applicationWillTerminate will be called on the + * delegate and an @ref OFApplicationWillTerminateNotification will be sent. */ OF_SUBCLASSING_RESTRICTED @interface OFApplication: OFObject { OFString *_programName; Index: src/OFApplication.m ================================================================== --- src/OFApplication.m +++ src/OFApplication.m @@ -30,10 +30,11 @@ #ifdef OF_AMIGAOS # import "OFFile.h" # import "OFFileManager.h" #endif #import "OFLocale.h" +#import "OFNotificationCenter.h" #import "OFPair.h" #import "OFRunLoop+Private.h" #import "OFRunLoop.h" #import "OFSandbox.h" #import "OFString.h" @@ -78,16 +79,22 @@ - (void)of_setArgumentCount: (int)argc andWideArgumentValues: (wchar_t *[])argv; #endif - (void)of_run; @end +const OFNotificationName OFApplicationWillTerminateNotification = + @"OFApplicationWillTerminateNotification"; static OFApplication *app = nil; static void atexitHandler(void) { id delegate = app.delegate; + + [[OFNotificationCenter defaultCenter] + postNotificationName: OFApplicationWillTerminateNotification + object: app]; if ([delegate respondsToSelector: @selector(applicationWillTerminate)]) [delegate applicationWillTerminate]; [delegate release];