Skip to content

Commit

Permalink
Some code cleanup
Browse files Browse the repository at this point in the history
- replace the killall command by a more soft way and unload and reload
the agent
- remove some unused code
- add some comments
  • Loading branch information
Waitsnake committed Jan 29, 2018
1 parent 94c57d4 commit 042957b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions AnimatedGif/AnimatedGifView.m
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,6 @@ - (void)startAnimation
// only call super method in case startAnimation is not called by timerMethod
[super startAnimation];

NSString *pathToScreenSaverEngine = @"/System/Library/Frameworks/ScreenSaver.framework/Resources/ScreenSaverEngine.app/Contents/MacOS/ScreenSaverEngine";
NSOperatingSystemVersion osVer = [[NSProcessInfo processInfo] operatingSystemVersion];
if (osVer.majorVersion > 10 || osVer.minorVersion > 12)
{
pathToScreenSaverEngine = @"/System/Library/CoreServices/ScreenSaverEngine.app/Contents/MacOS/ScreenSaverEngine";
}

// add glview to screensaver view in case of not in preview mode
if ([self isPreview] == FALSE)
{
Expand Down Expand Up @@ -478,8 +471,9 @@ - (IBAction)closeConfigOk:(id)sender
NSColor *colorPicked = self.colorWellBackgrColor.color;
NSInteger changeInt = [self.sliderChangeInterval integerValue];

// write values back to screensaver defaults
// init access to screensaver defaults
ScreenSaverDefaults *defaults = [ScreenSaverDefaults defaultsForModuleWithName:[[NSBundle bundleForClass: [self class]] bundleIdentifier]];
// check for changes in default values first
if ([gifFileName isEqualToString:[defaults objectForKey:@"GifFileName"]]==FALSE)
{
defaultsChanged = TRUE;
Expand Down Expand Up @@ -516,7 +510,7 @@ - (IBAction)closeConfigOk:(id)sender
{
defaultsChanged = TRUE;
}

// write new default values
[defaults setObject:gifFileName forKey:@"GifFileName"];
[defaults setFloat:frameRate forKey:@"GifFrameRate"];
[defaults setBool:frameRateManual forKey:@"GifFrameRateManual"];
Expand All @@ -537,12 +531,12 @@ - (IBAction)closeConfigOk:(id)sender
[[NSColorPanel sharedColorPanel] close];
[[NSApplication sharedApplication] endSheet:self.optionsPanel];

if (defaultsChanged==TRUE)
// check if any default value has changed and background mode is active
if ((defaultsChanged==TRUE) && (self.segmentButtonLaunchAgent.selectedSegment == LOAD_BTN))
{
// finally kill ScreenSaverEngine
// in case it was running in background it will restarted from launchd and uses the new default vales
NSString *cmdstr = [[NSString alloc] initWithFormat:@"%@", @"killall ScreenSaverEngine"];
system([cmdstr cStringUsingEncoding:NSUTF8StringEncoding]);
// in this case stop and restart ScreenSaverEngine
[self unloadAgent];
[self loadAgent];
}
}

Expand Down
Binary file modified Release/AnimatedGif.saver.zip
Binary file not shown.

0 comments on commit 042957b

Please sign in to comment.