浏览代码

[2.8.2] Fix keep settings code

DSR! 3 年之前
父节点
当前提交
8bee191e0a
共有 2 个文件被更改,包括 42 次插入49 次删除
  1. 34 46
      src/pineapple/api/Setup.php
  2. 8 3
      src/pineapple/modules/Setup/js/module.js

+ 34 - 46
src/pineapple/api/Setup.php

@@ -2,14 +2,27 @@
 
 class Setup extends APIModule
 {
-    public function __construct($request)
+    public function route()
     {
-        Parent::__construct($request);
-
-        # Disable setup in "keep settings" scenario
-        $count = explode("\n", exec('ls "/etc/pineapple" | wc -l'))[0];
-        if (intval($count) > 13) {
-            exec('/bin/rm -rf /pineapple/modules/Setup /pineapple/api/Setup.php /etc/pineapple/setupRequired');
+        @session_write_close();
+        if (file_exists('/etc/pineapple/setupRequired')) {
+            switch ($this->request->action) {
+                case 'checkButtonStatus':
+                    $this->checkButtonStatus();
+                    break;
+                case 'getChanges':
+                    $this->getChanges();
+                    break;
+                case 'getDeviceData':
+                    $this->getDeviceData();
+                    break;
+                case 'populateFields':
+                    $this->populateFields();
+                    break;
+                case 'performSetup':
+                    $this->performSetup();
+                    break;
+            }
         }
     }
 
@@ -35,15 +48,10 @@ class Setup extends APIModule
 
     private function checkButtonStatus()
     {
-        $buttonPressed = false;
-        $bootStatus = false;
-        if (file_exists('/tmp/button_setup')) {
-            $buttonPressed = true;
-        }
-        if (!file_exists('/etc/pineapple/init')) {
-            $bootStatus = true;
-        }
+        $buttonPressed = file_exists('/tmp/button_setup');
+        $bootStatus = !file_exists('/etc/pineapple/init');
         $this->response = array('buttonPressed' => $buttonPressed, 'booted' => $bootStatus);
+
         return $buttonPressed;
     }
 
@@ -59,15 +67,18 @@ class Setup extends APIModule
         return true;
     }
 
-    private function getDeviceName()
+    private function getDeviceData()
     {
-        $device = \helper\getDevice();
-        if ($device == 'tetra') {
-            $this->response = array('device' => "tetra");
-        } elseif ($device == 'nano') {
-            $this->response = array('device' => "nano");
+        # Disable setup in "keep settings" scenario
+        $complete = file_exists('/etc/pineapple/setup_complete');
+        if ($complete) {
+            exec('/bin/rm -rf /pineapple/modules/Setup /pineapple/api/Setup.php /etc/pineapple/setupRequired /etc/pineapple/init');
         }
-        return true;
+
+        $this->response = array(
+            'complete' => $complete,
+            'device'   => \helper\getDevice(),
+        );
     }
 
     private function populateFields()
@@ -189,6 +200,7 @@ class Setup extends APIModule
         exec('killall blink');
         exec('led reset');
         exec('/bin/rm -rf /pineapple/modules/Setup');
+        exec('/bin/touch /etc/pineapple/setup_complete');
     }
 
     public function performSetup()
@@ -222,28 +234,4 @@ class Setup extends APIModule
 
         return true;
     }
-
-    public function route()
-    {
-        @session_write_close();
-        if (file_exists('/etc/pineapple/setupRequired')) {
-            switch ($this->request->action) {
-                case 'checkButtonStatus':
-                    $this->checkButtonStatus();
-                    break;
-                case 'getChanges':
-                    $this->getChanges();
-                    break;
-                case 'getDeviceName':
-                    $this->getDeviceName();
-                    break;
-                case 'populateFields':
-                    $this->populateFields();
-                    break;
-                case 'performSetup':
-                    $this->performSetup();
-                    break;
-            }
-        }
-    }
 }

+ 8 - 3
src/pineapple/modules/Setup/js/module.js

@@ -132,15 +132,20 @@ registerController('SetupController', ['$api', '$scope', '$interval', '$timeout'
         { value: 'VN', country: "Vietnam" }
     ];
 
-    $scope.getDeviceName = function(){
+    $scope.getDeviceData = function(){
         $api.request({
             system: 'setup',
-            action: 'getDeviceName'
+            action: 'getDeviceData'
         }, function(response) {
             $scope.device = response.device;
+            if (response.complete) {
+                $scope.complete = true;
+                $("#loginModal").remove();
+                window.location = '/';
+            }
         });
     };
-    $scope.getDeviceName();
+    $scope.getDeviceData();
 
     $scope.doSetup = function(){
         $scope.error = '';