Optimize -autolaunch YES checking code.

This commit is contained in:
Sergii Stoian 2019-04-03 02:10:37 +03:00
parent 215eb89e27
commit f8c955acf4
2 changed files with 19 additions and 14 deletions

View file

@ -1,3 +1,8 @@
2019-04-03 Sergii Stoian <stoyan255@ukr.net>
* Source/NSApplication.m (activateIgnoringOtherApps:):
Optimize `-autolaunch YES` checking code.
2019-04-02 Sergii Stoian <stoyan255@gmail.com>
* Source/NSApplication.m:

View file

@ -753,6 +753,8 @@ static NSSize scaledIconSizeForSize(NSSize imageSize)
*/
@implementation NSApplication
static BOOL _isAutolaunchChecked = NO;
/*
* Class methods
*/
@ -1259,21 +1261,19 @@ static NSSize scaledIconSizeForSize(NSSize imageSize)
*/
- (void) activateIgnoringOtherApps: (BOOL)flag
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *autolaunch = [defaults objectForKey: @"autolaunch"];
/* Application was executed with argument '-autolaunch YES'. Set argument
* value to "NO" for future calls to `activateIgnoringOtherApps:`. */
if (autolaunch && [autolaunch isEqualToString: @"YES"])
if (_isAutolaunchChecked == NO)
{
NSMutableDictionary *args;
args = [[defaults volatileDomainForName: NSArgumentDomain] mutableCopy];
[defaults removeVolatileDomainForName: NSArgumentDomain];
[args setObject: @"NO" forKey: @"autolaunch"];
[defaults setVolatileDomain: [NSDictionary dictionaryWithDictionary: args]
forName: NSArgumentDomain];
[args release];
return;
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *autolaunch = [defaults objectForKey: @"autolaunch"];
_isAutolaunchChecked = YES;
/* Application was executed with an argument '-autolaunch YES'.
Do not activate application on first call. */
if (autolaunch && [autolaunch isEqualToString: @"YES"])
{
return;
}
}
// TODO: Currently the flag is ignored