From 2f2b2e1c504aa1caa1be6000f2e17ecf4b774f41 Mon Sep 17 00:00:00 2001 From: Christina Ying Wang Date: Tue, 12 Nov 2024 22:10:00 -0800 Subject: [PATCH] Don't require reboot if setting fan control Signed-off-by: Christina Ying Wang --- src/config/backends/backend.ts | 6 ++++++ src/config/backends/power-fan.ts | 11 +++++++++++ src/device-config.ts | 7 +++++-- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/config/backends/backend.ts b/src/config/backends/backend.ts index ff9396241..e81b17c80 100644 --- a/src/config/backends/backend.ts +++ b/src/config/backends/backend.ts @@ -41,6 +41,12 @@ export abstract class ConfigBackend { // Example an empty string should return null. public abstract createConfigVarName(configName: string): string | null; + // Is a reboot required for the given config options? + // eslint-disable-next-line @typescript-eslint/no-unused-vars + public async isRebootRequired(_opts: ConfigOptions): Promise { + return true; + } + // Allow a chosen config backend to be initialised public async initialise(): Promise { return this; diff --git a/src/config/backends/power-fan.ts b/src/config/backends/power-fan.ts index 0e99d4317..d0f09f5ee 100644 --- a/src/config/backends/power-fan.ts +++ b/src/config/backends/power-fan.ts @@ -1,6 +1,7 @@ import { isRight } from 'fp-ts/lib/Either'; import Reporter from 'io-ts-reporters'; import * as t from 'io-ts'; +import * as _ from 'lodash'; import { ConfigBackend } from './backend'; import type { ConfigOptions } from './backend'; @@ -145,6 +146,16 @@ export class PowerFanConfig extends ConfigBackend { return PowerFanConfig.CONFIGS.has(PowerFanConfig.stripPrefix(envVar)); } + public async isRebootRequired(opts: ConfigOptions): Promise { + const supportedOpts = _.pickBy( + _.mapKeys(opts, (_value, key) => PowerFanConfig.stripPrefix(key)), + (_value, key) => this.isSupportedConfig(key), + ); + const current = await this.getBootConfig(); + // A reboot is only required if the power mode is changing + return current.power_mode !== supportedOpts.power_mode; + } + public processConfigVarName(envVar: string): string { return PowerFanConfig.stripPrefix(envVar).toLowerCase(); } diff --git a/src/device-config.ts b/src/device-config.ts index 724632bfe..428458014 100644 --- a/src/device-config.ts +++ b/src/device-config.ts @@ -529,18 +529,21 @@ async function getBackendSteps( const { deviceType } = await config.getMany(['deviceType']); // Check for required bootConfig changes + let rebootRequired = false; for (const backend of backends) { if (changeRequired(backend, current, target, deviceType)) { steps.push({ action: 'setBootConfig', target, }); + rebootRequired = + (await backend.isRebootRequired(target)) || rebootRequired; } } return [ - // All backend steps require a reboot - ...(steps.length > 0 + // All backend steps require a reboot except fan control + ...(steps.length > 0 && rebootRequired ? [{ action: 'setRebootBreadcrumb' } as ConfigStep] : []), ...steps,