From 39a3ae3522e168e76f97511fa9623eff587d7580 Mon Sep 17 00:00:00 2001 From: Simone Manganelli Date: Wed, 24 Jun 2009 22:11:34 -0700 Subject: [PATCH] finished external .plist prefs file support; includes code to migrate existing parasitic prefs from com.apple.Safari.plist to the new external file --- CTFUserDefaultsController.h | 20 -- CTFUserDefaultsController.m | 50 ---- ClickToFlash.xcodeproj/project.pbxproj | 24 +- .../CTFPreferencesDictionary.h | 0 .../CTFPreferencesDictionary.m | 6 +- Plugin/CTFUserDefaultsController.h | 36 +++ Plugin/CTFUserDefaultsController.m | 124 ++++++++++ Plugin/CTFWhitelist.m | 13 +- Plugin/CTFsIFRSupport.m | 7 +- Plugin/English.lproj/WhitelistPanel.xib | 215 ++++++++++-------- Plugin/Plugin.h | 1 + Plugin/Plugin.m | 67 ++++-- SparkleManager.m | 9 +- 13 files changed, 371 insertions(+), 201 deletions(-) delete mode 100644 CTFUserDefaultsController.h delete mode 100644 CTFUserDefaultsController.m rename CTFPreferencesDictionary.h => Plugin/CTFPreferencesDictionary.h (100%) rename CTFPreferencesDictionary.m => Plugin/CTFPreferencesDictionary.m (79%) create mode 100644 Plugin/CTFUserDefaultsController.h create mode 100644 Plugin/CTFUserDefaultsController.m diff --git a/CTFUserDefaultsController.h b/CTFUserDefaultsController.h deleted file mode 100644 index afffead1..00000000 --- a/CTFUserDefaultsController.h +++ /dev/null @@ -1,20 +0,0 @@ -// -// CTFUserDefaultsController.h -// ClickToFlash -// -// Created by Simone Manganelli on 2009-05-23. -// Copyright 2009 __MyCompanyName__. All rights reserved. -// - -#import -#import "CTFPreferencesDictionary.h" - - -@interface CTFUserDefaultsController : NSUserDefaultsController { - CTFPreferencesDictionary *userDefaultsDict; -} - -- (void)pluginDefaultsDidChange:(NSNotification *)notification; -- (void)setValues:(CTFPreferencesDictionary *)newUserDefaultsDict; - -@end diff --git a/CTFUserDefaultsController.m b/CTFUserDefaultsController.m deleted file mode 100644 index 07a64c81..00000000 --- a/CTFUserDefaultsController.m +++ /dev/null @@ -1,50 +0,0 @@ -// -// CTFUserDefaultsController.m -// ClickToFlash -// -// Created by Simone Manganelli on 2009-05-23. -// Copyright 2009 __MyCompanyName__. All rights reserved. -// - -#import "CTFUserDefaultsController.h" - - -@implementation CTFUserDefaultsController - -- (void)awakeFromNib; -{ - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(pluginDefaultsDidChange:) - name:@"ClickToFlashPluginDefaultsDidChange" - object:nil]; - [self setValues:[CTFPreferencesDictionary dictionaryWithDictionary: - [[NSUserDefaults standardUserDefaults] persistentDomainForName:@"com.github.rentzsch.clicktoflash"]] - ]; -} - -- (void)dealloc; -{ - [userDefaultsDict release]; - [super dealloc]; -} - -- (CTFPreferencesDictionary *)values; -{ - return userDefaultsDict; -} - -- (void)setValues:(CTFPreferencesDictionary *)newUserDefaultsDict; -{ - if (! userDefaultsDict) userDefaultsDict = [[CTFPreferencesDictionary alloc] init]; - [userDefaultsDict removeAllObjects]; - [userDefaultsDict addEntriesFromDictionary:newUserDefaultsDict]; -} - -- (void)pluginDefaultsDidChange:(NSNotification *)notification; -{ - NSLog(@"Setting persistent domain defaults: %@", userDefaultsDict); - [[NSUserDefaults standardUserDefaults] setPersistentDomain:userDefaultsDict - forName:@"com.github.rentzsch.clicktoflash"]; -} - -@end diff --git a/ClickToFlash.xcodeproj/project.pbxproj b/ClickToFlash.xcodeproj/project.pbxproj index 1f6d0be5..d0b8e054 100755 --- a/ClickToFlash.xcodeproj/project.pbxproj +++ b/ClickToFlash.xcodeproj/project.pbxproj @@ -51,9 +51,9 @@ 844695F70F470D1F00DC783A /* CTFsIFRSupport.m in Sources */ = {isa = PBXBuildFile; fileRef = 844695910F46FC6600DC783A /* CTFsIFRSupport.m */; }; 845704550F4792320017F3F4 /* CTFWhitelist.m in Sources */ = {isa = PBXBuildFile; fileRef = 845704540F4792320017F3F4 /* CTFWhitelist.m */; }; 8457045A0F47BC170017F3F4 /* CTFUtilities.m in Sources */ = {isa = PBXBuildFile; fileRef = 845704590F47BC170017F3F4 /* CTFUtilities.m */; }; - A41626600FCB535300181427 /* CTFPreferencesDictionary.m in Sources */ = {isa = PBXBuildFile; fileRef = A416265F0FCB535300181427 /* CTFPreferencesDictionary.m */; }; - A461B6590FC8ECB20028C966 /* CTFUserDefaultsController.m in Sources */ = {isa = PBXBuildFile; fileRef = A461B6580FC8ECB20028C966 /* CTFUserDefaultsController.m */; }; A494CC2C0F9F2446007D5EEB /* ctf.icns in Resources */ = {isa = PBXBuildFile; fileRef = A494CC2B0F9F2446007D5EEB /* ctf.icns */; }; + A4DEFC460FF33D2D00CCB6A8 /* CTFPreferencesDictionary.m in Sources */ = {isa = PBXBuildFile; fileRef = A4DEFC430FF33D2D00CCB6A8 /* CTFPreferencesDictionary.m */; }; + A4DEFC470FF33D2D00CCB6A8 /* CTFUserDefaultsController.m in Sources */ = {isa = PBXBuildFile; fileRef = A4DEFC450FF33D2D00CCB6A8 /* CTFUserDefaultsController.m */; }; B5028E930F413553004886D7 /* HarnessAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = B5028E910F413553004886D7 /* HarnessAppDelegate.m */; }; B5CFF17A0F40EEF1005DB9CC /* WhitelistPanel.xib in Resources */ = {isa = PBXBuildFile; fileRef = 072189BC0F30D9C3008C8944 /* WhitelistPanel.xib */; }; B5CFF1870F40F000005DB9CC /* HarnessMain.xib in Resources */ = {isa = PBXBuildFile; fileRef = B5CFF1860F40F000005DB9CC /* HarnessMain.xib */; }; @@ -157,11 +157,11 @@ 845704540F4792320017F3F4 /* CTFWhitelist.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CTFWhitelist.m; path = Plugin/CTFWhitelist.m; sourceTree = ""; }; 845704580F47BC170017F3F4 /* CTFUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CTFUtilities.h; path = Plugin/CTFUtilities.h; sourceTree = ""; }; 845704590F47BC170017F3F4 /* CTFUtilities.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CTFUtilities.m; path = Plugin/CTFUtilities.m; sourceTree = ""; }; - A416265E0FCB535300181427 /* CTFPreferencesDictionary.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CTFPreferencesDictionary.h; sourceTree = ""; }; - A416265F0FCB535300181427 /* CTFPreferencesDictionary.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CTFPreferencesDictionary.m; sourceTree = ""; }; - A461B6570FC8ECB20028C966 /* CTFUserDefaultsController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CTFUserDefaultsController.h; sourceTree = ""; }; - A461B6580FC8ECB20028C966 /* CTFUserDefaultsController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CTFUserDefaultsController.m; sourceTree = ""; }; A494CC2B0F9F2446007D5EEB /* ctf.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; path = ctf.icns; sourceTree = ""; }; + A4DEFC420FF33D2D00CCB6A8 /* CTFPreferencesDictionary.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CTFPreferencesDictionary.h; path = Plugin/CTFPreferencesDictionary.h; sourceTree = ""; }; + A4DEFC430FF33D2D00CCB6A8 /* CTFPreferencesDictionary.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CTFPreferencesDictionary.m; path = Plugin/CTFPreferencesDictionary.m; sourceTree = ""; }; + A4DEFC440FF33D2D00CCB6A8 /* CTFUserDefaultsController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CTFUserDefaultsController.h; path = Plugin/CTFUserDefaultsController.h; sourceTree = ""; }; + A4DEFC450FF33D2D00CCB6A8 /* CTFUserDefaultsController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CTFUserDefaultsController.m; path = Plugin/CTFUserDefaultsController.m; sourceTree = ""; }; B5028E910F413553004886D7 /* HarnessAppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = HarnessAppDelegate.m; path = "TestFiles/Debugging Harness/HarnessAppDelegate.m"; sourceTree = ""; }; B5028E920F413553004886D7 /* HarnessAppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = HarnessAppDelegate.h; path = "TestFiles/Debugging Harness/HarnessAppDelegate.h"; sourceTree = ""; }; B5CFF1740F40EEDB005DB9CC /* Whitelist Panel Harness.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Whitelist Panel Harness.app"; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -229,10 +229,10 @@ children = ( 55EB703D0E04A84F0016593D /* Plugin.m */, 55EB703C0E04A84F0016593D /* Plugin.h */, - A416265E0FCB535300181427 /* CTFPreferencesDictionary.h */, - A416265F0FCB535300181427 /* CTFPreferencesDictionary.m */, - A461B6570FC8ECB20028C966 /* CTFUserDefaultsController.h */, - A461B6580FC8ECB20028C966 /* CTFUserDefaultsController.m */, + A4DEFC420FF33D2D00CCB6A8 /* CTFPreferencesDictionary.h */, + A4DEFC430FF33D2D00CCB6A8 /* CTFPreferencesDictionary.m */, + A4DEFC440FF33D2D00CCB6A8 /* CTFUserDefaultsController.h */, + A4DEFC450FF33D2D00CCB6A8 /* CTFUserDefaultsController.m */, 845704580F47BC170017F3F4 /* CTFUtilities.h */, 845704590F47BC170017F3F4 /* CTFUtilities.m */, 6953E4340F3EDE9D0014ECF7 /* CTFMenubarMenuController.m */, @@ -468,8 +468,8 @@ 8457045A0F47BC170017F3F4 /* CTFUtilities.m in Sources */, 79E2EB930F86AAD3005CF170 /* SparkleManager.m in Sources */, 0038DE240FC0CCF0007B54E9 /* MATrackingArea.m in Sources */, - A461B6590FC8ECB20028C966 /* CTFUserDefaultsController.m in Sources */, - A41626600FCB535300181427 /* CTFPreferencesDictionary.m in Sources */, + A4DEFC460FF33D2D00CCB6A8 /* CTFPreferencesDictionary.m in Sources */, + A4DEFC470FF33D2D00CCB6A8 /* CTFUserDefaultsController.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/CTFPreferencesDictionary.h b/Plugin/CTFPreferencesDictionary.h similarity index 100% rename from CTFPreferencesDictionary.h rename to Plugin/CTFPreferencesDictionary.h diff --git a/CTFPreferencesDictionary.m b/Plugin/CTFPreferencesDictionary.m similarity index 79% rename from CTFPreferencesDictionary.m rename to Plugin/CTFPreferencesDictionary.m index 8f3092c2..83807103 100644 --- a/CTFPreferencesDictionary.m +++ b/Plugin/CTFPreferencesDictionary.m @@ -5,6 +5,11 @@ // Created by Simone Manganelli on 2009-05-25. // Copyright 2009 __MyCompanyName__. All rights reserved. // +// the rationale for this class is so that we can monitor when +// defaults change, and update the *external* preference file accordingly. +// to do so, we need to monitor the mutable dictionary that represents the +// defaults. this class follows @bbum's suggestion at this URL: +// http://www.omnigroup.com/mailman/archive/macosx-dev/1999-April/007726.html #import "CTFPreferencesDictionary.h" @@ -43,7 +48,6 @@ - (void)dealloc; - (void)setObject:(id)object forKey:(id)key; { [realMutableDictionary setObject:object forKey:key]; - NSLog(@"posting a notification of defaults change"); [[NSNotificationCenter defaultCenter] postNotificationName:@"ClickToFlashPluginDefaultsDidChange" object:self]; } diff --git a/Plugin/CTFUserDefaultsController.h b/Plugin/CTFUserDefaultsController.h new file mode 100644 index 00000000..aadbe036 --- /dev/null +++ b/Plugin/CTFUserDefaultsController.h @@ -0,0 +1,36 @@ +// +// CTFUserDefaultsController.h +// ClickToFlash +// +// Created by Simone Manganelli on 2009-05-23. +// Copyright 2009 __MyCompanyName__. All rights reserved. +// + +#import +#import "CTFPreferencesDictionary.h" + + +@interface CTFUserDefaultsController : NSUserDefaultsController { + CTFPreferencesDictionary *userDefaultsDict; + BOOL hasInited; +} + ++ (CTFUserDefaultsController *)standardUserDefaults; +- (void)setUpExternalPrefsDictionary; + +- (void)pluginDefaultsDidChange:(NSNotification *)notification; +- (CTFPreferencesDictionary *)values; +- (CTFPreferencesDictionary *)dictionaryRepresentation; +- (void)setValues:(CTFPreferencesDictionary *)newUserDefaultsDict; + +- (id)objectForKey:(NSString *)defaultName; +- (void)setObject:(id)value forKey:(NSString *)defaultName; +- (int)integerForKey:(NSString *)defaultName; +- (void)setIntegerForKey:(int)value forKey:(NSString *)defaultName; +- (BOOL)boolForKey:(NSString *)defaultName; +- (void)setBool:(BOOL)value forKey:(NSString *)defaultName; +- (NSArray *)arrayForKey:(NSString *)defaultName; +- (void)removeObjectForKey:(NSString *)defaultName; + + +@end diff --git a/Plugin/CTFUserDefaultsController.m b/Plugin/CTFUserDefaultsController.m new file mode 100644 index 00000000..aada7cc8 --- /dev/null +++ b/Plugin/CTFUserDefaultsController.m @@ -0,0 +1,124 @@ +// +// CTFUserDefaultsController.m +// ClickToFlash +// +// Created by Simone Manganelli on 2009-05-23. +// Copyright 2009 __MyCompanyName__. All rights reserved. +// + +#import "CTFUserDefaultsController.h" + +static CTFUserDefaultsController *sharedInstance = nil; + +@implementation CTFUserDefaultsController + ++ (CTFUserDefaultsController *)standardUserDefaults; +{ + if (! sharedInstance) sharedInstance = [[self alloc] init]; + return sharedInstance; +} + +- (id)init; +{ + if (! sharedInstance) { + if ((self = [super init])) { + hasInited = YES; + } + } + + return self; +} + +- (void)dealloc; +{ + [userDefaultsDict release]; + [super dealloc]; +} + +- (void)setUpExternalPrefsDictionary; +{ + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(pluginDefaultsDidChange:) + name:@"ClickToFlashPluginDefaultsDidChange" + object:nil]; + [self setValues:[CTFPreferencesDictionary dictionaryWithDictionary: + [[NSUserDefaults standardUserDefaults] persistentDomainForName:@"com.github.rentzsch.clicktoflash"]] + ]; +} + +- (CTFPreferencesDictionary *)values; +{ + // I have no idea why, but -init, -initWithDefaults:initialValues:, + // and +sharedUserDefaultsController all never seem to get called. Only + // -awakeFromNib gets called, and that's too late for bindings; + + // so instead, we just wait for the initial call to access values, + // and if that call detects that the user defaults dictionary hasn't + // been set up yet, it sets it up and *then* returns the values + + if (! userDefaultsDict) [self setUpExternalPrefsDictionary]; + return userDefaultsDict; +} + +- (CTFPreferencesDictionary *)dictionaryRepresentation; +{ + return [self values]; +} + +- (void)setValues:(CTFPreferencesDictionary *)newUserDefaultsDict; +{ + if (! userDefaultsDict) userDefaultsDict = [[CTFPreferencesDictionary alloc] init]; + [userDefaultsDict removeAllObjects]; + [userDefaultsDict addEntriesFromDictionary:newUserDefaultsDict]; +} + +- (void)pluginDefaultsDidChange:(NSNotification *)notification; +{ + [[NSUserDefaults standardUserDefaults] setPersistentDomain:userDefaultsDict + forName:@"com.github.rentzsch.clicktoflash"]; +} + +- (id)objectForKey:(NSString *)defaultName; +{ + return [[self values] objectForKey:defaultName]; +} + +- (void)setObject:(id)value forKey:(NSString *)defaultName; +{ + [[self values] setObject:value forKey:defaultName]; +} + +- (int)integerForKey:(NSString *)defaultName; +{ + return [[[self values] objectForKey:defaultName] intValue]; +} + +- (void)setIntegerForKey:(int)value forKey:(NSString *)defaultName; +{ + [[self values] setObject:[NSNumber numberWithInt:value] forKey:defaultName]; +} + +- (BOOL)boolForKey:(NSString *)defaultName; +{ + return [[[self values] objectForKey:defaultName] boolValue]; +} + +- (void)setBool:(BOOL)value forKey:(NSString *)defaultName; +{ + [[self values] setObject:[NSNumber numberWithBool:value] forKey:defaultName]; +} + +- (NSArray *)arrayForKey:(NSString *)defaultName; +{ + id value = [[self values] objectForKey:defaultName]; + id valueToReturn = nil; + if ([[value className] isEqualToString:@"NSCFArray"]) valueToReturn = value; + return valueToReturn; +} + +- (void)removeObjectForKey:(NSString *)defaultName; +{ + [[self values] removeObjectForKey:defaultName]; +} + +@end diff --git a/Plugin/CTFWhitelist.m b/Plugin/CTFWhitelist.m index 4c6913d0..b8f23828 100644 --- a/Plugin/CTFWhitelist.m +++ b/Plugin/CTFWhitelist.m @@ -29,11 +29,14 @@ of this software and associated documentation files (the "Software"), to deal #import "CTFUtilities.h" #import "CTFMenubarMenuController.h" +#import "CTFUserDefaultsController.h" +#import "CTFPreferencesDictionary.h" + // NSNotification names static NSString *sCTFWhitelistAdditionMade = @"CTFWhitelistAdditionMade"; - // NSUserDefaults keys + // CTFUserDefaultsController keys static NSString *sHostSiteInfoDefaultsKey = @"ClickToFlash_siteInfo"; typedef enum { @@ -160,13 +163,13 @@ - (BOOL) _isHostWhitelisted - (BOOL) _isWhiteListedForHostString:(NSString *)hostString { - NSArray *hostWhitelist = [[NSUserDefaults standardUserDefaults] arrayForKey: sHostSiteInfoDefaultsKey]; + NSArray *hostWhitelist = [[CTFUserDefaultsController standardUserDefaults] arrayForKey: sHostSiteInfoDefaultsKey]; return hostWhitelist && itemForSite(hostWhitelist, hostString) != nil; } - (NSMutableArray *) _mutableSiteInfo { - NSMutableArray *hostWhitelist = [[[[NSUserDefaults standardUserDefaults] arrayForKey: sHostSiteInfoDefaultsKey] mutableCopy] autorelease]; + NSMutableArray *hostWhitelist = [[[[CTFUserDefaultsController standardUserDefaults] arrayForKey: sHostSiteInfoDefaultsKey] mutableCopy] autorelease]; if (hostWhitelist == nil) { hostWhitelist = [NSMutableArray array]; } @@ -177,7 +180,7 @@ - (void) _addHostToWhitelist { NSMutableArray *siteInfo = [self _mutableSiteInfo]; [siteInfo addObject: whitelistItemForSite([self host])]; - [[NSUserDefaults standardUserDefaults] setObject: siteInfo forKey: sHostSiteInfoDefaultsKey]; + [[CTFUserDefaultsController standardUserDefaults] setObject: siteInfo forKey: sHostSiteInfoDefaultsKey]; [[NSNotificationCenter defaultCenter] postNotificationName: sCTFWhitelistAdditionMade object: self]; } @@ -188,7 +191,7 @@ - (void) _removeHostFromWhitelist if(foundIndex != NSNotFound) { [siteInfo removeObjectAtIndex: foundIndex]; - [[NSUserDefaults standardUserDefaults] setObject: siteInfo forKey: sHostSiteInfoDefaultsKey]; + [[CTFUserDefaultsController standardUserDefaults] setObject: siteInfo forKey: sHostSiteInfoDefaultsKey]; } } diff --git a/Plugin/CTFsIFRSupport.m b/Plugin/CTFsIFRSupport.m index 5ded0e8e..4fdf9e31 100644 --- a/Plugin/CTFsIFRSupport.m +++ b/Plugin/CTFsIFRSupport.m @@ -26,6 +26,9 @@ of this software and associated documentation files (the "Software"), to deal #import "CTFsIFRSupport.h" +#import "CTFUserDefaultsController.h" +#import "CTFPreferencesDictionary.h" + typedef enum { CTFSifrModeDoNothing = 0, CTFSifrModeAutoLoadSifr = 1, @@ -61,7 +64,7 @@ - (NSUInteger) _sifrVersionInstalled - (BOOL) _shouldDeSIFR { - if ([[NSUserDefaults standardUserDefaults] integerForKey: sSifrModeDefaultsKey] == CTFSifrModeDeSifr) { + if ([[CTFUserDefaultsController standardUserDefaults] integerForKey: sSifrModeDefaultsKey] == CTFSifrModeDeSifr) { _sifrVersion = [self _sifrVersionInstalled]; if( _sifrVersion != 0 ) @@ -73,7 +76,7 @@ - (BOOL) _shouldDeSIFR - (BOOL) _shouldAutoLoadSIFR { - return [[NSUserDefaults standardUserDefaults] integerForKey: sSifrModeDefaultsKey] == CTFSifrModeAutoLoadSifr; + return [[CTFUserDefaultsController standardUserDefaults] integerForKey: sSifrModeDefaultsKey] == CTFSifrModeAutoLoadSifr; } - (void) _disableSIFR diff --git a/Plugin/English.lproj/WhitelistPanel.xib b/Plugin/English.lproj/WhitelistPanel.xib index 69e78494..ff606c66 100755 --- a/Plugin/English.lproj/WhitelistPanel.xib +++ b/Plugin/English.lproj/WhitelistPanel.xib @@ -8,7 +8,6 @@ 353.00 YES - YES @@ -65,12 +64,14 @@ 4352 {485, 151} + YES 256 {485, 17} + @@ -78,6 +79,7 @@ -2147483392 {{-26, 0}, {16, 17}} + YES @@ -163,6 +165,7 @@ {{1, 17}, {485, 151}} + @@ -173,6 +176,7 @@ -2147483392 {{471, 17}, {15, 152}} + _doScroller: 3.700000e+01 @@ -183,6 +187,7 @@ 256 {{-100, -100}, {450, 15}} + 1 _doScroller: @@ -197,6 +202,7 @@ {{1, 0}, {485, 17}} + @@ -206,6 +212,7 @@ {{20, 58}, {487, 169}} + 530 @@ -220,6 +227,7 @@ 292 {{48, 30}, {29, 26}} + YES 67239424 @@ -244,6 +252,7 @@ 292 {{20, 30}, {29, 26}} + YES 67239424 @@ -264,6 +273,7 @@ 289 {{227, 31}, {283, 17}} + YES 67239424 @@ -290,6 +300,7 @@ 268 {{93, 149}, {286, 18}} + YES -2080244224 @@ -321,6 +332,7 @@ 268 {{93, 129}, {286, 18}} + YES -2080244224 @@ -343,6 +355,7 @@ 268 {{17, 170}, {67, 17}} + YES 68288064 @@ -359,6 +372,7 @@ 268 {{93, 58}, {285, 58}} + YES 3 1 @@ -630,6 +644,7 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA 268 {{17, 99}, {67, 17}} + YES 68288064 @@ -646,6 +661,7 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA 268 {{17, 28}, {67, 17}} + YES 68288064 @@ -662,6 +678,7 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA 268 {{93, 27}, {287, 18}} + YES -2080244224 @@ -684,6 +701,7 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA 268 {{117, -3}, {86, 28}} + YES 67239424 @@ -704,6 +722,7 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA 268 {{93, 169}, {286, 18}} + YES -2080244224 @@ -724,6 +743,7 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA {{65, 235}, {397, 207}} + NSView @@ -731,6 +751,7 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA 289 {{471, 9}, {39, 14}} + YES 68288064 @@ -745,6 +766,7 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA {527, 438} + {{0, 0}, {1280, 778}} {420, 372} @@ -770,6 +792,15 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA YES + + YES + pluginEnabled + useYouTubeH264 + autoLoadInvisibleViews + sifrMode + checkForUpdatesOnFirstLoad + siteInfo + YES @@ -808,38 +839,6 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA 24 - - - value: values.ClickToFlash_useYouTubeH264 - - - - - - value: values.ClickToFlash_useYouTubeH264 - value - values.ClickToFlash_useYouTubeH264 - 2 - - - 48 - - - - selectedTag: values.ClickToFlash_sifrMode - - - - - - selectedTag: values.ClickToFlash_sifrMode - selectedTag - values.ClickToFlash_sifrMode - 2 - - - 112 - add: @@ -848,26 +847,6 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA 115 - - - contentArray: values.ClickToFlash_siteInfo - - - - - - contentArray: values.ClickToFlash_siteInfo - contentArray - values.ClickToFlash_siteInfo - - NSHandlesContentAsCompoundValue - - - 2 - - - 127 - value: arrangedObjects.site @@ -897,22 +876,6 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA 130 - - - value: values.ClickToFlash_autoLoadInvisibleViews - - - - - - value: values.ClickToFlash_autoLoadInvisibleViews - value - values.ClickToFlash_autoLoadInvisibleViews - 2 - - - 136 - checkForUpdates: @@ -921,22 +884,6 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA 146 - - - value: values.ClickToFlash_checkForUpdatesOnFirstLoad - - - - - - value: values.ClickToFlash_checkForUpdatesOnFirstLoad - value - values.ClickToFlash_checkForUpdatesOnFirstLoad - 2 - - - 147 - _checkNowButton @@ -967,19 +914,103 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA - value: values.ClickToFlash_pluginEnabled + value: values.pluginEnabled - value: values.ClickToFlash_pluginEnabled + value: values.pluginEnabled value - values.ClickToFlash_pluginEnabled + values.pluginEnabled + 2 + + + 178 + + + + value: values.useYouTubeH264 + + + + + + value: values.useYouTubeH264 + value + values.useYouTubeH264 + 2 + + + 179 + + + + value: values.autoLoadInvisibleViews + + + + + + value: values.autoLoadInvisibleViews + value + values.autoLoadInvisibleViews + 2 + + + 180 + + + + selectedTag: values.sifrMode + + + + + + selectedTag: values.sifrMode + selectedTag + values.sifrMode + 2 + + + 181 + + + + value: values.checkForUpdatesOnFirstLoad + + + + + + value: values.checkForUpdatesOnFirstLoad + value + values.checkForUpdatesOnFirstLoad + 2 + + + 182 + + + + contentArray: values.siteInfo + + + + + + contentArray: values.siteInfo + contentArray + values.siteInfo + + NSHandlesContentAsCompoundValue + + 2 - 171 + 183 @@ -1393,10 +1424,10 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA com.apple.InterfaceBuilder.CocoaPlugin {{40, 279}, {527, 438}} - + {196, 240} {{202, 428}, {480, 270}} - + {420, 350} com.apple.InterfaceBuilder.CocoaPlugin @@ -1516,7 +1547,7 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA - 172 + 183 diff --git a/Plugin/Plugin.h b/Plugin/Plugin.h index 7c663ddb..1fc9e339 100755 --- a/Plugin/Plugin.h +++ b/Plugin/Plugin.h @@ -52,6 +52,7 @@ THE SOFTWARE. + (NSView *)plugInViewWithArguments:(NSDictionary *)arguments; - (id) initWithArguments:(NSDictionary *)arguments; +- (void)_migratePrefsToExternalFile; - (DOMElement *)container; - (void)setContainer:(DOMElement *)newValue; diff --git a/Plugin/Plugin.m b/Plugin/Plugin.m index 937694ae..b16465fd 100755 --- a/Plugin/Plugin.m +++ b/Plugin/Plugin.m @@ -25,6 +25,8 @@ of this software and associated documentation files (the "Software"), to deal */ #import "Plugin.h" +#import "CTFUserDefaultsController.h" +#import "CTFPreferencesDictionary.h" #import "MATrackingArea.h" #import "CTFMenubarMenuController.h" @@ -40,10 +42,10 @@ of this software and associated documentation files (the "Software"), to deal static NSString *sFlashOldMIMEType = @"application/x-shockwave-flash"; static NSString *sFlashNewMIMEType = @"application/futuresplash"; - // NSUserDefaults keys -static NSString *sUseYouTubeH264DefaultsKey = @"ClickToFlash_useYouTubeH264"; -static NSString *sAutoLoadInvisibleFlashViewsKey = @"ClickToFlash_autoLoadInvisibleViews"; -static NSString *sPluginEnabled = @"ClickToFlash_pluginEnabled"; + // CTFUserDefaultsController keys +static NSString *sUseYouTubeH264DefaultsKey = @"useYouTubeH264"; +static NSString *sAutoLoadInvisibleFlashViewsKey = @"autoLoadInvisibleViews"; +static NSString *sPluginEnabled = @"pluginEnabled"; BOOL usingMATrackingArea = NO; @@ -100,24 +102,24 @@ + (NSView *)plugInViewWithArguments:(NSDictionary *)arguments - (id) initWithArguments:(NSDictionary *)arguments { self = [super init]; - if (self) { + if (self) { [[NSUserDefaults standardUserDefaults] addSuiteNamed:@"com.github.rentzsch.clicktoflash"]; - + NSLog(@"ummmm0"); SparkleManager *sharedSparkleManager = [SparkleManager sharedManager]; NSWorkspace *sharedWorkspace = [NSWorkspace sharedWorkspace]; NSString *pathToRelaunch = [sharedWorkspace absolutePathForAppBundleWithIdentifier:[self launchedAppBundleIdentifier]]; [sharedSparkleManager setPathToRelaunch:pathToRelaunch]; [sharedSparkleManager startAutomaticallyCheckingForUpdates]; - - if (![[NSUserDefaults standardUserDefaults] objectForKey:sAutoLoadInvisibleFlashViewsKey]) { + NSLog(@"ummmm"); + if (![[CTFUserDefaultsController standardUserDefaults] objectForKey:sAutoLoadInvisibleFlashViewsKey]) { // Default to auto-loading invisible flash views. - [[NSUserDefaults standardUserDefaults] setBool:YES forKey:sAutoLoadInvisibleFlashViewsKey]; + [[CTFUserDefaultsController standardUserDefaults] setBool:YES forKey:sAutoLoadInvisibleFlashViewsKey]; } - if (![[NSUserDefaults standardUserDefaults] objectForKey:sPluginEnabled]) { + if (![[CTFUserDefaultsController standardUserDefaults] objectForKey:sPluginEnabled]) { // Default to enable the plugin - [[NSUserDefaults standardUserDefaults] setBool:YES forKey:sPluginEnabled]; + [[CTFUserDefaultsController standardUserDefaults] setBool:YES forKey:sPluginEnabled]; } - + NSLog(@"ummmm2"); [self setLaunchedAppBundleIdentifier:[self launchedAppBundleIdentifier]]; [self setWebView:[[[arguments objectForKey:WebPlugInContainerKey] webFrame] webView]]; @@ -125,6 +127,7 @@ - (id) initWithArguments:(NSDictionary *)arguments [self setContainer:[arguments objectForKey:WebPlugInContainingElementKey]]; [self _migrateWhitelist]; + [self _migratePrefsToExternalFile]; // Get URL @@ -189,7 +192,7 @@ - (id) initWithArguments:(NSDictionary *)arguments // check whether plugin is disabled, load all content as normal if so - if ( ![ [ NSUserDefaults standardUserDefaults ] boolForKey: sPluginEnabled ] ) { + if ( ![ [ CTFUserDefaultsController standardUserDefaults ] boolForKey: sPluginEnabled ] ) { _isLoadingFromWhitelist = YES; [self _convertTypesForContainer]; return self; @@ -218,7 +221,7 @@ - (id) initWithArguments:(NSDictionary *)arguments } } - if ( [ [ NSUserDefaults standardUserDefaults ] boolForKey: sAutoLoadInvisibleFlashViewsKey ] + if ( [ [ CTFUserDefaultsController standardUserDefaults ] boolForKey: sAutoLoadInvisibleFlashViewsKey ] && [ self isConsideredInvisible ] ) { // auto-loading is on and this view meets the size constraints _isLoadingFromWhitelist = YES; @@ -358,6 +361,38 @@ - (void) dealloc [super dealloc]; } +- (void)_migratePrefsToExternalFile +{ + NSArray *parasiticDefaultsNameArray = [NSArray arrayWithObjects:@"ClickToFlash_pluginEnabled", + @"ClickToFlash_useYouTubeH264", + @"ClickToFlash_autoLoadInvisibleViews", + @"ClickToFlash_sifrMode", + @"ClickToFlash_checkForUpdatesOnFirstLoad", + @"ClickToFlash_siteInfo", + nil]; + + NSArray *externalDefaultsNameArray = [NSArray arrayWithObjects:@"pluginEnabled", + @"useYouTubeH264", + @"autoLoadInvisibleViews", + @"sifrMode", + @"checkForUpdatesOnFirstLoad", + @"siteInfo", + nil]; + + NSMutableDictionary *externalFileDefaults = [[CTFUserDefaultsController standardUserDefaults] dictionaryRepresentation]; + + unsigned int i; + for (i = 0; i < [parasiticDefaultsNameArray count]; i++) { + NSString *currentParasiticDefault = [parasiticDefaultsNameArray objectAtIndex:i]; + NSLog(@"sending objectForKey: to a CTFUserDefaultsController"); + id prefValue = [[NSUserDefaults standardUserDefaults] objectForKey:currentParasiticDefault]; + if (prefValue) { + [externalFileDefaults setObject:prefValue forKey:[externalDefaultsNameArray objectAtIndex:i]]; + [[NSUserDefaults standardUserDefaults] removeObjectForKey:currentParasiticDefault]; + } + } +} + - (void) drawRect:(NSRect)rect { if(!_isLoadingFromWhitelist) @@ -896,8 +931,8 @@ - (BOOL) _hasH264Version - (BOOL) _useH264Version { return [ self _hasH264Version ] - && [ [ NSUserDefaults standardUserDefaults ] boolForKey: sUseYouTubeH264DefaultsKey ] - && [ [ NSUserDefaults standardUserDefaults ] boolForKey: sPluginEnabled ]; + && [ [ CTFUserDefaultsController standardUserDefaults ] boolForKey: sUseYouTubeH264DefaultsKey ] + && [ [ CTFUserDefaultsController standardUserDefaults ] boolForKey: sPluginEnabled ]; } - (void) _convertElementForMP4: (DOMElement*) element diff --git a/SparkleManager.m b/SparkleManager.m index 87c784f7..381402a1 100644 --- a/SparkleManager.m +++ b/SparkleManager.m @@ -27,6 +27,9 @@ of this software and associated documentation files (the "Software"), to deal #import "SparkleManager.h" #import +#import "CTFUserDefaultsController.h" +#import "CTFPreferencesDictionary.h" + // NSUserDefaults keys static NSString *sAutomaticallyCheckForUpdates = @"ClickToFlash_checkForUpdatesOnFirstLoad"; @@ -99,11 +102,11 @@ - (SUUpdater*)_updater { } - (void)startAutomaticallyCheckingForUpdates { - if (![[NSUserDefaults standardUserDefaults] objectForKey:sAutomaticallyCheckForUpdates]) { + if (![[CTFUserDefaultsController standardUserDefaults] objectForKey:sAutomaticallyCheckForUpdates]) { // If the key isn't set yet, default to YES, automatically check for updates. - [[NSUserDefaults standardUserDefaults] setBool:YES forKey:sAutomaticallyCheckForUpdates]; + [[CTFUserDefaultsController standardUserDefaults] setBool:YES forKey:sAutomaticallyCheckForUpdates]; } - if ([[NSUserDefaults standardUserDefaults] boolForKey:sAutomaticallyCheckForUpdates]) { + if ([[CTFUserDefaultsController standardUserDefaults] boolForKey:sAutomaticallyCheckForUpdates]) { static BOOL checkedForUpdate = NO; if (!checkedForUpdate) { checkedForUpdate = YES;