[vlc-commits] macosx: correctly reset interface preferences when requested

David Fuhrmann git at videolan.org
Thu Nov 21 02:00:35 CET 2013


vlc | branch: master | David Fuhrmann <david.fuhrmann at googlemail.com> | Thu Nov 21 01:58:56 2013 +0100| [f88d16b248d051d1366d4097df97ee00a1129997] | committer: David Fuhrmann

macosx: correctly reset interface preferences when requested

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=f88d16b248d051d1366d4097df97ee00a1129997
---

 modules/gui/macosx/intf.h         |    3 +++
 modules/gui/macosx/intf.m         |   22 +++++++++++++++++-----
 modules/gui/macosx/simple_prefs.m |    3 +--
 3 files changed, 21 insertions(+), 7 deletions(-)

diff --git a/modules/gui/macosx/intf.h b/modules/gui/macosx/intf.h
index 730b7a8..f75de5a 100644
--- a/modules/gui/macosx/intf.h
+++ b/modules/gui/macosx/intf.h
@@ -180,6 +180,9 @@ struct intf_sys_t
 - (void)updateTogglePlaylistState;
 
 - (void)mediaKeyTap:(SPMediaKeyTap*)keyTap receivedMediaKeyEvent:(NSEvent*)event;
+
+- (void)resetAndReinitializeUserDefaults;
+
 @end
 
 
diff --git a/modules/gui/macosx/intf.m b/modules/gui/macosx/intf.m
index d836a8d..d990c8a 100644
--- a/modules/gui/macosx/intf.m
+++ b/modules/gui/macosx/intf.m
@@ -1685,10 +1685,24 @@ static VLCMain *_o_sharedMainInstance = nil;
 #pragma mark -
 #pragma mark Remove old prefs
 
+
+static NSString * kVLCPreferencesVersion = @"VLCPreferencesVersion";
+static const int kCurrentPreferencesVersion = 3;
+
+- (void)resetAndReinitializeUserDefaults
+{
+    // note that [NSUserDefaults resetStandardUserDefaults] will NOT correctly reset to the defaults
+
+    NSString *appDomain = [[NSBundle mainBundle] bundleIdentifier];
+    [[NSUserDefaults standardUserDefaults] removePersistentDomainForName:appDomain];
+
+    // set correct version to avoid question about outdated config
+    [[NSUserDefaults standardUserDefaults] setInteger:kCurrentPreferencesVersion forKey:kVLCPreferencesVersion];
+    [[NSUserDefaults standardUserDefaults] synchronize];
+}
+
 - (void)removeOldPreferences
 {
-    static NSString * kVLCPreferencesVersion = @"VLCPreferencesVersion";
-    static const int kCurrentPreferencesVersion = 3;
     NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];
     int version = [defaults integerForKey:kVLCPreferencesVersion];
     if (version >= kCurrentPreferencesVersion)
@@ -1705,10 +1719,8 @@ static VLCMain *_o_sharedMainInstance = nil;
     } else if (version == 2) {
         /* version 2 (used by VLC 2.0.x and early versions of 2.1) can lead to exceptions within 2.1 or later
          * so we reset the OS X specific prefs here - in practice, no user will notice */
-        [NSUserDefaults resetStandardUserDefaults];
+        [self resetAndReinitializeUserDefaults];
 
-        [defaults setInteger:kCurrentPreferencesVersion forKey:kVLCPreferencesVersion];
-        [defaults synchronize];
     } else {
         NSArray *libraries = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory,
             NSUserDomainMask, YES);
diff --git a/modules/gui/macosx/simple_prefs.m b/modules/gui/macosx/simple_prefs.m
index 41f8c0a..9ed9d91 100644
--- a/modules/gui/macosx/simple_prefs.m
+++ b/modules/gui/macosx/simple_prefs.m
@@ -861,8 +861,7 @@ static inline char * __config_GetLabel(vlc_object_t *p_this, const char *psz_nam
         config_SaveConfigFile(p_intf);
 
         /* reset OS X defaults */
-        [NSUserDefaults resetStandardUserDefaults];
-        [[NSUserDefaults standardUserDefaults] synchronize];
+        [[VLCMain sharedInstance] resetAndReinitializeUserDefaults];
 
         /* Relaunch now */
         const char * path = [[[NSBundle mainBundle] executablePath] UTF8String];



More information about the vlc-commits mailing list