UI: fix failed api calls after restart (#30234)

This commit is contained in:
Michael Geers 2026-05-26 18:29:05 +02:00 • committed by GitHub
parent 45ee243be0
commit 41b4de8783
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 17 additions and 5 deletions

View file

@ -7,6 +7,7 @@ import setupRouter from "./router.ts";
import setupI18n from "./i18n.ts";
import { watchThemeChanges } from "./theme.ts";
import { appDetection, sendToApp } from "./utils/native";
import store from "./store";
import type { Notification } from "./types/evcc";
// lazy load smoothscroll polyfill. mainly for safari < 15.4
@ -20,7 +21,12 @@ if (!window.CSS.supports("scroll-behavior", "smooth")) {
const app = createApp(
defineComponent({
data() {
return { notifications: [] as Notification[], offline: false };
return { notifications: [] as Notification[], wsOffline: false };
},
computed: {
offline(): boolean {
return this.wsOffline || store.state.apiReady !== true;
},
},
watch: {
offline(value) {
@ -54,11 +60,11 @@ const app = createApp(
this.notifications = [];
},
setOnline() {
this.offline = false;
this.wsOffline = false;
sendToApp({ type: "online" });
},
setOffline() {
this.offline = true;
this.wsOffline = true;
sendToApp({ type: "offline" });
},
},

View file

@ -116,8 +116,8 @@ watch(
(offline) => offline && debounedUpdateAuthStatus()
);
watch(
() => store.state.startupCompleted,
(startupCompleted) => startupCompleted && debounedUpdateAuthStatus()
() => store.state.apiReady,
(ready) => ready && debounedUpdateAuthStatus()
);
export default auth;

View file

@ -71,6 +71,7 @@ export interface State {
experimental?: boolean;
setupRequired?: boolean;
startupCompleted?: boolean;
apiReady?: boolean;
loadpoints: Loadpoint[];
forecast: Forecast;
currency?: CURRENCY;

View file

@ -244,6 +244,7 @@ func runRoot(cmd *cobra.Command, args []string) {
// signal ui listening
valueChan <- util.Param{Key: keys.StartupCompleted, Val: false}
valueChan <- util.Param{Key: keys.ApiReady, Val: false}
// metrics
if viper.GetBool("metrics") {
@ -464,6 +465,9 @@ func runRoot(cmd *cobra.Command, args []string) {
}()
}
// signal HTTP API ready
valueChan <- util.Param{Key: keys.ApiReady, Val: true}
if err != nil {
if uw, ok := err.(interface{ Unwrap() []error }); ok {
valueChan <- util.Param{Key: keys.Fatal, Val: uw.Unwrap()}

View file

@ -25,6 +25,7 @@ const (
Timezone = "timezone"
Fatal = "fatal"
StartupCompleted = "startupCompleted" // false: starting, true: started
ApiReady = "apiReady" // http handlers are registered
SetupRequired = "setupRequired" // initial setup is required (lp = 0), fresh installation
Plant = "plant"
Telemetry = "telemetry"