2022-10-02 12:19:20 +03:00
|
|
|
$(document).ready(async function() {
|
|
|
|
const $startupSwitch = $("#settings_startupSwitch");
|
|
|
|
const $startupSwitchTogglerName = $("#settings_startupTogglerName");
|
|
|
|
|
|
|
|
const $wallpaperSwitch = $("#settings_autoSetWallpaperSwitch");
|
|
|
|
const $wallpaperSwitchTogglerName = $("#settings_autoSetWallpaperTogglerName");
|
|
|
|
|
2022-11-21 22:22:00 +03:00
|
|
|
const $loggingSwitch = $("#settings_saveLoggSwitch");
|
|
|
|
const $loggingSwitchTogglerName = $("#settings_saveLoggTogglerName");
|
|
|
|
|
|
|
|
getSettings().then((data) => {
|
2022-11-22 21:36:35 +03:00
|
|
|
if (data["wallpaper"] === 1) {
|
|
|
|
$wallpaperSwitch.attr("checked", "true");
|
|
|
|
$wallpaperSwitchTogglerName.text("On");
|
|
|
|
}
|
|
|
|
if (data["startup"] === 1) {
|
|
|
|
$startupSwitch.attr("checked", "true");
|
|
|
|
$startupSwitchTogglerName.text("On");
|
|
|
|
}
|
|
|
|
if (data["save_logg"] === 1) {
|
|
|
|
$loggingSwitch.attr("checked", "true");
|
|
|
|
$loggingSwitchTogglerName.text("On");
|
|
|
|
}
|
2022-09-18 19:27:23 +03:00
|
|
|
});
|
2022-09-19 16:55:29 +03:00
|
|
|
|
2023-03-18 16:49:24 +03:00
|
|
|
$wallpaperSwitch.click(async function () {
|
2022-10-09 12:03:38 +03:00
|
|
|
$.ajax({
|
2022-10-23 15:27:45 +03:00
|
|
|
url: "http://localhost:3000/api/get/settings",
|
2022-10-09 12:03:38 +03:00
|
|
|
type: "GET",
|
|
|
|
success: function (data) {
|
|
|
|
if (data["wallpaper"] === 1) {
|
|
|
|
$.ajax({
|
2022-10-23 15:27:45 +03:00
|
|
|
url: "http://localhost:3000/api/update/settings",
|
2022-10-09 12:03:38 +03:00
|
|
|
type: "POST",
|
|
|
|
data: {
|
|
|
|
"wallpaper": 0,
|
|
|
|
},
|
|
|
|
success: function (data) {
|
2023-03-18 16:49:24 +03:00
|
|
|
if (data["status"]) {
|
2022-10-09 12:03:38 +03:00
|
|
|
$wallpaperSwitchTogglerName.text("Off");
|
|
|
|
$wallpaperSwitch.removeAttr("checked");
|
|
|
|
|
|
|
|
toast(data.message);
|
|
|
|
} else {
|
|
|
|
toast("Failed to apply settings.");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
$.ajax({
|
2022-10-23 15:27:45 +03:00
|
|
|
url: "http://localhost:3000/api/update/settings",
|
2022-10-09 12:03:38 +03:00
|
|
|
type: "POST",
|
|
|
|
data: {
|
|
|
|
"wallpaper": 1,
|
|
|
|
},
|
|
|
|
success: function (data) {
|
2023-03-18 16:49:24 +03:00
|
|
|
if (data["status"]) {
|
2022-10-09 12:03:38 +03:00
|
|
|
$wallpaperSwitchTogglerName.text("On");
|
|
|
|
$wallpaperSwitch.attr("checked", "true");
|
|
|
|
|
|
|
|
toast(data.message);
|
|
|
|
} else {
|
|
|
|
toast("Failed to apply settings.");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|
2022-10-02 12:19:20 +03:00
|
|
|
}
|
2022-10-09 12:03:38 +03:00
|
|
|
},
|
|
|
|
})
|
2022-09-19 16:55:29 +03:00
|
|
|
});
|
2022-10-02 12:19:20 +03:00
|
|
|
|
2023-03-18 16:49:24 +03:00
|
|
|
$startupSwitch.click(async function () {
|
2022-10-02 12:19:20 +03:00
|
|
|
$.ajax({
|
2022-10-23 15:27:45 +03:00
|
|
|
url: "http://localhost:3000/api/get/settings",
|
2022-10-09 12:03:38 +03:00
|
|
|
type: "GET",
|
2022-10-02 12:19:20 +03:00
|
|
|
success: function (data) {
|
2022-10-09 12:03:38 +03:00
|
|
|
if (data["startup"] === 1) {
|
|
|
|
$.ajax({
|
2022-10-23 15:27:45 +03:00
|
|
|
url: "http://localhost:3000/api/update/settings",
|
2022-10-09 12:03:38 +03:00
|
|
|
type: "POST",
|
|
|
|
data: {
|
|
|
|
"startup": 0,
|
|
|
|
},
|
|
|
|
success: async function (data) {
|
|
|
|
if (data["status"]) {
|
|
|
|
await editStartup(0);
|
|
|
|
|
|
|
|
$startupSwitchTogglerName.text("Off");
|
|
|
|
$startupSwitch.removeAttr("checked");
|
|
|
|
|
|
|
|
toast(data.message);
|
|
|
|
} else {
|
|
|
|
toast("Failed to apply settings.");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|
2022-10-02 12:19:20 +03:00
|
|
|
} else {
|
2022-10-09 12:03:38 +03:00
|
|
|
$.ajax({
|
2022-10-23 15:27:45 +03:00
|
|
|
url: "http://localhost:3000/api/update/settings",
|
2022-10-09 12:03:38 +03:00
|
|
|
type: "POST",
|
|
|
|
data: {
|
|
|
|
"startup": 1,
|
|
|
|
},
|
|
|
|
success: async function (data) {
|
|
|
|
if (data["status"]) {
|
|
|
|
await editStartup(1);
|
|
|
|
|
|
|
|
$startupSwitchTogglerName.text("On");
|
|
|
|
$startupSwitch.attr("checked", "true");
|
|
|
|
toast(data.message);
|
|
|
|
} else {
|
|
|
|
toast("Failed to apply settings.");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|
2022-10-02 12:19:20 +03:00
|
|
|
}
|
2022-10-09 12:03:38 +03:00
|
|
|
},
|
2022-10-02 12:19:20 +03:00
|
|
|
});
|
|
|
|
});
|
2022-11-21 22:22:00 +03:00
|
|
|
|
2023-03-18 16:49:24 +03:00
|
|
|
$loggingSwitch.click(async function () {
|
2022-11-21 22:22:00 +03:00
|
|
|
$.ajax({
|
|
|
|
url: "http://localhost:3000/api/get/settings",
|
|
|
|
type: "GET",
|
|
|
|
success: function (data) {
|
|
|
|
if (data["save_logg"] === 1) {
|
|
|
|
$.ajax({
|
|
|
|
url: "http://localhost:3000/api/update/settings",
|
|
|
|
type: "POST",
|
|
|
|
data: {
|
|
|
|
"save_logg": 0,
|
|
|
|
},
|
|
|
|
success: function (data) {
|
2023-03-18 16:49:24 +03:00
|
|
|
if (data["status"]) {
|
2022-11-21 22:22:00 +03:00
|
|
|
$loggingSwitchTogglerName.text("Off");
|
|
|
|
$loggingSwitch.removeAttr("checked");
|
|
|
|
|
|
|
|
toast(data.message);
|
|
|
|
} else {
|
|
|
|
toast("Failed to apply settings.");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
$.ajax({
|
|
|
|
url: "http://localhost:3000/api/update/settings",
|
|
|
|
type: "POST",
|
|
|
|
data: {
|
|
|
|
"save_logg": 1,
|
|
|
|
},
|
|
|
|
success: function (data) {
|
2023-03-18 16:49:24 +03:00
|
|
|
if (data["status"]) {
|
2022-11-21 22:22:00 +03:00
|
|
|
$loggingSwitchTogglerName.text("On");
|
|
|
|
$loggingSwitch.attr("checked", "true");
|
|
|
|
|
|
|
|
toast(data.message);
|
|
|
|
} else {
|
|
|
|
toast("Failed to apply settings.");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
2022-11-22 21:36:35 +03:00
|
|
|
});
|
|
|
|
});
|
2022-10-02 12:19:20 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
function toast(message) {
|
2022-11-21 22:22:00 +03:00
|
|
|
if (message === null) {
|
|
|
|
return "Required parameter 'message' is missing.";
|
|
|
|
}
|
|
|
|
|
2022-10-02 12:19:20 +03:00
|
|
|
$(".toast-body").text(message);
|
|
|
|
let toastLiveExample = document.getElementById('liveToast');
|
|
|
|
let toast = new bootstrap.Toast(toastLiveExample);
|
|
|
|
toast.show();
|
|
|
|
}
|
|
|
|
|
|
|
|
function editStartup(i) {
|
2022-11-21 22:22:00 +03:00
|
|
|
if (i !== 1 || i !== 0 || i === null) {
|
|
|
|
return "Required parameter 'i' is missing.";
|
|
|
|
}
|
|
|
|
|
2022-10-02 12:19:20 +03:00
|
|
|
return $.ajax({
|
2022-10-23 15:27:45 +03:00
|
|
|
url: "http://localhost:3000/api/update/startup",
|
2022-10-02 12:19:20 +03:00
|
|
|
type: "POST",
|
|
|
|
data: {
|
|
|
|
"startup": i
|
|
|
|
},
|
|
|
|
});
|
2022-11-21 22:22:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function getSettings() {
|
|
|
|
return $.ajax({
|
|
|
|
url: "http://localhost:3000/api/get/settings",
|
|
|
|
type: "GET",
|
|
|
|
});
|
2022-10-02 12:19:20 +03:00
|
|
|
}
|