Skip to content

Commit

Permalink
Dynamically change theme css
Browse files Browse the repository at this point in the history
  • Loading branch information
jtremolo committed Aug 19, 2020
1 parent 4241d2a commit b28b002
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
1 change: 1 addition & 0 deletions web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@

<link rel="stylesheet" href="css/main.css" />
<link rel="stylesheet" href="css/ahrs.css" />
<link rel="stylesheet" id="themeStylesheet" href="" />

<script src="maui/js/angular.min.js"></script>
<script src="maui/js/angular-ui-router.min.js"></script>
Expand Down
16 changes: 16 additions & 0 deletions web/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,23 @@ app.controller('MainCtrl', function ($scope, $http) {
.then(function(response) {
var settings = angular.fromJson(response.data);
$scope.DeveloperMode = settings.DeveloperMode;

// Update theme
$scope.updateTheme(settings.DarkMode);
}, function(response) {
//Second function handles error
});

$scope.updateTheme = function(darkMode) {
if(darkMode != $scope.DarkMode) {
// console.log("Updating theme, use dark mode?", darkMode);
$scope.DarkMode = darkMode;

if($scope.DarkMode) {
document.getElementById('themeStylesheet').href = 'css/dark-mode.css';
} else {
document.getElementById('themeStylesheet').href = '';
}
}
};
});
8 changes: 7 additions & 1 deletion web/plates/js/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function SettingsCtrl($rootScope, $scope, $state, $location, $window, $http) {
$scope.$parent.helppage = 'plates/settings-help.html';

var toggles = ['UAT_Enabled', 'ES_Enabled', 'Ping_Enabled', 'GPS_Enabled', 'IMU_Sensor_Enabled',
'BMP_Sensor_Enabled', 'DisplayTrafficSource', 'DEBUG', 'ReplayLog', 'AHRSLog'];
'BMP_Sensor_Enabled', 'DisplayTrafficSource', 'DEBUG', 'ReplayLog', 'AHRSLog', 'DarkMode'];
var settings = {};
for (var i = 0; i < toggles.length; i++) {
settings[toggles[i]] = undefined;
Expand All @@ -24,6 +24,9 @@ function SettingsCtrl($rootScope, $scope, $state, $location, $window, $http) {
$scope.Baud = settings.SerialOutputs['/dev/serialout0'].Baud;
$scope.visible_serialout = true;
}

$scope.DarkMode = settings.DarkMode;

$scope.UAT_Enabled = settings.UAT_Enabled;
$scope.ES_Enabled = settings.ES_Enabled;
$scope.Ping_Enabled = settings.Ping_Enabled;
Expand All @@ -50,6 +53,9 @@ function SettingsCtrl($rootScope, $scope, $state, $location, $window, $http) {
$scope.WiFiSmartEnabled = settings.WiFiSmartEnabled;

$scope.Channels = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11];

// Update theme
$scope.$parent.updateTheme($scope.DarkMode);
}

function getSettings() {
Expand Down

0 comments on commit b28b002

Please sign in to comment.