Compare commits

..

No commits in common. "0cc84f0c54e06947eb7883e18e968acecf84340a" and "9832be29ef76f9c2a1b7272d371019d285b30fb4" have entirely different histories.

7 changed files with 25 additions and 109 deletions

View File

@ -311,27 +311,13 @@ func (s *State) checkUpdateStatus(
appUpdateStatus.available = false
}
components := params.Components
// skip check if no components are specified
if len(components) == 0 {
return nil
// Handle custom target versions
if slices.Contains(params.Components, "app") && params.AppTargetVersion != "" {
appUpdateStatus.available = appVersionRemote.String() != appUpdateStatus.localVersion
}
// TODO: simplify this
if slices.Contains(components, "app") {
if params.AppTargetVersion != "" {
appUpdateStatus.available = appVersionRemote.String() != appVersionLocal.String()
}
} else {
appUpdateStatus.available = false
}
if slices.Contains(components, "system") {
if params.SystemTargetVersion != "" {
systemUpdateStatus.available = systemVersionRemote.String() != systemVersionLocal.String()
}
} else {
systemUpdateStatus.available = false
if slices.Contains(params.Components, "system") && params.SystemTargetVersion != "" {
systemUpdateStatus.available = systemVersionRemote.String() != systemUpdateStatus.localVersion
}
return nil

View File

@ -1,58 +0,0 @@
package ota
import (
"context"
"net/http"
"os"
"testing"
"time"
"github.com/Masterminds/semver/v3"
"github.com/rs/zerolog"
"github.com/stretchr/testify/assert"
)
func pseudoGetLocalVersion() (systemVersion *semver.Version, appVersion *semver.Version, err error) {
systemVersion = semver.MustParse("0.2.5")
appVersion = semver.MustParse("0.4.7")
return systemVersion, appVersion, nil
}
func newOtaState() *State {
logger := zerolog.New(os.Stdout).Level(zerolog.TraceLevel)
otaState := NewState(Options{
SkipConfirmSystem: true,
Logger: &logger,
ReleaseAPIEndpoint: "https://api.jetkvm.com/releases",
GetHTTPClient: func() *http.Client {
transport := http.DefaultTransport.(*http.Transport).Clone()
client := &http.Client{
Transport: transport,
}
return client
},
GetLocalVersion: pseudoGetLocalVersion,
HwReboot: func(force bool, postRebootAction *PostRebootAction, delay time.Duration) error { return nil },
ResetConfig: func() error { return nil },
OnStateUpdate: func(state *RPCState) {},
OnProgressUpdate: func(progress float32) {},
})
return otaState
}
func TestCheckUpdateComponents(t *testing.T) {
otaState := newOtaState()
updateParams := UpdateParams{
DeviceID: "test",
IncludePreRelease: false,
SystemTargetVersion: "0.2.2",
Components: []string{"system"},
}
info, err := otaState.GetUpdateStatus(context.Background(), updateParams)
t.Logf("update status: %+v", info)
if err != nil {
t.Fatalf("failed to check update: %v", err)
}
assert.True(t, info.SystemUpdateAvailable)
assert.False(t, info.AppUpdateAvailable)
}

View File

@ -203,7 +203,6 @@ type Options struct {
HwReboot HwRebootFunc
ReleaseAPIEndpoint string
ResetConfig ResetConfigFunc
SkipConfirmSystem bool
}
// NewState creates a new OTA state
@ -222,9 +221,7 @@ func NewState(opts Options) *State {
releaseAPIEndpoint: opts.ReleaseAPIEndpoint,
resetConfig: opts.ResetConfig,
}
if !opts.SkipConfirmSystem {
go s.confirmCurrentSystem()
}
return s
}

4
ota.go
View File

@ -91,7 +91,7 @@ func getUpdateStatus(includePreRelease bool) (*ota.UpdateStatus, error) {
updateStatus.Error = err.Error()
}
otaLogger.Info().Interface("updateStatus", updateStatus).Msg("Update status")
logger.Info().Interface("updateStatus", updateStatus).Msg("Update status")
return updateStatus, nil
}
@ -189,7 +189,7 @@ func rpcTryUpdateComponents(params updateParams, includePreRelease bool, resetCo
go func() {
err := otaState.TryUpdate(context.Background(), updateParams)
if err != nil {
otaLogger.Warn().Err(err).Msg("failed to try update")
logger.Warn().Err(err).Msg("failed to try update")
}
}()
return nil

View File

@ -603,9 +603,6 @@ export interface UpdateState {
updateErrorMessage: string | null;
setUpdateErrorMessage: (errorMessage: string) => void;
shouldReload: boolean;
setShouldReload: (reloadRequired: boolean) => void;
}
export const useUpdateStore = create<UpdateState>(set => ({
@ -643,9 +640,6 @@ export const useUpdateStore = create<UpdateState>(set => ({
updateErrorMessage: null,
setUpdateErrorMessage: (errorMessage: string) =>
set({ updateErrorMessage: errorMessage }),
shouldReload: false,
setShouldReload: (reloadRequired: boolean) => set({ shouldReload: reloadRequired }),
}));
export type UsbConfigModalViews = "updateUsbConfig" | "updateUsbConfigSuccess";

View File

@ -19,7 +19,7 @@ export default function SettingsGeneralUpdateRoute() {
const [searchParams] = useSearchParams();
const { updateSuccess } = location.state || {};
const { setModalView, otaState, shouldReload, setShouldReload } = useUpdateStore();
const { setModalView, otaState } = useUpdateStore();
const { send } = useJsonRpc();
const customAppVersion = useMemo(() => searchParams.get("custom_app_version") || undefined, [searchParams]);
@ -28,19 +28,15 @@ export default function SettingsGeneralUpdateRoute() {
const onClose = useCallback(async () => {
navigate(".."); // back to the devices.$id.settings page
if (shouldReload) {
setShouldReload(false);
await sleep(1000); // Add 1s delay between navigation and calling reload() to prevent reload from interrupting the navigation.
// Add 1s delay between navigation and calling reload() to prevent reload from interrupting the navigation.
await sleep(1000);
window.location.reload(); // force a full reload to ensure the current device/cloud UI version is loaded
}
}, [navigate, setShouldReload, shouldReload]);
}, [navigate]);
const onConfirmUpdate = useCallback(() => {
setShouldReload(true);
send("tryUpdate", {});
setModalView("updating");
}, [send, setModalView, setShouldReload]);
}, [send, setModalView]);
const onConfirmCustomUpdate = useCallback((appTargetVersion?: string, systemTargetVersion?: string) => {
const components = [];
@ -101,9 +97,10 @@ export function Dialog({
const { modalView, setModalView, otaState } = useUpdateStore();
const forceCustomUpdate = customSystemVersion !== undefined || customAppVersion !== undefined;
const onConfirmCustomUpdate = useCallback(() => {
console.debug("onConfirmCustomUpdate", customAppVersion, customSystemVersion, versionInfo);
onConfirmCustomUpdateCallback(
customAppVersion !== undefined ? versionInfo?.remote?.appVersion : undefined,
customSystemVersion !== undefined ? versionInfo?.remote?.systemVersion : undefined,
customAppVersion !== undefined ? customAppVersion : versionInfo?.remote?.appVersion,
customSystemVersion !== undefined ? customSystemVersion : versionInfo?.remote?.systemVersion,
);
}, [onConfirmCustomUpdateCallback, customAppVersion, customSystemVersion, versionInfo]);

4
web.go
View File

@ -814,7 +814,7 @@ func handleSendWOLMagicPacket(c *gin.Context) {
inputMacAddr := c.Param("mac-addr")
macAddr, err := net.ParseMAC(inputMacAddr)
if err != nil {
logger.Warn().Err(err).Str("inputMacAddr", inputMacAddr).Msg("Invalid MAC address provided")
logger.Warn().Err(err).Str("sendWol", inputMacAddr).Msg("Invalid mac address provided")
c.String(http.StatusBadRequest, "Invalid mac address provided")
return
}
@ -822,7 +822,7 @@ func handleSendWOLMagicPacket(c *gin.Context) {
macAddrString := macAddr.String()
err = rpcSendWOLMagicPacket(macAddrString)
if err != nil {
logger.Warn().Err(err).Str("macAddrString", macAddrString).Msg("Failed to send WOL magic packet")
logger.Warn().Err(err).Str("sendWOL", macAddrString).Msg("Failed to send WOL magic packet")
c.String(http.StatusInternalServerError, "Failed to send WOL to %s: %v", macAddrString, err)
return
}