Refactor Toggle Dark mode

This commit is contained in:
Jokob-sk
2023-01-16 23:56:19 +11:00
parent 8ef6f420e4
commit fef33d652d
15 changed files with 70 additions and 111 deletions

View File

@@ -70,11 +70,6 @@ function OpenDB (...$DBPath) {
$db->exec('PRAGMA journal_mode = wal;');
}
function CommitDB () {
global $db;
// $db->commit();
}
// # Open DB once and keep open
// # Opening / closing DB frequently actually casues more issues

View File

@@ -41,9 +41,7 @@
case 'deleteDeviceEvents': deleteDeviceEvents(); break;
case 'PiaBackupDBtoArchive': PiaBackupDBtoArchive(); break;
case 'PiaRestoreDBfromArchive': PiaRestoreDBfromArchive(); break;
case 'PiaPurgeDBBackups': PiaPurgeDBBackups(); break;
case 'PiaEnableDarkmode': PiaEnableDarkmode(); break;
case 'PiaToggleArpScan': PiaToggleArpScan(); break;
case 'PiaPurgeDBBackups': PiaPurgeDBBackups(); break;
case 'ExportCSV': ExportCSV(); break;
case 'ImportCSV': ImportCSV(); break;
@@ -66,7 +64,7 @@
}
}
CommitDB();
//------------------------------------------------------------------------------
// Query Device Data
@@ -527,28 +525,8 @@ function ImportCSV() {
echo lang('BackDevices_DBTools_ImportCSVMissing');
}
CommitDB();
}
//------------------------------------------------------------------------------
// Toggle Dark/Light Themes
//------------------------------------------------------------------------------
function PiaEnableDarkmode() {
$file = '../../../db/setting_darkmode';
if (file_exists($file)) {
echo lang('BackDevices_darkmode_disabled');
unlink($file);
echo("<meta http-equiv='refresh' content='1'>");
} else {
echo lang('BackDevices_darkmode_enabled');
$darkmode = fopen($file, 'w');
echo("<meta http-equiv='refresh' content='1'>");
}
}
//------------------------------------------------------------------------------
// Query total numbers of Devices by status
//------------------------------------------------------------------------------

View File

@@ -22,16 +22,21 @@
ini_set ('max_execution_time','15');
$skipCache = FALSE;
$defaultValue = '';
if (isset ($_REQUEST['skipcache'])) {
$skipCache = TRUE;
}
if (isset ($_REQUEST['defaultValue'])) {
$defaultValue = $_REQUEST['defaultValue'];
}
// Action functions
if (isset ($_REQUEST['action']) && !empty ($_REQUEST['action'])) {
$action = $_REQUEST['action'];
switch ($action) {
case 'get': getParameter($skipCache); break;
case 'get': getParameter($skipCache, $defaultValue); break;
case 'set': setParameter(); break;
default: logServerConsole ('Action: '. $action); break;
}
@@ -41,18 +46,19 @@
//------------------------------------------------------------------------------
// Get Parameter Value
//------------------------------------------------------------------------------
function getParameter($skipCache) {
function getParameter($skipCache, $defaultValue) {
$parameter = $_REQUEST['parameter'];
$value = "";
// get the value from the cookie if available
if(getCache($parameter) != "")
// get the value from the cache if available
$cachedValue = getCache($parameter);
if($cachedValue != "")
{
$value = getCache($parameter);
$value = $cachedValue;
}
// query the database if no cache entry found or requesting live data for the Back_App_State in the header
// query the database if no cache entry found or requesting live data (skipping cache)
if($skipCache || $value == "" )
{
global $db;
@@ -62,12 +68,15 @@ function getParameter($skipCache) {
$result = $db->query($sql);
$row = $result -> fetchArray (SQLITE3_NUM);
$value = $row[0];
// Commit DB
CommitDB();
if($row != NULL && count($row) == 1)
{
$value = $row[0];
} else{
$value = $defaultValue;
}
// update cookie cache
// update cache
setCache($parameter, $value);
}
// return value
@@ -109,10 +118,7 @@ function setParameter() {
}
}
// Commit DB
CommitDB();
// update cookie cache
// update cache
setCache($parameter, $value);
echo 'OK';

View File

@@ -9,7 +9,7 @@
//------------------------------------------------------------------------------
require '/home/pi/pialert/front/php/templates/timezone.php';
require '/home/pi/pialert/front/php/templates/skinUI.php';
require '/home/pi/pialert/front/php/templates/language/lang.php';
$FUNCTION = [];
$SETTINGS = [];