[vlc-commits] macosx: refactor preferences reset and restart code

Felix Paul Kühne git at videolan.org
Tue Jul 16 12:10:55 CEST 2019


vlc | branch: master | Felix Paul Kühne <felix at feepk.net> | Tue Jul 16 12:09:53 2019 +0200| [ad8a01497b38d636fa8808a7fac615d6f0f69c87] | committer: Felix Paul Kühne

macosx: refactor preferences reset and restart code

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

 modules/gui/macosx/main/VLCMain+OldPrefs.h         |  4 +++-
 modules/gui/macosx/main/VLCMain+OldPrefs.m         | 23 ++++++++++++++--------
 modules/gui/macosx/main/VLCMain.h                  |  1 +
 modules/gui/macosx/main/VLCMain.m                  | 11 +++++++++++
 .../macosx/preferences/VLCSimplePrefsController.m  | 20 +------------------
 5 files changed, 31 insertions(+), 28 deletions(-)

diff --git a/modules/gui/macosx/main/VLCMain+OldPrefs.h b/modules/gui/macosx/main/VLCMain+OldPrefs.h
index 3cdeaa22c2..3eae71713d 100644
--- a/modules/gui/macosx/main/VLCMain+OldPrefs.h
+++ b/modules/gui/macosx/main/VLCMain+OldPrefs.h
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * intf-prefs.h
  *****************************************************************************
- * Copyright (C) 2001-2015 VLC authors and VideoLAN
+ * Copyright (C) 2001-2019 VLC authors and VideoLAN
  *
  * Authors: Felix Paul Kühne <fkuehne at videolan dot org>
  *
@@ -27,4 +27,6 @@
 - (void)resetAndReinitializeUserDefaults;
 - (void)migrateOldPreferences;
 
+- (void)resetPreferences;
+
 @end
diff --git a/modules/gui/macosx/main/VLCMain+OldPrefs.m b/modules/gui/macosx/main/VLCMain+OldPrefs.m
index 6860b254a6..ec4027686d 100644
--- a/modules/gui/macosx/main/VLCMain+OldPrefs.m
+++ b/modules/gui/macosx/main/VLCMain+OldPrefs.m
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * intf-prefs.m
  *****************************************************************************
- * Copyright (C) 2001-2015 VLC authors and VideoLAN
+ * Copyright (C) 2001-2019 VLC authors and VideoLAN
  *
  * Authors: Pierre d'Herbemont <pdherbemont # videolan org>
  *          Felix Paul Kühne <fkuehne at videolan dot org>
@@ -133,14 +133,21 @@ static const int kCurrentPreferencesVersion = 4;
         [self resetAndReinitializeUserDefaults];
     }
 
-    /* Relaunch now */
-    const char * path = [[[NSBundle mainBundle] executablePath] UTF8String];
+    [VLCMain relaunchApplication];
+}
 
-    /* For some reason we need to fork(), not just execl(), which reports a ENOTSUP then. */
-    if (fork() != 0) {
-        exit(0);
-    }
-    execl(path, path, (char *)NULL);
+- (void)resetPreferences
+{
+    /* reset VLC's config */
+    config_ResetAll();
+
+    /* force config file creation, since libvlc won't exit normally */
+    config_SaveConfigFile(getIntf());
+
+    /* reset OS X defaults */
+    [self resetAndReinitializeUserDefaults];
+
+    [VLCMain relaunchApplication];
 }
 
 @end
diff --git a/modules/gui/macosx/main/VLCMain.h b/modules/gui/macosx/main/VLCMain.h
index 0a9a7d2c66..1e38fdd8cd 100644
--- a/modules/gui/macosx/main/VLCMain.h
+++ b/modules/gui/macosx/main/VLCMain.h
@@ -65,6 +65,7 @@ extern NSString *VLCConfigurationChangedNotification;
 @interface VLCMain : NSObject
 
 + (VLCMain *)sharedInstance;
++ (void)relaunchApplication;
 
 @property (readonly) BOOL isTerminating;
 
diff --git a/modules/gui/macosx/main/VLCMain.m b/modules/gui/macosx/main/VLCMain.m
index e8c4497eed..dff44584ff 100644
--- a/modules/gui/macosx/main/VLCMain.m
+++ b/modules/gui/macosx/main/VLCMain.m
@@ -210,6 +210,17 @@ static VLCMain *sharedInstance = nil;
     sharedInstance = nil;
 }
 
++ (void)relaunchApplication
+{
+    const char *path = [[[NSBundle mainBundle] executablePath] UTF8String];
+
+    /* For some reason we need to fork(), not just execl(), which reports a ENOTSUP then. */
+    if (fork() != 0) {
+        exit(0);
+    }
+    execl(path, path, (char *)NULL);
+}
+
 - (id)init
 {
     self = [super init];
diff --git a/modules/gui/macosx/preferences/VLCSimplePrefsController.m b/modules/gui/macosx/preferences/VLCSimplePrefsController.m
index 482a886325..c183a7b72d 100644
--- a/modules/gui/macosx/preferences/VLCSimplePrefsController.m
+++ b/modules/gui/macosx/preferences/VLCSimplePrefsController.m
@@ -908,25 +908,7 @@ static inline const char * __config_GetLabel(vlc_object_t *p_this, const char *p
     [alert addButtonWithTitle:_NS("Continue")];
     [alert beginSheetModalForWindow:[sender window] completionHandler:^(NSModalResponse returnCode) {
         if (returnCode == NSAlertSecondButtonReturn) {
-            /* reset VLC's config */
-            config_ResetAll();
-            [self resetControls];
-
-            /* force config file creation, since libvlc won't exit normally */
-            config_SaveConfigFile(self->p_intf);
-
-            /* reset OS X defaults */
-            [[VLCMain sharedInstance] resetAndReinitializeUserDefaults];
-
-            /* Relaunch now */
-            const char * path = [[[NSBundle mainBundle] executablePath] UTF8String];
-
-            /* For some reason we need to fork(), not just execl(), which reports a ENOTSUP then. */
-            if (fork() != 0) {
-                exit(0);
-                return;
-            }
-            execl(path, path, (char *)NULL);
+            [[VLCMain sharedInstance] resetPreferences];
         }
     }];
 }



More information about the vlc-commits mailing list