feat(watchdog): separate watchdog from startup
- Add /api/v1/watchdog to enable/disable - Scheduled task now runs every 15 minutes - Use schtasks command line instead of XML - Dashboard shows watchdog enabled state - Preserve watchdog state during install
This commit is contained in:
+20
-18
@@ -33,36 +33,38 @@ func Enable() error {
|
||||
if err := k.SetStringValue(config.StartupValueName, command); err != nil {
|
||||
return err
|
||||
}
|
||||
return enableWatchdog()
|
||||
return nil
|
||||
}
|
||||
|
||||
// SyncInstalledPath rewrites an existing Run entry to the AppData install path.
|
||||
// SyncInstalledPath rewrites existing Run/watchdog entries to the AppData path.
|
||||
func SyncInstalledPath() error {
|
||||
if !Enabled() {
|
||||
return nil
|
||||
if Enabled() {
|
||||
if err := Enable(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return Enable()
|
||||
if WatchdogEnabled() {
|
||||
if err := EnableWatchdog(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func Disable() error {
|
||||
var regErr error
|
||||
k, err := registry.OpenKey(registry.CURRENT_USER, config.StartupRunKey, registry.SET_VALUE)
|
||||
if err != nil {
|
||||
if !errors.Is(err, registry.ErrNotExist) {
|
||||
regErr = err
|
||||
}
|
||||
} else {
|
||||
err = k.DeleteValue(config.StartupValueName)
|
||||
_ = k.Close()
|
||||
if err != nil && !errors.Is(err, registry.ErrNotExist) {
|
||||
regErr = err
|
||||
if errors.Is(err, registry.ErrNotExist) {
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
taskErr := disableWatchdog()
|
||||
if regErr != nil {
|
||||
return regErr
|
||||
defer k.Close()
|
||||
err = k.DeleteValue(config.StartupValueName)
|
||||
if errors.Is(err, registry.ErrNotExist) {
|
||||
return nil
|
||||
}
|
||||
return taskErr
|
||||
return err
|
||||
}
|
||||
|
||||
func installedCommandLine() (string, error) {
|
||||
|
||||
Reference in New Issue
Block a user