mirror of
https://github.com/Starlio-app/Starlio-web.git
synced 2024-12-26 18:23:46 +03:00
add auto change wallpaper
This commit is contained in:
parent
41507c8fc5
commit
b9d775eec9
4 changed files with 111 additions and 10 deletions
|
@ -2,6 +2,7 @@ package controllers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
|
"github.com/Redume/EveryNasa/functions"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/Redume/EveryNasa/api/utils"
|
"github.com/Redume/EveryNasa/api/utils"
|
||||||
|
@ -27,14 +28,14 @@ var SettingsGet = func(w http.ResponseWriter, r *http.Request) {
|
||||||
}(query)
|
}(query)
|
||||||
|
|
||||||
var lang string
|
var lang string
|
||||||
var autostart, autoupdate int
|
var autostart, autoupdate, autochangewallpaper int
|
||||||
|
|
||||||
for query.Next() {
|
for query.Next() {
|
||||||
err := query.Scan(&lang, &autostart, &autoupdate)
|
err := query.Scan(&lang, &autostart, &autoupdate, &autochangewallpaper)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
var data = map[string]interface{}{"lang": lang, "autostart": autostart, "autoupdate": autoupdate}
|
var data = map[string]interface{}{"lang": lang, "autostart": autostart, "autoupdate": autoupdate, "autochangewallpaper": autochangewallpaper}
|
||||||
utils.Respond(w, data)
|
utils.Respond(w, data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -48,8 +49,9 @@ var SettingsUpdate = func(w http.ResponseWriter, r *http.Request) {
|
||||||
lang := r.FormValue("lang")
|
lang := r.FormValue("lang")
|
||||||
autostart := r.FormValue("autostart")
|
autostart := r.FormValue("autostart")
|
||||||
autoupdate := r.FormValue("autoupdate")
|
autoupdate := r.FormValue("autoupdate")
|
||||||
|
autochangewallpaper := r.FormValue("autochangewallpaper")
|
||||||
|
|
||||||
if lang == "" && autostart == "" && autoupdate == "" {
|
if lang == "" && autostart == "" && autoupdate == "" && autochangewallpaper == "" {
|
||||||
utils.Respond(w, utils.Message(false, "All fields are required"))
|
utils.Respond(w, utils.Message(false, "All fields are required"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -75,5 +77,16 @@ var SettingsUpdate = func(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if autochangewallpaper != "" {
|
||||||
|
_, err := db.Exec("UPDATE settings SET autochangewallpaper = ?", autochangewallpaper)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if autochangewallpaper == "1" {
|
||||||
|
go functions.StartWallpaper()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
utils.Respond(w, utils.Message(true, "Settings updated"))
|
utils.Respond(w, utils.Message(true, "Settings updated"))
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package functions
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"github.com/jasonlvhit/gocron"
|
"github.com/jasonlvhit/gocron"
|
||||||
"github.com/reujab/wallpaper"
|
"github.com/reujab/wallpaper"
|
||||||
"github.com/rodkranz/fetch"
|
"github.com/rodkranz/fetch"
|
||||||
|
@ -61,12 +62,43 @@ func SetWallpaper() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func x() {
|
||||||
|
fmt.Println("F")
|
||||||
|
}
|
||||||
|
|
||||||
func StartWallpaper() {
|
func StartWallpaper() {
|
||||||
SetWallpaper()
|
type Autostart struct {
|
||||||
times := time.Now()
|
Autochangewallpaper int `json:"autochangewallpaper"`
|
||||||
t := time.Date(times.Year(), times.Month(), times.Day(), 4, 50, times.Second(), times.Nanosecond(), time.UTC)
|
}
|
||||||
err := gocron.Every(1).Day().From(&t).Do(SetWallpaper)
|
|
||||||
if err != nil {
|
client := fetch.NewDefault()
|
||||||
panic(err)
|
res, getErr := client.Get("http://localhost:8080/api/get/settings", nil)
|
||||||
|
if getErr != nil {
|
||||||
|
panic(getErr)
|
||||||
|
}
|
||||||
|
|
||||||
|
body, StringErr := res.ToString()
|
||||||
|
if StringErr != nil {
|
||||||
|
panic(StringErr)
|
||||||
|
}
|
||||||
|
|
||||||
|
var AutostartSetWallpaper Autostart
|
||||||
|
jsonErr := json.Unmarshal([]byte(body), &AutostartSetWallpaper)
|
||||||
|
|
||||||
|
if jsonErr != nil {
|
||||||
|
panic(jsonErr)
|
||||||
|
}
|
||||||
|
|
||||||
|
if AutostartSetWallpaper.Autochangewallpaper == 1 {
|
||||||
|
times := time.Now()
|
||||||
|
t := time.Date(times.Year(), times.Month(), times.Day(), 4, 50, times.Second(), times.Nanosecond(), time.UTC)
|
||||||
|
|
||||||
|
SetWallpaper()
|
||||||
|
|
||||||
|
err := gocron.Every(1).Day().From(&t).Do(SetWallpaper)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
gocron.Start()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,14 @@
|
||||||
<h1 id="title">Application Settings</h1>
|
<h1 id="title">Application Settings</h1>
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<header class="header-row">
|
<header class="header-row">
|
||||||
|
<div class="settings">
|
||||||
|
<p class="title"><strong>Auto-change of desktop wallpaper</strong></p>
|
||||||
|
<p class="desc">EveryNasa will automatically change the desktop wallpaper at startup as well as every day</p>
|
||||||
|
<div class="form-check form-switch">
|
||||||
|
<input class="form-check-input" type="checkbox" role="switch" id="autosetWallpaperSwitch">
|
||||||
|
<label class="form-check-label" for="autorunText" id="autosetWallpaperText">Off</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div class="settings">
|
<div class="settings">
|
||||||
<p class="title"><strong>Automatic updates</strong></p>
|
<p class="title"><strong>Automatic updates</strong></p>
|
||||||
<p class="desc">EveryNasa will automatically perform an update at startup.</p>
|
<p class="desc">EveryNasa will automatically perform an update at startup.</p>
|
||||||
|
@ -52,6 +60,16 @@
|
||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="toast-container position-fixed bottom-0 end-0 p-3">
|
||||||
|
<div id="liveToast" class="toast" role="alert" aria-live="assertive" aria-atomic="true">
|
||||||
|
<div class="toast-header">
|
||||||
|
<img src="/static/image/icons/favicon.png" class="rounded me-2" alt="EveryNasa" width="30">
|
||||||
|
<strong class="me-auto" style="color: black;">EveryNasa</strong>
|
||||||
|
<button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>
|
||||||
|
</div>
|
||||||
|
<div class="toast-body" style="color: black;"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<script src="https://code.jquery.com/jquery-3.6.1.min.js"></script>
|
<script src="https://code.jquery.com/jquery-3.6.1.min.js"></script>
|
||||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0/dist/js/bootstrap.min.js" integrity="sha384-ODmDIVzN+pFdexxHEHFBQH3/9/vQ9uori45z4JjnFsRydbmQbmL5t1tQ0culUzyK" crossorigin="anonymous"></script>
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0/dist/js/bootstrap.min.js" integrity="sha384-ODmDIVzN+pFdexxHEHFBQH3/9/vQ9uori45z4JjnFsRydbmQbmL5t1tQ0culUzyK" crossorigin="anonymous"></script>
|
||||||
<script src="/static/scripts/switch.js"></script>
|
<script src="/static/scripts/switch.js"></script>
|
||||||
|
|
|
@ -10,6 +10,10 @@ $.ajax({
|
||||||
$("#autorunSwitch").attr("checked", "true");
|
$("#autorunSwitch").attr("checked", "true");
|
||||||
$("#autorunText").text("On");
|
$("#autorunText").text("On");
|
||||||
}
|
}
|
||||||
|
if(data["autochangewallpaper"] === 1) {
|
||||||
|
$("#autosetWallpaperSwitch").attr("checked", "true");
|
||||||
|
$("#autosetWallpaperText").text("On");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
|
@ -82,3 +86,37 @@ $("#autorunSwitch").click(function(){
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
|
||||||
|
$("#autosetWallpaperSwitch").click(function(){
|
||||||
|
$.ajax({
|
||||||
|
url: "http://localhost:8080/api/get/settings",
|
||||||
|
type: "GET",
|
||||||
|
success: function(data){
|
||||||
|
if(data["autochangewallpaper"] === 1){
|
||||||
|
$.ajax({
|
||||||
|
url: "http://localhost:8080/api/update/settings",
|
||||||
|
type: "POST",
|
||||||
|
data: {
|
||||||
|
autochangewallpaper: 0
|
||||||
|
},
|
||||||
|
success: function(){
|
||||||
|
$("#autosetWallpaperSwitch").removeAttr("checked");
|
||||||
|
$("#autosetWallpaperText").text("Off");
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
$.ajax({
|
||||||
|
url: "http://localhost:8080/api/update/settings",
|
||||||
|
type: "POST",
|
||||||
|
data: {
|
||||||
|
autochangewallpaper: 1
|
||||||
|
},
|
||||||
|
success: function(){
|
||||||
|
$("#autosetWallpaperSwitch").attr("checked", "true");
|
||||||
|
$("#autosetWallpaperText").text("On");
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})
|
Loading…
Add table
Reference in a new issue