diff --git a/ui/webui/src/actions/storage-actions.js b/ui/webui/src/actions/storage-actions.js index 0da381051af7..0fe525b2279e 100644 --- a/ui/webui/src/actions/storage-actions.js +++ b/ui/webui/src/actions/storage-actions.js @@ -40,9 +40,8 @@ export const getDevicesAction = () => { return async (dispatch) => { try { const devices = await getDevices(); - const devicesData = await Promise.all(devices[0].map(async (device) => { - let devData = await getDeviceData({ disk: device }); - devData = devData[0]; + const devicesData = await Promise.all(devices.map(async (device) => { + const devData = await getDeviceData({ disk: device }); const free = await getDiskFreeSpace({ diskNames: [device] }); // extend it with variants to keep the format consistent @@ -81,7 +80,7 @@ export const getDiskSelectionAction = () => { diskSelection: { ignoredDisks: diskSelection[0].IgnoredDisks.v, selectedDisks: diskSelection[0].SelectedDisks.v, - usableDisks: usableDisks[0], + usableDisks, } }, }); @@ -102,7 +101,7 @@ export const getPartitioningDataAction = ({ requests, partitioning }) => { if (props.method === "MANUAL") { const reqs = await gatherRequests({ partitioning }); - props.requests = convertRequests(reqs[0]); + props.requests = convertRequests(reqs); } } else { props.requests = convertRequests(requests); diff --git a/ui/webui/src/apis/boss.js b/ui/webui/src/apis/boss.js index a90332c48612..bcadedafc7a9 100644 --- a/ui/webui/src/apis/boss.js +++ b/ui/webui/src/apis/boss.js @@ -17,6 +17,12 @@ import cockpit from "cockpit"; +const OBJECT_PATH = "/org/fedoraproject/Anaconda/Boss"; +const INTERFACE_NAME = "org.fedoraproject.Anaconda.Boss"; +const callClient = (...args) => { + return new BossClient().client.call(OBJECT_PATH, INTERFACE_NAME, ...args).then(res => res?.[0]); +}; + /** * @param {string} address Anaconda bus address * @@ -33,7 +39,7 @@ export class BossClient { BossClient.instance = this; this.client = cockpit.dbus( - "org.fedoraproject.Anaconda.Boss", + INTERFACE_NAME, { superuser: "try", bus: "none", address } ); this.address = address; @@ -63,21 +69,12 @@ export const getSteps = ({ task }) => { * @returns {Promise} Resolves a list of tasks */ export const installWithTasks = () => { - return new BossClient().client.call( - "/org/fedoraproject/Anaconda/Boss", - "org.fedoraproject.Anaconda.Boss", - "InstallWithTasks", [] - ) - .then(ret => ret[0]); + return callClient("InstallWithTasks", []); }; /** * @param {string} locale Locale id */ export const setLocale = ({ locale }) => { - return new BossClient().client.call( - "/org/fedoraproject/Anaconda/Boss", - "org.fedoraproject.Anaconda.Boss", - "SetLocale", [locale] - ); + return callClient("SetLocale", [locale]); }; diff --git a/ui/webui/src/apis/localization.js b/ui/webui/src/apis/localization.js index 130124ed4eee..e0d5e1fc6b28 100644 --- a/ui/webui/src/apis/localization.js +++ b/ui/webui/src/apis/localization.js @@ -20,6 +20,22 @@ import cockpit from "cockpit"; import { getLanguageAction, getLanguagesAction } from "../actions/localization-actions.js"; import { debug } from "../helpers/log.js"; +const OBJECT_PATH = "/org/fedoraproject/Anaconda/Modules/Localization"; +const INTERFACE_NAME = "org.fedoraproject.Anaconda.Modules.Localization"; +const callClient = (...args) => { + return new LocalizationClient().client.call(OBJECT_PATH, INTERFACE_NAME, ...args).then(res => res[0]); +}; +const setProperty = (...args) => { + return new LocalizationClient().client.call( + OBJECT_PATH, "org.freedesktop.DBus.Properties", "Set", [INTERFACE_NAME, ...args] + ); +}; +const getProperty = (...args) => { + return new LocalizationClient().client.call( + OBJECT_PATH, "org.freedesktop.DBus.Properties", "Get", [INTERFACE_NAME, ...args] + ).then(res => res[0].v); +}; + export class LocalizationClient { constructor (address) { if (LocalizationClient.instance && (!address || LocalizationClient.instance.address === address)) { @@ -31,7 +47,7 @@ export class LocalizationClient { LocalizationClient.instance = this; this.client = cockpit.dbus( - "org.fedoraproject.Anaconda.Modules.Localization", + INTERFACE_NAME, { superuser: "try", bus: "none", address } ); this.address = address; @@ -46,29 +62,14 @@ export class LocalizationClient { * @returns {Promise} Resolves a list of language ids */ export const getLanguages = () => { - return ( - new LocalizationClient().client.call( - "/org/fedoraproject/Anaconda/Modules/Localization", - "org.fedoraproject.Anaconda.Modules.Localization", - "GetLanguages", [] - ) - .then(res => res[0]) - ); + return callClient("GetLanguages", []); }; /** * @returns {Promise} The language the system will use */ export const getLanguage = () => { - return ( - new LocalizationClient().client.call( - "/org/fedoraproject/Anaconda/Modules/Localization", - "org.freedesktop.DBus.Properties", - "Get", - ["org.fedoraproject.Anaconda.Modules.Localization", "Language"] - ) - .then(res => res[0].v) - ); + return getProperty("Language"); }; /** @@ -77,14 +78,7 @@ export const getLanguage = () => { * @returns {Promise} Resolves a language data object */ export const getLanguageData = ({ lang }) => { - return ( - new LocalizationClient().client.call( - "/org/fedoraproject/Anaconda/Modules/Localization", - "org.fedoraproject.Anaconda.Modules.Localization", - "GetLanguageData", [lang] - ) - .then(res => res[0]) - ); + return callClient("GetLanguageData", [lang]); }; /** @@ -93,28 +87,14 @@ export const getLanguageData = ({ lang }) => { * @returns {Promise} Resolves a list of locales ids */ export const getLocales = ({ lang }) => { - return ( - new LocalizationClient().client.call( - "/org/fedoraproject/Anaconda/Modules/Localization", - "org.fedoraproject.Anaconda.Modules.Localization", - "GetLocales", [lang] - ) - .then(res => res[0]) - ); + return callClient("GetLocales", [lang]); }; /** * @returns {Promise} Resolves a list of common locales id's. */ export const getCommonLocales = () => { - return ( - new LocalizationClient().client.call( - "/org/fedoraproject/Anaconda/Modules/Localization", - "org.fedoraproject.Anaconda.Modules.Localization", - "GetCommonLocales" - ) - .then(res => res[0]) - ); + return callClient("GetCommonLocales"); }; /** @@ -123,32 +103,14 @@ export const getCommonLocales = () => { * @returns {Promise} Resolves a locale data object */ export const getLocaleData = ({ locale }) => { - return ( - new LocalizationClient().client.call( - "/org/fedoraproject/Anaconda/Modules/Localization", - "org.fedoraproject.Anaconda.Modules.Localization", - "GetLocaleData", [locale] - ) - .then(res => res[0]) - ); + return callClient("GetLocaleData", [locale]); }; /** * @param {string} lang Language id */ export const setLanguage = ({ lang }) => { - return ( - new LocalizationClient().client.call( - "/org/fedoraproject/Anaconda/Modules/Localization", - "org.freedesktop.DBus.Properties", - "Set", - [ - "org.fedoraproject.Anaconda.Modules.Localization", - "Language", - cockpit.variant("s", lang) - ] - ) - ); + return setProperty("Language", cockpit.variant("s", lang)); }; export const startEventMonitorLocalization = ({ dispatch }) => { @@ -157,7 +119,7 @@ export const startEventMonitorLocalization = ({ dispatch }) => { (path, iface, signal, args) => { switch (signal) { case "PropertiesChanged": - if (args[0] === "org.fedoraproject.Anaconda.Modules.Localization" && Object.hasOwn(args[1], "Language")) { + if (args[0] === INTERFACE_NAME && Object.hasOwn(args[1], "Language")) { dispatch(getLanguageAction()); } else { debug(`Unhandled signal on ${path}: ${iface}.${signal}`, JSON.stringify(args)); diff --git a/ui/webui/src/apis/network.js b/ui/webui/src/apis/network.js index 7954aceedead..c794c91972c2 100644 --- a/ui/webui/src/apis/network.js +++ b/ui/webui/src/apis/network.js @@ -20,6 +20,14 @@ import cockpit from "cockpit"; import { getConnectedAction } from "../actions/network-actions.js"; import { debug } from "../helpers/log.js"; +const OBJECT_PATH = "/org/fedoraproject/Anaconda/Modules/Network"; +const INTERFACE_NAME = "org.fedoraproject.Anaconda.Modules.Network"; +const getProperty = (...args) => { + return new NetworkClient().client.call( + OBJECT_PATH, "org.freedesktop.DBus.Properties", "Get", [INTERFACE_NAME, ...args] + ).then(res => res[0].v); +}; + export class NetworkClient { constructor (address) { if (NetworkClient.instance && (!address || NetworkClient.instance.address === address)) { @@ -31,7 +39,7 @@ export class NetworkClient { NetworkClient.instance = this; this.client = cockpit.dbus( - "org.fedoraproject.Anaconda.Modules.Network", + INTERFACE_NAME, { superuser: "try", bus: "none", address } ); this.address = address; @@ -46,15 +54,7 @@ export class NetworkClient { * @returns {Promise} The bool state of the network connection */ export const getConnected = () => { - return ( - new NetworkClient().client.call( - "/org/fedoraproject/Anaconda/Modules/Network", - "org.freedesktop.DBus.Properties", - "Get", - ["org.fedoraproject.Anaconda.Modules.Network", "Connected"] - ) - .then(res => res[0].v) - ); + return getProperty("Connected"); }; export const startEventMonitorNetwork = ({ dispatch }) => { @@ -63,7 +63,7 @@ export const startEventMonitorNetwork = ({ dispatch }) => { (path, iface, signal, args) => { switch (signal) { case "PropertiesChanged": - if (args[0] === "org.fedoraproject.Anaconda.Modules.Network" && Object.hasOwn(args[1], "Connected")) { + if (args[0] === INTERFACE_NAME && Object.hasOwn(args[1], "Connected")) { dispatch(getConnectedAction()); } else { debug(`Unhandled signal on ${path}: ${iface}.${signal}`, JSON.stringify(args)); diff --git a/ui/webui/src/apis/payloads.js b/ui/webui/src/apis/payloads.js index 0a36b7991cea..a1933cc0904d 100644 --- a/ui/webui/src/apis/payloads.js +++ b/ui/webui/src/apis/payloads.js @@ -16,6 +16,12 @@ */ import cockpit from "cockpit"; +const OBJECT_PATH = "/org/fedoraproject/Anaconda/Modules/Payloads"; +const INTERFACE_NAME = "org.fedoraproject.Anaconda.Modules.Payloads"; +const callClient = (...args) => { + return new PayloadsClient().client.call(OBJECT_PATH, INTERFACE_NAME, ...args).then(res => res[0]); +}; + export class PayloadsClient { constructor (address) { if (PayloadsClient.instance && (!address || PayloadsClient.instance.address === address)) { @@ -27,7 +33,7 @@ export class PayloadsClient { PayloadsClient.instance = this; this.client = cockpit.dbus( - "org.fedoraproject.Anaconda.Modules.Payloads", + INTERFACE_NAME, { superuser: "try", bus: "none", address } ); this.address = address; @@ -45,10 +51,5 @@ export class PayloadsClient { * @returns {Promise} Resolves the total space required by the payload */ export const getRequiredSpace = () => { - return new PayloadsClient().client.call( - "/org/fedoraproject/Anaconda/Modules/Payloads", - "org.fedoraproject.Anaconda.Modules.Payloads", - "CalculateRequiredSpace", [] - ) - .then(res => res[0]); + return callClient("CalculateRequiredSpace", []); }; diff --git a/ui/webui/src/apis/runtime.js b/ui/webui/src/apis/runtime.js index 6576e2cfaf67..afaf4823bee0 100644 --- a/ui/webui/src/apis/runtime.js +++ b/ui/webui/src/apis/runtime.js @@ -20,6 +20,14 @@ import cockpit from "cockpit"; import { getPasswordPoliciesAction } from "../actions/runtime-actions.js"; import { debug } from "../helpers/log.js"; +const OBJECT_PATH = "/org/fedoraproject/Anaconda/Modules/Runtime/UserInterface"; +const INTERFACE_NAME = "org.fedoraproject.Anaconda.Modules.Runtime.UserInterface"; +const getProperty = (...args) => { + return new RuntimeClient().client.call( + OBJECT_PATH, "org.freedesktop.DBus.Properties", "Get", [INTERFACE_NAME, ...args] + ); +}; + export class RuntimeClient { constructor (address) { if (RuntimeClient.instance && (!address || RuntimeClient.instance.address === address)) { @@ -49,18 +57,7 @@ export class RuntimeClient { * @returns {Promise} Reports if the given OS release is considered final */ export const getIsFinal = () => { - return ( - new RuntimeClient().client.call( - "/org/fedoraproject/Anaconda/Modules/Runtime/UserInterface", - "org.freedesktop.DBus.Properties", - "Get", - [ - "org.fedoraproject.Anaconda.Modules.Runtime.UserInterface", - "IsFinal", - ] - ) - .then(res => res[0].v) - ); + return getProperty("IsFinal").then(res => res[0].v); }; /** @@ -68,18 +65,7 @@ export const getIsFinal = () => { * @returns {Promise} Returns the password policies */ export const getPasswordPolicies = () => { - return ( - new RuntimeClient().client.call( - "/org/fedoraproject/Anaconda/Modules/Runtime/UserInterface", - "org.freedesktop.DBus.Properties", - "Get", - [ - "org.fedoraproject.Anaconda.Modules.Runtime.UserInterface", - "PasswordPolicies", - ] - ) - .then(res => res[0].v) - ); + return getProperty("PasswordPolicies").then(res => res[0].v); }; export const startEventMonitorRuntime = ({ dispatch }) => { @@ -88,7 +74,7 @@ export const startEventMonitorRuntime = ({ dispatch }) => { (path, iface, signal, args) => { switch (signal) { case "PropertiesChanged": - if (args[0] === "org.fedoraproject.Anaconda.Modules.Runtime.UserInterface" && Object.hasOwn(args[1], "PasswordPolicies")) { + if (args[0] === INTERFACE_NAME && Object.hasOwn(args[1], "PasswordPolicies")) { dispatch(getPasswordPoliciesAction()); } else { debug(`Unhandled signal on ${path}: ${iface}.${signal}`, JSON.stringify(args)); diff --git a/ui/webui/src/apis/storage.js b/ui/webui/src/apis/storage.js index 31ed342629d4..d11963e6a43c 100644 --- a/ui/webui/src/apis/storage.js +++ b/ui/webui/src/apis/storage.js @@ -24,6 +24,18 @@ import { import { debug } from "../helpers/log.js"; +const INTERFACE_NAME = "org.fedoraproject.Anaconda.Modules.Storage"; +const OBJECT_PATH = "/org/fedoraproject/Anaconda/Modules/Storage"; +const callClient = (...args) => { + return new StorageClient().client.call(OBJECT_PATH, INTERFACE_NAME, ...args) + .then(res => res[0]); +}; +const getProperty = (...args) => { + return new StorageClient().client.call( + OBJECT_PATH, "org.freedesktop.DBus.Properties", "Get", [INTERFACE_NAME, ...args] + ).then(res => res[0].v); +}; + export class StorageClient { constructor (address) { if (StorageClient.instance && (!address || StorageClient.instance.address === address)) { @@ -35,7 +47,7 @@ export class StorageClient { StorageClient.instance = this; this.client = cockpit.dbus( - "org.fedoraproject.Anaconda.Modules.Storage", + INTERFACE_NAME, { superuser: "try", bus: "none", address } ); this.address = address; @@ -80,11 +92,7 @@ export const runStorageTask = ({ task, onSuccess, onFail }) => { * @returns {Promise} Resolves a DBus path to a task */ export const scanDevicesWithTask = () => { - return new StorageClient().client.call( - "/org/fedoraproject/Anaconda/Modules/Storage", - "org.fedoraproject.Anaconda.Modules.Storage", - "ScanDevicesWithTask", [] - ); + return callClient("ScanDevicesWithTask", []); }; export const startEventMonitorStorage = ({ dispatch }) => { @@ -97,7 +105,7 @@ export const startEventMonitorStorage = ({ dispatch }) => { dispatch(getDiskSelectionAction()); } else if (args[0] === "org.fedoraproject.Anaconda.Modules.Storage.Partitioning.Manual" && Object.hasOwn(args[1], "Requests")) { dispatch(getPartitioningDataAction({ requests: args[1].Requests.v, partitioning: path })); - } else if (args[0] === "org.fedoraproject.Anaconda.Modules.Storage" && Object.hasOwn(args[1], "CreatedPartitioning")) { + } else if (args[0] === INTERFACE_NAME && Object.hasOwn(args[1], "CreatedPartitioning")) { const last = args[1].CreatedPartitioning.v.length - 1; dispatch(getPartitioningDataAction({ partitioning: args[1].CreatedPartitioning.v[last] })); } else { @@ -111,18 +119,10 @@ export const startEventMonitorStorage = ({ dispatch }) => { }; export const initDataStorage = ({ dispatch }) => { - return new StorageClient().client.call( - "/org/fedoraproject/Anaconda/Modules/Storage", - "org.freedesktop.DBus.Properties", - "Get", - [ - "org.fedoraproject.Anaconda.Modules.Storage", - "CreatedPartitioning", - ] - ) - .then(([res]) => { - if (res.v.length !== 0) { - return Promise.all(res.v.map(path => dispatch(getPartitioningDataAction({ partitioning: path })))); + return getProperty("CreatedPartitioning") + .then(res => { + if (res.length !== 0) { + return Promise.all(res.map(path => dispatch(getPartitioningDataAction({ partitioning: path })))); } }) .then(() => dispatch(getDevicesAction())) diff --git a/ui/webui/src/apis/storage_bootloader.js b/ui/webui/src/apis/storage_bootloader.js index 6443d0ff01d2..62287977a9da 100644 --- a/ui/webui/src/apis/storage_bootloader.js +++ b/ui/webui/src/apis/storage_bootloader.js @@ -17,18 +17,17 @@ import cockpit from "cockpit"; import { StorageClient } from "./storage.js"; +const INTERFACE_NAME = "org.fedoraproject.Anaconda.Modules.Storage.Bootloader"; +const OBJECT_PATH = "/org/fedoraproject/Anaconda/Modules/Storage/Bootloader"; +const setProperty = (...args) => { + return new StorageClient().client.call( + OBJECT_PATH, "org.freedesktop.DBus.Properties", "Set", [INTERFACE_NAME, ...args] + ); +}; + /** * @param {string} drive A drive name */ export const setBootloaderDrive = ({ drive }) => { - return new StorageClient().client.call( - "/org/fedoraproject/Anaconda/Modules/Storage/Bootloader", - "org.freedesktop.DBus.Properties", - "Set", - [ - "org.fedoraproject.Anaconda.Modules.Storage.Bootloader", - "Drive", - cockpit.variant("s", drive) - ] - ); + return setProperty("Drive", cockpit.variant("s", drive)); }; diff --git a/ui/webui/src/apis/storage_devicetree.js b/ui/webui/src/apis/storage_devicetree.js index 2b38c32b579c..e6371a6038e8 100644 --- a/ui/webui/src/apis/storage_devicetree.js +++ b/ui/webui/src/apis/storage_devicetree.js @@ -16,6 +16,17 @@ */ import { StorageClient } from "./storage.js"; +const INTERFACE_NAME_VIEWER = "org.fedoraproject.Anaconda.Modules.Storage.DeviceTree.Viewer"; +const INTERFACE_NAME_HANDLER = "org.fedoraproject.Anaconda.Modules.Storage.DeviceTree.Handler"; +const OBJECT_PATH = "/org/fedoraproject/Anaconda/Modules/Storage/DeviceTree"; + +const callViewer = (...args) => { + return new StorageClient().client.call(OBJECT_PATH, INTERFACE_NAME_VIEWER, ...args).then(res => res[0]); +}; +const callHandler = (...args) => { + return new StorageClient().client.call(OBJECT_PATH, INTERFACE_NAME_HANDLER, ...args).then(res => res[0]); +}; + /** * @param {string} deviceName A device name * @param {string} password A password @@ -23,11 +34,7 @@ import { StorageClient } from "./storage.js"; * @returns {Promise} Resolves true if success otherwise false */ export const unlockDevice = ({ deviceName, passphrase }) => { - return new StorageClient().client.call( - "/org/fedoraproject/Anaconda/Modules/Storage/DeviceTree", - "org.fedoraproject.Anaconda.Modules.Storage.DeviceTree.Handler", - "UnlockDevice", [deviceName, passphrase] - ); + return callHandler("UnlockDevice", [deviceName, passphrase]); }; /** @@ -36,11 +43,7 @@ export const unlockDevice = ({ deviceName, passphrase }) => { * @returns {Promise} Resolves an object with the device data */ export const getDeviceData = ({ disk }) => { - return new StorageClient().client.call( - "/org/fedoraproject/Anaconda/Modules/Storage/DeviceTree", - "org.fedoraproject.Anaconda.Modules.Storage.DeviceTree.Viewer", - "GetDeviceData", [disk] - ); + return callViewer("GetDeviceData", [disk]); }; /** @@ -49,12 +52,7 @@ export const getDeviceData = ({ disk }) => { * @returns {Promise} Resolves the total free space on the given disks */ export const getDiskFreeSpace = ({ diskNames }) => { - return new StorageClient().client.call( - "/org/fedoraproject/Anaconda/Modules/Storage/DeviceTree", - "org.fedoraproject.Anaconda.Modules.Storage.DeviceTree.Viewer", - "GetDiskFreeSpace", [diskNames] - ) - .then(res => res[0]); + return callViewer("GetDiskFreeSpace", [diskNames]); }; /** @@ -63,12 +61,7 @@ export const getDiskFreeSpace = ({ diskNames }) => { * @returns {Promise} Resolves the device format data */ export const getFormatData = ({ diskName }) => { - return new StorageClient().client.call( - "/org/fedoraproject/Anaconda/Modules/Storage/DeviceTree", - "org.fedoraproject.Anaconda.Modules.Storage.DeviceTree.Viewer", - "GetFormatData", [diskName] - ) - .then(res => res[0]); + return callViewer("GetFormatData", [diskName]); }; /** @@ -77,24 +70,14 @@ export const getFormatData = ({ diskName }) => { * @returns {Promise} Resolves the total free space on the given disks */ export const getRequiredDeviceSize = ({ requiredSpace }) => { - return new StorageClient().client.call( - "/org/fedoraproject/Anaconda/Modules/Storage/DeviceTree", - "org.fedoraproject.Anaconda.Modules.Storage.DeviceTree.Viewer", - "GetRequiredDeviceSize", [requiredSpace] - ) - .then(res => res[0]); + return callViewer("GetRequiredDeviceSize", [requiredSpace]); }; /** * @returns {Promise} List of all mount points required on the platform */ export const getRequiredMountPoints = () => { - return new StorageClient().client.call( - "/org/fedoraproject/Anaconda/Modules/Storage/DeviceTree", - "org.fedoraproject.Anaconda.Modules.Storage.DeviceTree.Viewer", - "GetRequiredMountPoints", [] - ) - .then(res => res[0]); + return callViewer("GetRequiredMountPoints", []); }; /** @@ -103,21 +86,12 @@ export const getRequiredMountPoints = () => { * @returns {Promise} Resolves the total space on the given disks */ export const getDiskTotalSpace = ({ diskNames }) => { - return new StorageClient().client.call( - "/org/fedoraproject/Anaconda/Modules/Storage/DeviceTree", - "org.fedoraproject.Anaconda.Modules.Storage.DeviceTree.Viewer", - "GetDiskTotalSpace", [diskNames] - ) - .then(res => res[0]); + return callViewer("GetDiskTotalSpace", [diskNames]); }; /** * @returns {Promise} Resolves all devices in a device tree */ export const getDevices = () => { - return new StorageClient().client.call( - "/org/fedoraproject/Anaconda/Modules/Storage/DeviceTree", - "org.fedoraproject.Anaconda.Modules.Storage.DeviceTree.Viewer", - "GetDevices", [] - ); + return callViewer("GetDevices", []); }; diff --git a/ui/webui/src/apis/storage_disk_initialization.js b/ui/webui/src/apis/storage_disk_initialization.js index 2d5eb777c625..d3158578c518 100644 --- a/ui/webui/src/apis/storage_disk_initialization.js +++ b/ui/webui/src/apis/storage_disk_initialization.js @@ -20,52 +20,36 @@ import { StorageClient, } from "./storage.js"; +const INTERFACE_NAME = "org.fedoraproject.Anaconda.Modules.Storage.DiskInitialization"; +const OBJECT_PATH = "/org/fedoraproject/Anaconda/Modules/Storage/DiskInitialization"; +const getProperty = (...args) => { + return new StorageClient().client.call( + OBJECT_PATH, "org.freedesktop.DBus.Properties", "Get", [INTERFACE_NAME, ...args] + ).then(res => res[0]); +}; +const setProperty = (...args) => { + return new StorageClient().client.call( + OBJECT_PATH, "org.freedesktop.DBus.Properties", "Set", [INTERFACE_NAME, ...args] + ); +}; + /** * @returns {Promise} The number of the mode */ export const getInitializationMode = () => { - return ( - new StorageClient().client.call( - "/org/fedoraproject/Anaconda/Modules/Storage/DiskInitialization", - "org.freedesktop.DBus.Properties", - "Get", - [ - "org.fedoraproject.Anaconda.Modules.Storage.DiskInitialization", - "InitializationMode", - ] - ) - .then(res => res[0].v) - ); + return getProperty("InitializationMode"); }; /** * @param {int} mode The number of the mode */ export const setInitializationMode = ({ mode }) => { - return new StorageClient().client.call( - "/org/fedoraproject/Anaconda/Modules/Storage/DiskInitialization", - "org.freedesktop.DBus.Properties", - "Set", - [ - "org.fedoraproject.Anaconda.Modules.Storage.DiskInitialization", - "InitializationMode", - cockpit.variant("i", mode) - ] - ); + return setProperty("InitializationMode", cockpit.variant("i", mode)); }; /** * @param {boolean} enabled True if allowed, otherwise False */ export const setInitializeLabelsEnabled = ({ enabled }) => { - return new StorageClient().client.call( - "/org/fedoraproject/Anaconda/Modules/Storage/DiskInitialization", - "org.freedesktop.DBus.Properties", - "Set", - [ - "org.fedoraproject.Anaconda.Modules.Storage.DiskInitialization", - "InitializeLabelsEnabled", - cockpit.variant("b", enabled) - ] - ); + return setProperty("InitializeLabelsEnabled", cockpit.variant("b", enabled)); }; diff --git a/ui/webui/src/apis/storage_disks_selection.js b/ui/webui/src/apis/storage_disks_selection.js index a6e51ec88bca..839e6624a94a 100644 --- a/ui/webui/src/apis/storage_disks_selection.js +++ b/ui/webui/src/apis/storage_disks_selection.js @@ -20,59 +20,45 @@ import { StorageClient, } from "./storage.js"; +const INTERFACE_NAME = "org.fedoraproject.Anaconda.Modules.Storage.DiskSelection"; +const OBJECT_PATH = "/org/fedoraproject/Anaconda/Modules/Storage/DiskSelection"; +const callClient = (...args) => { + return new StorageClient().client.call(OBJECT_PATH, INTERFACE_NAME, ...args).then(res => res[0]); +}; +const setProperty = (...args) => { + return new StorageClient().client.call( + OBJECT_PATH, "org.freedesktop.DBus.Properties", "Set", [INTERFACE_NAME, ...args] + ); +}; +const getProperty = (...args) => { + return new StorageClient().client.call( + OBJECT_PATH, "org.freedesktop.DBus.Properties", "Get", [INTERFACE_NAME, ...args] + ).then(res => res[0].v); +}; /** * @returns {Promise} Resolves all properties of DiskSelection interface */ export const getAllDiskSelection = () => { - return new StorageClient().client.call( - "/org/fedoraproject/Anaconda/Modules/Storage/DiskSelection", - "org.freedesktop.DBus.Properties", - "GetAll", - ["org.fedoraproject.Anaconda.Modules.Storage.DiskSelection"], - ); + return new StorageClient().client.call(OBJECT_PATH, "org.freedesktop.DBus.Properties", "GetAll", [INTERFACE_NAME]); }; /** * @returns {Promise} Resolves a list with disk names */ export const getUsableDisks = () => { - return new StorageClient().client.call( - "/org/fedoraproject/Anaconda/Modules/Storage/DiskSelection", - "org.fedoraproject.Anaconda.Modules.Storage.DiskSelection", - "GetUsableDisks", [] - ); + return callClient("GetUsableDisks", []); }; /** * @returns {Promise} The list of selected disks */ export const getSelectedDisks = () => { - return ( - new StorageClient().client.call( - "/org/fedoraproject/Anaconda/Modules/Storage/DiskSelection", - "org.freedesktop.DBus.Properties", - "Get", - [ - "org.fedoraproject.Anaconda.Modules.Storage.DiskSelection", - "SelectedDisks" - ] - ) - .then(res => res[0].v) - ); + return getProperty("SelectedDisks"); }; /** * @param {Array.} drives A list of drives names */ export const setSelectedDisks = ({ drives }) => { - return new StorageClient().client.call( - "/org/fedoraproject/Anaconda/Modules/Storage/DiskSelection", - "org.freedesktop.DBus.Properties", - "Set", - [ - "org.fedoraproject.Anaconda.Modules.Storage.DiskSelection", - "SelectedDisks", - cockpit.variant("as", drives) - ] - ); + return setProperty("SelectedDisks", cockpit.variant("as", drives)); }; diff --git a/ui/webui/src/apis/storage_partitioning.js b/ui/webui/src/apis/storage_partitioning.js index 042625543512..aa54eba1c542 100644 --- a/ui/webui/src/apis/storage_partitioning.js +++ b/ui/webui/src/apis/storage_partitioning.js @@ -27,17 +27,28 @@ import { setInitializeLabelsEnabled, } from "./storage_disk_initialization.js"; +const INTERFACE_NAME_STORAGE = "org.fedoraproject.Anaconda.Modules.Storage"; +const INTERFACE_NAME_PARTITIONING = "org.fedoraproject.Anaconda.Modules.Storage.Partitioning"; +const INTERFACE_NAME_PARTITIONING_MANUAL = "org.fedoraproject.Anaconda.Modules.Storage.Partitioning.Manual"; +const INTERFACE_NAME_PARTITIONING_AUTOMATIC = "org.fedoraproject.Anaconda.Modules.Storage.Partitioning.Automatic"; +const OBJECT_PATH = "/org/fedoraproject/Anaconda/Modules/Storage"; +const callClient = (...args) => { + return new StorageClient().client.call(OBJECT_PATH, INTERFACE_NAME_STORAGE, ...args) + .then(res => res[0]); +}; +const getProperty = (...args) => { + return new StorageClient().client.call( + OBJECT_PATH, "org.freedesktop.DBus.Properties", "Get", [INTERFACE_NAME_PARTITIONING, ...args] + ).then(res => res[0].v); +}; + /** * @param {string} partitioning DBus path to a partitioning * * @returns {Promise} Resolves the DBus path to the partitioning */ export const applyPartitioning = ({ partitioning }) => { - return new StorageClient().client.call( - "/org/fedoraproject/Anaconda/Modules/Storage", - "org.fedoraproject.Anaconda.Modules.Storage", - "ApplyPartitioning", [partitioning] - ); + return callClient("ApplyPartitioning", [partitioning]); }; /** @@ -46,11 +57,7 @@ export const applyPartitioning = ({ partitioning }) => { * @returns {Promise} Resolves the DBus path to the partitioning */ export const createPartitioning = ({ method }) => { - return new StorageClient().client.call( - "/org/fedoraproject/Anaconda/Modules/Storage", - "org.fedoraproject.Anaconda.Modules.Storage", - "CreatePartitioning", [method] - ); + return callClient("CreatePartitioning", [method]); }; /** @@ -60,7 +67,7 @@ export const createPartitioning = ({ method }) => { export const partitioningSetPassphrase = ({ partitioning, passphrase }) => { return new StorageClient().client.call( partitioning, - "org.fedoraproject.Anaconda.Modules.Storage.Partitioning.Automatic", + INTERFACE_NAME_PARTITIONING_AUTOMATIC, "SetPassphrase", [passphrase] ); }; @@ -87,7 +94,7 @@ export const getPartitioningRequest = ({ partitioning }) => { "org.freedesktop.DBus.Properties", "Get", [ - "org.fedoraproject.Anaconda.Modules.Storage.Partitioning.Automatic", + INTERFACE_NAME_PARTITIONING_AUTOMATIC, "Request", ] ) @@ -107,7 +114,7 @@ export const getPartitioningMethod = ({ partitioning }) => { "org.freedesktop.DBus.Properties", "Get", [ - "org.fedoraproject.Anaconda.Modules.Storage.Partitioning", + INTERFACE_NAME_PARTITIONING, "PartitioningMethod", ] ) @@ -119,18 +126,7 @@ export const getPartitioningMethod = ({ partitioning }) => { * @returns {Promise} The applied partitioning */ export const getAppliedPartitioning = () => { - return ( - new StorageClient().client.call( - "/org/fedoraproject/Anaconda/Modules/Storage", - "org.freedesktop.DBus.Properties", - "Get", - [ - "org.fedoraproject.Anaconda.Modules.Storage", - "AppliedPartitioning", - ] - ) - .then(res => res[0].v) - ); + return getProperty("AppliedPartitioning"); }; /** @@ -143,7 +139,7 @@ export const setPartitioningRequest = ({ partitioning, request }) => { "org.freedesktop.DBus.Properties", "Set", [ - "org.fedoraproject.Anaconda.Modules.Storage.Partitioning.Automatic", + INTERFACE_NAME_PARTITIONING_AUTOMATIC, "Request", cockpit.variant("a{sv}", request) ] @@ -158,17 +154,13 @@ export const setPartitioningRequest = ({ partitioning, request }) => { export const partitioningConfigureWithTask = ({ partitioning }) => { return new StorageClient().client.call( partitioning, - "org.fedoraproject.Anaconda.Modules.Storage.Partitioning", + INTERFACE_NAME_PARTITIONING, "ConfigureWithTask", [] ); }; export const resetPartitioning = () => { - return new StorageClient().client.call( - "/org/fedoraproject/Anaconda/Modules/Storage", - "org.fedoraproject.Anaconda.Modules.Storage", - "ResetPartitioning", [] - ); + return callClient("ResetPartitioning", []); }; /* @@ -181,7 +173,7 @@ export const setManualPartitioningRequests = ({ partitioning, requests }) => { "org.freedesktop.DBus.Properties", "Set", [ - "org.fedoraproject.Anaconda.Modules.Storage.Partitioning.Manual", + INTERFACE_NAME_PARTITIONING_MANUAL, "Requests", cockpit.variant("aa{sv}", requests) ] @@ -196,17 +188,17 @@ export const setManualPartitioningRequests = ({ partitioning, requests }) => { export const gatherRequests = ({ partitioning }) => { return new StorageClient().client.call( partitioning, - "org.fedoraproject.Anaconda.Modules.Storage.Partitioning.Manual", + INTERFACE_NAME_PARTITIONING_MANUAL, "GatherRequests", [] - ); + ).then(res => res[0]); }; export const applyStorage = async ({ partitioning, encrypt, encryptPassword, onFail, onSuccess }) => { await setInitializeLabelsEnabled({ enabled: true }); await setBootloaderDrive({ drive: "" }); - const [part] = partitioning ? [partitioning] : await createPartitioning({ method: "AUTOMATIC" }); + const part = partitioning || await createPartitioning({ method: "AUTOMATIC" }); if (encrypt) { await partitioningSetEncrypt({ partitioning: part, encrypt }); diff --git a/ui/webui/src/components/storage/EncryptedDevices.jsx b/ui/webui/src/components/storage/EncryptedDevices.jsx index 6cd0c3936861..2aaba8609755 100644 --- a/ui/webui/src/components/storage/EncryptedDevices.jsx +++ b/ui/webui/src/components/storage/EncryptedDevices.jsx @@ -118,11 +118,11 @@ const UnlockDialog = ({ isLoadingNewPartitioning, lockedLUKSDevices, onClose, di ).then( res => { if (res.every(r => r.status === "fulfilled")) { - if (res.every(r => r.value[0])) { + if (res.every(r => r.value)) { onClose(); } else { const unlockedDevs = res.reduce((acc, r, i) => { - if (r.value[0]) { + if (r.value) { acc.push(lockedLUKSDevices[i]); } return acc; diff --git a/ui/webui/src/components/storage/InstallationDestination.jsx b/ui/webui/src/components/storage/InstallationDestination.jsx index 5c2e8580d840..ca2a556ba5da 100644 --- a/ui/webui/src/components/storage/InstallationDestination.jsx +++ b/ui/webui/src/components/storage/InstallationDestination.jsx @@ -285,9 +285,9 @@ const rescanDisks = (setIsRescanningDisks, refUsableDisks, dispatch, errorHandle setIsFormDisabled(true); refUsableDisks.current = undefined; scanDevicesWithTask() - .then(res => { + .then(task => { return runStorageTask({ - task: res[0], + task, onSuccess: () => resetPartitioning() .then(() => Promise.all([ dispatch(getDevicesAction()), diff --git a/ui/webui/src/components/storage/InstallationScenario.jsx b/ui/webui/src/components/storage/InstallationScenario.jsx index da4292fb81d8..96490e895987 100644 --- a/ui/webui/src/components/storage/InstallationScenario.jsx +++ b/ui/webui/src/components/storage/InstallationScenario.jsx @@ -175,7 +175,7 @@ const InstallationScenarioSelector = ({ deviceData, selectedDisks, idPrefix, isF useEffect(() => { getDevices().then(res => { - const _duplicateDeviceNames = findDuplicatesInArray(res[0]); + const _duplicateDeviceNames = findDuplicatesInArray(res); setDuplicateDeviceNames(_duplicateDeviceNames); setIsFormValid(_duplicateDeviceNames.length === 0); }, onCritFail({ context: N_("Failed to get device names.") })); @@ -186,7 +186,7 @@ const InstallationScenarioSelector = ({ deviceData, selectedDisks, idPrefix, isF const diskTotalSpace = await getDiskTotalSpace({ diskNames: selectedDisks }).catch(console.error); const diskFreeSpace = await getDiskFreeSpace({ diskNames: selectedDisks }).catch(console.error); const devices = await getDevices().catch(console.error); - const _duplicateDeviceNames = findDuplicatesInArray(devices[0]); + const _duplicateDeviceNames = findDuplicatesInArray(devices); setDuplicateDeviceNames(_duplicateDeviceNames); setDiskTotalSpace(diskTotalSpace); diff --git a/ui/webui/src/components/storage/MountPointMapping.jsx b/ui/webui/src/components/storage/MountPointMapping.jsx index 23c27c5ad40d..0c4c057048ef 100644 --- a/ui/webui/src/components/storage/MountPointMapping.jsx +++ b/ui/webui/src/components/storage/MountPointMapping.jsx @@ -626,7 +626,7 @@ export const MountPointMapping = ({ setBootloaderDrive({ drive: "" }) .then(() => createPartitioning({ method: "MANUAL" })) .then(path => { - setUsedPartitioning(path[0]); + setUsedPartitioning(path); setReusePartitioning(true); }); }