mirror of
https://github.com/Starlio-app/StarlioX
synced 2024-11-05 06:03:57 +03:00
Analytics has been done, it is possible to turn it off
This commit is contained in:
parent
a5561d76e6
commit
d8bc09074c
9 changed files with 156 additions and 56 deletions
|
@ -27,14 +27,17 @@ var SettingsGet = func(c *fiber.Ctx) error {
|
|||
}
|
||||
}(querySettings)
|
||||
|
||||
var startup, wallpaper, save_logg int
|
||||
var startup, wallpaper, save_logg, analytics int
|
||||
|
||||
for querySettings.Next() {
|
||||
err := querySettings.Scan(&startup, &wallpaper, &save_logg)
|
||||
err := querySettings.Scan(&startup, &wallpaper, &save_logg, &analytics)
|
||||
if err != nil {
|
||||
functions.Logger(err.Error())
|
||||
}
|
||||
var data = map[string]interface{}{"startup": startup, "wallpaper": wallpaper, "save_logg": save_logg}
|
||||
var data = map[string]interface{}{"startup": startup,
|
||||
"wallpaper": wallpaper,
|
||||
"save_logg": save_logg,
|
||||
"analytics": analytics}
|
||||
utils.Respond(c, data)
|
||||
}
|
||||
|
||||
|
@ -50,8 +53,9 @@ var SettingsUpdate = func(c *fiber.Ctx) error {
|
|||
startup := c.FormValue("startup")
|
||||
wallpaper := c.FormValue("wallpaper")
|
||||
save_logg := c.FormValue("save_logg")
|
||||
analytics := c.FormValue("analytics")
|
||||
|
||||
if startup == "" && wallpaper == "" && save_logg == "" {
|
||||
if startup == "" && wallpaper == "" && save_logg == "" && analytics == "" {
|
||||
utils.Respond(c, utils.Message(false, "All fields are required."))
|
||||
return nil
|
||||
}
|
||||
|
@ -81,6 +85,13 @@ var SettingsUpdate = func(c *fiber.Ctx) error {
|
|||
}
|
||||
}
|
||||
|
||||
if analytics != "" {
|
||||
_, err := db.Exec("UPDATE settings SET analytics = ?", analytics)
|
||||
if err != nil {
|
||||
functions.Logger(err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
utils.Respond(c, utils.Message(true, "The settings have been applied successfully."))
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -2,9 +2,6 @@ package functions
|
|||
|
||||
import (
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"github.com/rodkranz/fetch"
|
||||
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
)
|
||||
|
||||
|
@ -26,7 +23,8 @@ func Database() {
|
|||
CREATE TABLE IF NOT EXISTS settings (
|
||||
startup INTEGER DEFAULT 0,
|
||||
wallpaper INTEGER DEFAULT 0,
|
||||
save_logg INTEGER DEFAULT 0
|
||||
save_logg INTEGER DEFAULT 1,
|
||||
analytics INTEGER DEFAULT 1
|
||||
);`
|
||||
|
||||
_, err = db.Exec(sqlTable)
|
||||
|
@ -34,39 +32,14 @@ func Database() {
|
|||
Logger(err.Error())
|
||||
}
|
||||
|
||||
stmt, err := db.Prepare("INSERT INTO settings(startup, wallpaper, save_logg) values(?,?,?)")
|
||||
stmt, err := db.Prepare("INSERT INTO settings(startup, wallpaper, save_logg, analytics) values(?,?,?,?)")
|
||||
if err != nil {
|
||||
Logger(err.Error())
|
||||
}
|
||||
|
||||
_, err = stmt.Exec(0, 0, 0)
|
||||
_, err = stmt.Exec(0, 0, 1, 1)
|
||||
if err != nil {
|
||||
Logger(err.Error())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func getDatabase() int {
|
||||
client := fetch.NewDefault()
|
||||
res, err := client.Get("http://localhost:3000/api/get/settings", nil)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
body, err := res.ToString()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
type DatabaseStruct struct {
|
||||
Save_logg int `json:"save_logg"`
|
||||
}
|
||||
|
||||
var Database DatabaseStruct
|
||||
err = json.Unmarshal([]byte(body), &Database)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return Database.Save_logg
|
||||
}
|
||||
|
|
|
@ -1,11 +1,14 @@
|
|||
package functions
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"runtime"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/rodkranz/fetch"
|
||||
)
|
||||
|
||||
func Logger(text string) {
|
||||
|
@ -93,3 +96,28 @@ func CreateFolder(name string) error {
|
|||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func getDatabase() int {
|
||||
client := fetch.NewDefault()
|
||||
res, err := client.Get("http://localhost:3000/api/get/settings", nil)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
body, err := res.ToString()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
type DatabaseStruct struct {
|
||||
Save_logg int `json:"save_logg"`
|
||||
}
|
||||
|
||||
var Database DatabaseStruct
|
||||
err = json.Unmarshal([]byte(body), &Database)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return Database.Save_logg
|
||||
}
|
||||
|
|
4
main.go
4
main.go
|
@ -68,10 +68,6 @@ func main() {
|
|||
return controllers.SettingsGet(c)
|
||||
})
|
||||
|
||||
get.Get("/settings", func(c *fiber.Ctx) error {
|
||||
return controllers.SettingsGet(c)
|
||||
})
|
||||
|
||||
err := app.Listen(":3000")
|
||||
if err != nil {
|
||||
return
|
||||
|
|
|
@ -53,5 +53,5 @@
|
|||
<script src="https://code.jquery.com/jquery-3.6.1.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.1/dist/js/bootstrap.bundle.min.js" integrity="sha384-u1OknCvxWvY5kfmNBILK2hRnQC3Pr17a+RTT6rIHI7NnikvbZlHgTPOOmMi466C8" crossorigin="anonymous"></script>
|
||||
<script src="/static/scripts/tooltip.js" type="application/javascript"></script>
|
||||
</body>
|
||||
<script src="/static/scripts/analytics.js" type="module"></script></body>
|
||||
</html>
|
|
@ -71,5 +71,6 @@
|
|||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.1/dist/js/bootstrap.min.js" integrity="sha384-7VPbUDkoPSGFnVtYi0QogXtr74QeVeeIs99Qfg5YCF+TidwNdjvaKZX19NZ/e6oz" crossorigin="anonymous"></script>
|
||||
<script src="https://unpkg.com/@lottiefiles/lottie-player@latest/dist/lottie-player.js"></script>
|
||||
<script src="/static/scripts/gallery.js" type="application/javascript"></script>
|
||||
<script src="/static/scripts/analytics.js" type="module" id="analytics"></script>
|
||||
</body>
|
||||
</html>
|
|
@ -52,11 +52,20 @@
|
|||
</div>
|
||||
<div class="settings">
|
||||
<p class="title"><strong>Create log files</strong></p>
|
||||
<p class="desc">Every Nasa will create files in which errors will be written that will help developers when correcting errors.</p>
|
||||
<p class="desc">EveryNasa will create files in which errors will be written that will help developers when correcting errors.</p>
|
||||
<div class="form-check form-switch">
|
||||
<input class="form-check-input" type="checkbox" role="switch" id="settings_saveLoggSwitch">
|
||||
<label class="form-check-label" for="settings_autoSetWallpaperTogglerName" id="settings_saveLoggTogglerName">Off</label>
|
||||
</div> </div>
|
||||
<label class="form-check-label" for="settings_saveLoggTogglerName" id="settings_saveLoggTogglerName">Off</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="settings">
|
||||
<p class="title"><strong>Enable Analytics</strong></p>
|
||||
<p class="desc">EveryNasa will collect Anonymous Usage data.</p>
|
||||
<div class="form-check form-switch">
|
||||
<input class="form-check-input" type="checkbox" role="switch" id="settings_analyticsSwitch">
|
||||
<label class="form-check-label" for="settings_analyticsTogglerName" id="settings_analyticsTogglerName">Off</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="settings">
|
||||
<p class="title"><strong>Create an application shortcut</strong></p>
|
||||
<p class="desc">EveryNasa will create an application shortcut on your desktop.</p>
|
||||
|
|
27
web/static/scripts/analytics.js
Normal file
27
web/static/scripts/analytics.js
Normal file
|
@ -0,0 +1,27 @@
|
|||
import { initializeApp } from "https://www.gstatic.com/firebasejs/9.14.0/firebase-app.js";
|
||||
import { getAnalytics } from "https://www.gstatic.com/firebasejs/9.14.0/firebase-analytics.js";
|
||||
|
||||
$.ajax({
|
||||
url: 'http://localhost:3000/api/get/settings',
|
||||
type: 'GET',
|
||||
dataType: 'json',
|
||||
success: function (data) {
|
||||
if (data["analytics"] === 1) {
|
||||
const firebaseConfig = {
|
||||
apiKey: "AIzaSyCeHtV4wmB9xJY4vfcpt7wX-WvlV-5S6v4",
|
||||
authDomain: "everynasa-181a1.firebaseapp.com",
|
||||
databaseURL: "https://everynasa-181a1-default-rtdb.firebaseio.com",
|
||||
projectId: "everynasa-181a1",
|
||||
storageBucket: "everynasa-181a1.appspot.com",
|
||||
messagingSenderId: "369869513900",
|
||||
appId: "1:369869513900:web:2ff68e57f95a36bf87ab09",
|
||||
measurementId: "G-JN83RYFK56"
|
||||
};
|
||||
|
||||
const app = initializeApp(firebaseConfig);
|
||||
getAnalytics(app);
|
||||
} else {
|
||||
$("#analytics").remove();
|
||||
}
|
||||
}
|
||||
})
|
|
@ -8,17 +8,26 @@ $(document).ready(async function() {
|
|||
const $loggingSwitch = $("#settings_saveLoggSwitch");
|
||||
const $loggingSwitchTogglerName = $("#settings_saveLoggTogglerName");
|
||||
|
||||
const $analyticsSwitch = $("#settings_analyticsSwitch");
|
||||
const $analyticsSwitchTogglerName = $("#settings_analyticsTogglerName");
|
||||
|
||||
getSettings().then((data) => {
|
||||
if (data["wallpaper"] === 1) {
|
||||
$wallpaperSwitch.attr("checked", "true");
|
||||
$wallpaperSwitchTogglerName.text("On");
|
||||
} else if (data["startup"] === 1) {
|
||||
$startupSwitch.attr("checked", "true");
|
||||
$startupSwitchTogglerName.text("On");
|
||||
} else if (data["save_logg"] === 1) {
|
||||
$loggingSwitch.attr("checked", "true");
|
||||
$loggingSwitchTogglerName.text("On");
|
||||
}
|
||||
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");
|
||||
}
|
||||
if (data["analytics"] === 1) {
|
||||
$analyticsSwitch.attr("checked", "true");
|
||||
$analyticsSwitchTogglerName.text("On");
|
||||
}
|
||||
});
|
||||
|
||||
$wallpaperSwitch.click(async function() {
|
||||
|
@ -67,7 +76,6 @@ $(document).ready(async function() {
|
|||
})
|
||||
});
|
||||
|
||||
|
||||
$startupSwitch.click(async function() {
|
||||
$.ajax({
|
||||
url: "http://localhost:3000/api/get/settings",
|
||||
|
@ -106,7 +114,6 @@ $(document).ready(async function() {
|
|||
|
||||
$startupSwitchTogglerName.text("On");
|
||||
$startupSwitch.attr("checked", "true");
|
||||
|
||||
toast(data.message);
|
||||
} else {
|
||||
toast("Failed to apply settings.");
|
||||
|
@ -161,7 +168,55 @@ $(document).ready(async function() {
|
|||
});
|
||||
}
|
||||
},
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
$analyticsSwitch.click(async function() {
|
||||
$.ajax({
|
||||
url: "http://localhost:3000/api/get/settings",
|
||||
type: "GET",
|
||||
success: function (data) {
|
||||
if (data["analytics"] === 1) {
|
||||
$.ajax({
|
||||
url: "http://localhost:3000/api/update/settings",
|
||||
type: "POST",
|
||||
data: {
|
||||
"analytics": 0,
|
||||
},
|
||||
success: function (data) {
|
||||
if(data["status"]) {
|
||||
$analyticsSwitchTogglerName.text("Off");
|
||||
$analyticsSwitch.removeAttr("checked");
|
||||
|
||||
toast(data.message);
|
||||
} else {
|
||||
toast("Failed to apply settings.");
|
||||
}
|
||||
},
|
||||
});
|
||||
} else {
|
||||
$.ajax({
|
||||
url: "http://localhost:3000/api/update/settings",
|
||||
type: "POST",
|
||||
data: {
|
||||
"analytics": 1,
|
||||
},
|
||||
success: function (data) {
|
||||
if(data["status"]) {
|
||||
$analyticsSwitchTogglerName.text("On");
|
||||
$analyticsSwitch.attr("checked", "true");
|
||||
|
||||
$("body").append("<script src='/static/scripts/analytics.js' type='module' id='analytics'></script>")
|
||||
|
||||
toast(data.message);
|
||||
} else {
|
||||
toast("Failed to apply settings.");
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue