mirror of
https://github.com/Starlio-app/StarlioX
synced 2024-11-06 06:13:57 +03:00
the settings code has been rewritten
This commit is contained in:
parent
3f51438c24
commit
f5c1909f81
1 changed files with 130 additions and 125 deletions
|
@ -1,39 +1,39 @@
|
||||||
$.ajax({
|
$(document).ready(async function() {
|
||||||
url: "http://localhost:8080/api/get/settings",
|
const data = await getData();
|
||||||
type: "GET",
|
|
||||||
success: function(data){
|
const $startupSwitch = $("#settings_startupSwitch");
|
||||||
if(data["autochangewallpaper"] === 1) {
|
const $startupSwitchTogglerName = $("#settings_startupTogglerName");
|
||||||
$("#autosetWallpaperSwitch").attr("checked", "true");
|
|
||||||
$("#autosetWallpaperText").text("On");
|
const $wallpaperSwitch = $("#settings_autoSetWallpaperSwitch");
|
||||||
|
const $wallpaperSwitchTogglerName = $("#settings_autoSetWallpaperTogglerName");
|
||||||
|
|
||||||
|
console.log(data)
|
||||||
|
|
||||||
|
if(data["wallpaper"] === 1) {
|
||||||
|
$wallpaperSwitch.attr("checked", "true");
|
||||||
|
$wallpaperSwitchTogglerName.text("On");
|
||||||
}
|
}
|
||||||
if(data["startup"] === 1) {
|
if(data["startup"] === 1) {
|
||||||
$("#startupSwitch").attr("checked", "true");
|
$startupSwitch.attr("checked", "true");
|
||||||
$("#startupText").text("On");
|
$startupSwitchTogglerName.text("On");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
$("#autosetWallpaperSwitch").click(function(){
|
$wallpaperSwitch.click(function() {
|
||||||
$.ajax({
|
if(data["wallpaper"] === 1) {
|
||||||
url: "http://localhost:8080/api/get/settings",
|
|
||||||
type: "GET",
|
|
||||||
success: function(data){
|
|
||||||
if(data["autochangewallpaper"] === 1){
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "http://localhost:8080/api/update/settings",
|
url: "http://localhost:8080/api/update/settings",
|
||||||
type: "POST",
|
type: "POST",
|
||||||
data: {
|
data: {
|
||||||
autochangewallpaper: 0
|
"wallpaper": 0
|
||||||
},
|
},
|
||||||
success: function(data) {
|
success: function(data) {
|
||||||
if(data.status) {
|
if(data["status"]) {
|
||||||
$("#autosetWallpaperSwitch").removeAttr("checked");
|
$wallpaperSwitchTogglerName.text("Off");
|
||||||
$("#autosetWallpaperText").text("Off");
|
$wallpaperSwitch.removeAttr("checked");
|
||||||
|
|
||||||
$(".toast-body").text(data.message);
|
toast(data.message);
|
||||||
let toastLiveExample = document.getElementById('liveToast');
|
} else {
|
||||||
let toast = new bootstrap.Toast(toastLiveExample);
|
toast("Failed to apply settings");
|
||||||
toast.show();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -42,96 +42,101 @@ $("#autosetWallpaperSwitch").click(function(){
|
||||||
url: "http://localhost:8080/api/update/settings",
|
url: "http://localhost:8080/api/update/settings",
|
||||||
type: "POST",
|
type: "POST",
|
||||||
data: {
|
data: {
|
||||||
autochangewallpaper: 1
|
"wallpaper": 1
|
||||||
},
|
},
|
||||||
success: function(data) {
|
success: function(data) {
|
||||||
if(data.status) {
|
if(data["status"]) {
|
||||||
$("#autosetWallpaperSwitch").attr("checked", "true");
|
$wallpaperSwitchTogglerName.text("On");
|
||||||
$("#autosetWallpaperText").text("On");
|
$wallpaperSwitch.attr("checked", "true");
|
||||||
|
|
||||||
$(".toast-body").text(data.message);
|
toast(data.message);
|
||||||
let toastLiveExample = document.getElementById('liveToast');
|
|
||||||
let toast = new bootstrap.Toast(toastLiveExample);
|
|
||||||
toast.show();
|
|
||||||
} else {
|
} else {
|
||||||
$(".toast-body").text("Could not remove the program from autorun.");
|
toast("Failed to apply settings");
|
||||||
let toastLiveExample = document.getElementById('liveToast');
|
|
||||||
let toast = new bootstrap.Toast(toastLiveExample);
|
|
||||||
toast.show();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
$("#startupSwitch").click(function() {
|
$startupSwitch.click(function() {
|
||||||
$.ajax({
|
|
||||||
url: "http://localhost:8080/api/get/settings",
|
|
||||||
type: "GET",
|
|
||||||
success: function (data) {
|
|
||||||
if(data["startup"] === 1) {
|
if(data["startup"] === 1) {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "http://localhost:8080/api/update/settings",
|
url: "http://localhost:8080/api/update/settings",
|
||||||
type: "POST",
|
type: "POST",
|
||||||
data: {
|
data: {
|
||||||
startup: 0
|
"startup": 0
|
||||||
},
|
},
|
||||||
success: function () {
|
success: async function(data) {
|
||||||
$.ajax({
|
if(data["status"]) {
|
||||||
url: "http://localhost:8080/api/update/del/startup",
|
await editStartup(0);
|
||||||
type: "POST",
|
|
||||||
success: function(data){
|
|
||||||
if(data.status) {
|
|
||||||
$("#startupSwitch").removeAttr("checked");
|
|
||||||
$("#startupText").text("Off");
|
|
||||||
|
|
||||||
$(".toast-body").text(data.message);
|
$startupSwitchTogglerName.text("Off");
|
||||||
let toastLiveExample = document.getElementById('liveToast');
|
$startupSwitch.removeAttr("checked");
|
||||||
let toast = new bootstrap.Toast(toastLiveExample);
|
|
||||||
toast.show();
|
toast(data.message);
|
||||||
} else {
|
} else {
|
||||||
$(".toast-body").text("Failed to apply settings.");
|
toast("Failed to apply settings");
|
||||||
let toastLiveExample = document.getElementById('liveToast');
|
|
||||||
let toast = new bootstrap.Toast(toastLiveExample);
|
|
||||||
toast.show();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "http://localhost:8080/api/update/settings",
|
url: "http://localhost:8080/api/update/settings",
|
||||||
type: "POST",
|
type: "POST",
|
||||||
data: {
|
data: {
|
||||||
startup: 1
|
"startup": 1
|
||||||
},
|
},
|
||||||
success: function () {
|
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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$("#createLabelButton").click(function() {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "http://localhost:8080/api/update/set/startup",
|
url: "http://localhost:8080/api/create/label",
|
||||||
type: "POST",
|
type: "POST",
|
||||||
success: function (data) {
|
success: function (data) {
|
||||||
if(data.status) {
|
if (data["status"]) {
|
||||||
$("#startupSwitch").attr("checked", "true");
|
toast(data.message);
|
||||||
$("#startupText").text("On");
|
|
||||||
|
|
||||||
$(".toast-body").text(data.message);
|
|
||||||
let toastLiveExample = document.getElementById('liveToast');
|
|
||||||
let toast = new bootstrap.Toast(toastLiveExample);
|
|
||||||
toast.show();
|
|
||||||
} else {
|
} else {
|
||||||
$(".toast-body").text("Failed to apply settings.");
|
toast("Failed to create label");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
function getData() {
|
||||||
|
return fetch("http://localhost:8080/api/get/settings").then(response => response.json()).then(data => {
|
||||||
|
return data;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function toast(message) {
|
||||||
|
$(".toast-body").text(message);
|
||||||
let toastLiveExample = document.getElementById('liveToast');
|
let toastLiveExample = document.getElementById('liveToast');
|
||||||
let toast = new bootstrap.Toast(toastLiveExample);
|
let toast = new bootstrap.Toast(toastLiveExample);
|
||||||
toast.show();
|
toast.show();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
function editStartup(i) {
|
||||||
|
return $.ajax({
|
||||||
|
url: "http://localhost:8080/api/update/startup",
|
||||||
|
type: "POST",
|
||||||
|
data: {
|
||||||
|
"startup": i
|
||||||
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
Loading…
Reference in a new issue