The settings code was almost returned to the old form, errors were fixed

This commit is contained in:
Данил 2022-10-09 12:03:38 +03:00
parent 727cc1d1e6
commit ea9931dc83
2 changed files with 110 additions and 114 deletions

View file

@ -63,7 +63,7 @@ func SetWallpaper() {
func StartWallpaper() { func StartWallpaper() {
type Autostart struct { type Autostart struct {
Autochangewallpaper int `json:"autochangewallpaper"` Wallpaper int `json:"wallpaper"`
} }
client := fetch.NewDefault() client := fetch.NewDefault()
@ -83,7 +83,7 @@ func StartWallpaper() {
Logger(err.Error()) Logger(err.Error())
} }
if AutostartSetWallpaper.Autochangewallpaper == 1 { if AutostartSetWallpaper.Wallpaper == 1 {
times := time.Now() times := time.Now()
t := time.Date(times.Year(), times.Month(), times.Day(), 4, 50, times.Second(), times.Nanosecond(), time.UTC) t := time.Date(times.Year(), times.Month(), times.Day(), 4, 50, times.Second(), times.Nanosecond(), time.UTC)

View file

@ -1,12 +1,14 @@
$(document).ready(async function() { $(document).ready(async function() {
const data = await getData();
const $startupSwitch = $("#settings_startupSwitch"); const $startupSwitch = $("#settings_startupSwitch");
const $startupSwitchTogglerName = $("#settings_startupTogglerName"); const $startupSwitchTogglerName = $("#settings_startupTogglerName");
const $wallpaperSwitch = $("#settings_autoSetWallpaperSwitch"); const $wallpaperSwitch = $("#settings_autoSetWallpaperSwitch");
const $wallpaperSwitchTogglerName = $("#settings_autoSetWallpaperTogglerName"); const $wallpaperSwitchTogglerName = $("#settings_autoSetWallpaperTogglerName");
$.ajax({
url: "http://localhost:8080/api/get/settings",
type: "GET",
success: function(data) {
if (data["wallpaper"] === 1) { if (data["wallpaper"] === 1) {
$wallpaperSwitch.attr("checked", "true"); $wallpaperSwitch.attr("checked", "true");
$wallpaperSwitchTogglerName.text("On"); $wallpaperSwitchTogglerName.text("On");
@ -15,14 +17,20 @@ $(document).ready(async function() {
$startupSwitch.attr("checked", "true"); $startupSwitch.attr("checked", "true");
$startupSwitchTogglerName.text("On"); $startupSwitchTogglerName.text("On");
} }
},
});
$wallpaperSwitch.click(function() { $wallpaperSwitch.click(async function() {
$.ajax({
url: "http://localhost:8080/api/get/settings",
type: "GET",
success: function (data) {
if (data["wallpaper"] === 1) { if (data["wallpaper"] === 1) {
$.ajax({ $.ajax({
url: "http://localhost:8080/api/update/settings", url: "http://localhost:8080/api/update/settings",
type: "POST", type: "POST",
data: { data: {
"wallpaper": 0 "wallpaper": 0,
}, },
success: function (data) { success: function (data) {
if(data["status"]) { if(data["status"]) {
@ -31,16 +39,16 @@ $(document).ready(async function() {
toast(data.message); toast(data.message);
} else { } else {
toast("Failed to apply settings"); toast("Failed to apply settings.");
}
} }
},
}); });
} else { } else {
$.ajax({ $.ajax({
url: "http://localhost:8080/api/update/settings", url: "http://localhost:8080/api/update/settings",
type: "POST", type: "POST",
data: { data: {
"wallpaper": 1 "wallpaper": 1,
}, },
success: function (data) { success: function (data) {
if(data["status"]) { if(data["status"]) {
@ -49,20 +57,27 @@ $(document).ready(async function() {
toast(data.message); toast(data.message);
} else { } else {
toast("Failed to apply settings"); toast("Failed to apply settings.");
}
} }
},
}); });
} }
},
})
}); });
$startupSwitch.click(function() {
$startupSwitch.click(async 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: async function (data) { success: async function (data) {
if (data["status"]) { if (data["status"]) {
@ -73,16 +88,16 @@ $(document).ready(async function() {
toast(data.message); toast(data.message);
} else { } else {
toast("Failed to apply settings"); toast("Failed to apply settings.");
}
} }
},
}); });
} 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: async function (data) { success: async function (data) {
if (data["status"]) { if (data["status"]) {
@ -93,35 +108,16 @@ $(document).ready(async function() {
toast(data.message); toast(data.message);
} else { } else {
toast("Failed to apply settings"); toast("Failed to apply settings.");
}
} }
},
}); });
} }
}); },
$("#createLabelButton").click(function() {
$.ajax({
url: "http://localhost:8080/api/create/label",
type: "POST",
success: function (data) {
if (data["status"]) {
toast(data.message);
} else {
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) { function toast(message) {
$(".toast-body").text(message); $(".toast-body").text(message);
let toastLiveExample = document.getElementById('liveToast'); let toastLiveExample = document.getElementById('liveToast');