mirror of
https://github.com/seriousm4x/UpSnap.git
synced 2026-07-30 09:22:41 -04:00
add lazy ping option
This commit is contained in:
@@ -21,9 +21,9 @@ func RunPing(app *pocketbase.PocketBase) {
|
||||
// init cronjob
|
||||
CronPing = cron.New()
|
||||
CronPing.AddFunc(settingsPrivateRecords[0].GetString("interval"), func() {
|
||||
// skip cron if no realtime clients connected
|
||||
// skip cron if no realtime clients connected and lazy_ping is turned on
|
||||
realtimeClients := len(app.SubscriptionsBroker().Clients())
|
||||
if realtimeClients == 0 {
|
||||
if realtimeClients == 0 && settingsPrivateRecords[0].GetBool("lazy_ping") {
|
||||
return
|
||||
}
|
||||
// expand ports field
|
||||
|
||||
48
backend/migrations/1692020613_updated_settings_private.go
Normal file
48
backend/migrations/1692020613_updated_settings_private.go
Normal file
@@ -0,0 +1,48 @@
|
||||
package migrations
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/pocketbase/dbx"
|
||||
"github.com/pocketbase/pocketbase/daos"
|
||||
m "github.com/pocketbase/pocketbase/migrations"
|
||||
"github.com/pocketbase/pocketbase/models/schema"
|
||||
)
|
||||
|
||||
func init() {
|
||||
m.Register(func(db dbx.Builder) error {
|
||||
dao := daos.New(db);
|
||||
|
||||
collection, err := dao.FindCollectionByNameOrId("nmj3ko20gzkg8n3")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// add
|
||||
new_lazy_ping := &schema.SchemaField{}
|
||||
json.Unmarshal([]byte(`{
|
||||
"system": false,
|
||||
"id": "yjyq5pvg",
|
||||
"name": "lazy_ping",
|
||||
"type": "bool",
|
||||
"required": false,
|
||||
"unique": false,
|
||||
"options": {}
|
||||
}`), new_lazy_ping)
|
||||
collection.Schema.AddField(new_lazy_ping)
|
||||
|
||||
return dao.SaveCollection(collection)
|
||||
}, func(db dbx.Builder) error {
|
||||
dao := daos.New(db);
|
||||
|
||||
collection, err := dao.FindCollectionByNameOrId("nmj3ko20gzkg8n3")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// remove
|
||||
collection.Schema.RemoveField("yjyq5pvg")
|
||||
|
||||
return dao.SaveCollection(collection)
|
||||
})
|
||||
}
|
||||
@@ -9,5 +9,6 @@ export type SettingsPublic = Record & {
|
||||
|
||||
export type SettingsPrivate = Record & {
|
||||
interval: number;
|
||||
lazy_ping: boolean;
|
||||
scan_range: string;
|
||||
};
|
||||
|
||||
@@ -67,8 +67,17 @@
|
||||
.collection('settings_public')
|
||||
.update(settingsPubClone.id, settingsPubClone)
|
||||
.then((res) => {
|
||||
toast.success('Saved settings');
|
||||
settingsPub.set(res as SettingsPublic);
|
||||
})
|
||||
.catch((err) => {
|
||||
toast.error(err.message);
|
||||
});
|
||||
await $pocketbase
|
||||
.collection('settings_private')
|
||||
.update(settingsPrivClone.id, settingsPrivClone)
|
||||
.then((res) => {
|
||||
toast.success('Saved settings');
|
||||
settingsPriv.set(res as SettingsPrivate);
|
||||
goto('/');
|
||||
})
|
||||
.catch((err) => {
|
||||
@@ -90,7 +99,7 @@
|
||||
class="badge">@every 3s</span
|
||||
>.
|
||||
</p>
|
||||
<p class="mb-2">
|
||||
<p>
|
||||
Learn more about the correct syntax for cron on
|
||||
<a target="_blank" class="link" href="https://en.wikipedia.org/wiki/Cron">Wikipedia</a>
|
||||
or refer to the
|
||||
@@ -98,7 +107,7 @@
|
||||
>package documentation</a
|
||||
>.
|
||||
</p>
|
||||
<div class="form-control w-full">
|
||||
<div class="form-control w-full mt-2">
|
||||
<input
|
||||
type="text"
|
||||
placeholder="e.g. '@every 5s' or '@every 1m'"
|
||||
@@ -106,6 +115,21 @@
|
||||
bind:value={settingsPrivClone.interval}
|
||||
/>
|
||||
</div>
|
||||
<h2 class="card-title mt-2">Lazy ping</h2>
|
||||
<p class="mt-2">
|
||||
When lazy ping is turned on, UpSnap will only ping devices if there is an active user
|
||||
visiting the website. If it's turned off, UpSnap will always ping devices.
|
||||
</p>
|
||||
<div class="form-control w-fit">
|
||||
<label class="label cursor-pointer gap-2">
|
||||
<input
|
||||
type="checkbox"
|
||||
class="checkbox checkbox-primary"
|
||||
bind:checked={settingsPrivClone.lazy_ping}
|
||||
/>
|
||||
<span class="label-text">Enable</span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card w-full bg-base-300 shadow-xl mt-6">
|
||||
|
||||
Reference in New Issue
Block a user