Compare commits

..

No commits in common. "master" and "v0.5.1" have entirely different histories.

7 changed files with 954 additions and 953 deletions

45
app.go
View File

@ -16,12 +16,11 @@ import (
) )
type App struct { type App struct {
cfg *config.Config cfg *config.Config
db *reveil.LevelDBStorage db *reveil.LevelDBStorage
router *gin.Engine router *gin.Engine
srv *http.Server srv *http.Server
nextAlarm *time.Timer nextAlarm *time.Timer
nextPreAlarm *time.Timer
} }
func NewApp(cfg *config.Config) *App { func NewApp(cfg *config.Config) *App {
@ -77,45 +76,11 @@ func (app *App) Start() {
func (app *App) ResetTimer() { func (app *App) ResetTimer() {
if app.nextAlarm != nil { if app.nextAlarm != nil {
app.nextAlarm.Stop() app.nextAlarm.Stop()
app.nextPreAlarm = nil
app.nextAlarm = nil app.nextAlarm = nil
} }
settings, _ := reveil.ReadSettings(app.cfg.SettingsFile)
if na, routines, federated, err := reveil.GetNextAlarm(app.cfg, app.db); err == nil && na != nil { if na, routines, federated, err := reveil.GetNextAlarm(app.cfg, app.db); err == nil && na != nil {
if settings != nil && settings.PreAlarmAction != "" {
app.nextPreAlarm = time.AfterFunc(time.Until(*na)-settings.PreAlarmActionDelay*time.Minute, func() {
app.nextPreAlarm = nil
settings, err := reveil.ReadSettings(app.cfg.SettingsFile)
if err != nil {
log.Println("Unable to read settings:", err.Error())
return
}
action, err := reveil.LoadAction(app.cfg, settings.PreAlarmAction)
if err != nil {
log.Println("Unable to load pre-alarm action:", err.Error())
}
cmd, err := action.Launch(settings)
if err != nil {
log.Println(err.Error())
return
}
go func() {
err := cmd.Wait()
if err != nil {
log.Printf("%q: %s", action.Name, err.Error())
}
}()
})
log.Println("Next pre-alarm programmed for", time.Time(*na).Add(settings.PreAlarmActionDelay*-1*time.Minute))
}
app.nextAlarm = time.AfterFunc(time.Until(*na), func() { app.nextAlarm = time.AfterFunc(time.Until(*na), func() {
app.nextPreAlarm = nil
app.nextAlarm = nil app.nextAlarm = nil
reveil.RemoveOldAlarmsSingle(app.db) reveil.RemoveOldAlarmsSingle(app.db)

View File

@ -8,15 +8,13 @@ import (
// Settings represents the settings panel. // Settings represents the settings panel.
type Settings struct { type Settings struct {
Language string `json:"language"` Language string `json:"language"`
GongInterval time.Duration `json:"gong_interval"` GongInterval time.Duration `json:"gong_interval"`
WeatherDelay time.Duration `json:"weather_delay"` WeatherDelay time.Duration `json:"weather_delay"`
WeatherAction string `json:"weather_action"` WeatherAction string `json:"weather_action"`
PreAlarmActionDelay time.Duration `json:"pre_alarm_delay"` MaxRunTime time.Duration `json:"max_run_time"`
PreAlarmAction string `json:"pre_alarm_action"` MaxVolume uint16 `json:"max_volume"`
MaxRunTime time.Duration `json:"max_run_time"` Federation map[string]FederationServer `json:"federation"`
MaxVolume uint16 `json:"max_volume"`
Federation map[string]FederationServer `json:"federation"`
} }
// ExistsSettings checks if the settings file can by found at the given path. // ExistsSettings checks if the settings file can by found at the given path.

1783
ui/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -15,18 +15,18 @@
"@sveltejs/adapter-static": "^3.0.0", "@sveltejs/adapter-static": "^3.0.0",
"@sveltejs/kit": "^2.0.0", "@sveltejs/kit": "^2.0.0",
"@sveltejs/vite-plugin-svelte": "^3.0.0", "@sveltejs/vite-plugin-svelte": "^3.0.0",
"@typescript-eslint/eslint-plugin": "^8.0.0", "@typescript-eslint/eslint-plugin": "^7.0.0",
"@typescript-eslint/parser": "^8.0.0", "@typescript-eslint/parser": "^7.0.0",
"bootstrap": "^5.1.3", "bootstrap": "^5.1.3",
"bootstrap-icons": "^1.8.0", "bootstrap-icons": "^1.8.0",
"bootswatch": "^5.1.3", "bootswatch": "^5.1.3",
"eslint": "^9.0.0", "eslint": "^8.0.0",
"eslint-config-prettier": "^9.0.0", "eslint-config-prettier": "^9.0.0",
"eslint-plugin-svelte": "^2.33.0", "eslint-plugin-svelte": "^2.33.0",
"prettier": "^3.1.1", "prettier": "^3.1.1",
"prettier-plugin-svelte": "^3.1.2", "prettier-plugin-svelte": "^3.1.2",
"svelte": "^5.0.0", "svelte": "^4.0.0",
"svelte-check": "^4.0.0", "svelte-check": "^3.4.3",
"svelte-preprocess": "^6.0.0", "svelte-preprocess": "^6.0.0",
"tslib": "^2.3.1", "tslib": "^2.3.1",
"typescript": "^5.0.0" "typescript": "^5.0.0"
@ -35,7 +35,7 @@
"dependencies": { "dependencies": {
"dayjs": "^1.11.5", "dayjs": "^1.11.5",
"sass": "^1.49.7", "sass": "^1.49.7",
"sass-loader": "^16.0.0", "sass-loader": "^15.0.0",
"@sveltestrap/sveltestrap": "^6.0.0", "@sveltestrap/sveltestrap": "^6.0.0",
"vite": "^5.0.0" "vite": "^5.0.0"
} }

View File

@ -5,13 +5,11 @@ export class Settings {
} }
} }
update({ language, gong_interval, weather_delay, weather_action, pre_alarm_delay, pre_alarm_action, max_run_time, max_volume, federation }) { update({ language, gong_interval, weather_delay, weather_action, max_run_time, max_volume, federation }) {
this.language = language; this.language = language;
this.gong_interval = gong_interval; this.gong_interval = gong_interval;
this.weather_delay = weather_delay; this.weather_delay = weather_delay;
this.weather_action = weather_action; this.weather_action = weather_action;
this.pre_alarm_delay = pre_alarm_delay;
this.pre_alarm_action = pre_alarm_action;
this.max_run_time = max_run_time; this.max_run_time = max_run_time;
this.max_volume = max_volume; this.max_volume = max_volume;
this.federation = federation; this.federation = federation;

View File

@ -2,18 +2,6 @@ import { writable } from 'svelte/store';
import { getTracks } from '$lib/track' import { getTracks } from '$lib/track'
function cmpTracks(a, b) {
if (a.enabled && !b.enabled) return -1;
if (!a.enabled && b.enabled) return 1;
if (a.path.toLowerCase() > b.path.toLowerCase())
return 1;
if (a.path.toLowerCase() < b.path.toLowerCase())
return -1;
return 0;
}
function createTracksStore() { function createTracksStore() {
const { subscribe, set, update } = writable({list: null}); const { subscribe, set, update } = writable({list: null});
@ -26,7 +14,6 @@ function createTracksStore() {
refresh: async () => { refresh: async () => {
const list = await getTracks(); const list = await getTracks();
list.sort(cmpTracks);
update((m) => Object.assign(m, {list})); update((m) => Object.assign(m, {list}));
return list; return list;
}, },

View File

@ -89,40 +89,6 @@
{/if} {/if}
</FormGroup> </FormGroup>
<FormGroup>
<Label for="preAlarmDelay">Lancement action pré-alarme</Label>
<InputGroup>
<Input
type="number"
id="preAlarmDelay"
placeholder="5"
bind:value={settings.pre_alarm_delay}
on:input={submitSettings}
/>
<InputGroupText>min</InputGroupText>
</InputGroup>
</FormGroup>
<FormGroup>
<Label for="preAlarmRituel">Action pour l'action pré-alarme</Label>
{#if $actions.list}
<Input
type="select"
id="preAlarmRituel"
bind:value={settings.pre_alarm_action}
on:input={submitSettings}
>
{#each $actions.list as action (action.id)}
<option value="{action.path}">{action.name}</option>
{/each}
</Input>
{:else}
<div class="d-flex justify-content-center align-items-center gap-2">
<Spinner color="primary" /> Chargement en cours&hellip;
</div>
{/if}
</FormGroup>
<FormGroup> <FormGroup>
<Label for="greetingLanguage">Langue de salutation</Label> <Label for="greetingLanguage">Langue de salutation</Label>
<Input <Input