Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"parserOptions": {
"ecmaVersion": 2022
},
"plugins": ["react", "react-hooks", "simple-import-sort", "sort-destructure-keys"],
"plugins": ["react", "react-hooks", "simple-import-sort", "sort-destructure-keys", "promise"],
"rules": {
"comma-dangle": "off",
"indent": ["error", 4,
Expand Down Expand Up @@ -55,7 +55,10 @@
"react/prop-types": "off",

"react-hooks/exhaustive-deps": "error",
"react-hooks/rules-of-hooks": "error"
"react-hooks/rules-of-hooks": "error",

"promise/prefer-await-to-then": "error",
"promise/prefer-await-to-callbacks": "error"
},
"globals": {
"require": false,
Expand Down
2 changes: 1 addition & 1 deletion build.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function watchDirs (dir, onChange) {
}
onChange(path.join(dir, fname));
};

// eslint-disable-next-line promise/prefer-await-to-callbacks
fs.watch(dir, {}, (ev, path) => callback(ev, dir, path));

// watch all subdirectories in dir
Expand Down
8 changes: 4 additions & 4 deletions src/apis/boss.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@ export class BossClient {
*
* @returns {Promise} Resolves the total number of tasks
*/
export const getSteps = ({ task }) => {
return new BossClient().client.call(
export const getSteps = async ({ task }) => {
const ret = await new BossClient().client.call(
task,
"org.freedesktop.DBus.Properties",
"Get",
["org.fedoraproject.Anaconda.Task", "Steps"]
)
.then(ret => ret[0]);
);
return ret[0];
};

/**
Expand Down
16 changes: 9 additions & 7 deletions src/apis/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,22 @@
*/
import cockpit from "cockpit";

export const _callClient = (Client, OBJECT_PATH, INTERFACE_NAME, ...args) => {
return new Client().client.call(OBJECT_PATH, INTERFACE_NAME, ...args).then(res => res[0]);
export const _callClient = async (Client, OBJECT_PATH, INTERFACE_NAME, ...args) => {
const res = await new Client().client.call(OBJECT_PATH, INTERFACE_NAME, ...args);
return res[0];
};

export const _setProperty = (Client, OBJECT_PATH, INTERFACE_NAME, ...args) => {
return new Client().client.call(
export const _setProperty = async (Client, OBJECT_PATH, INTERFACE_NAME, ...args) => {
return await new Client().client.call(
OBJECT_PATH, "org.freedesktop.DBus.Properties", "Set", [INTERFACE_NAME, ...args]
);
};

export const _getProperty = (Client, OBJECT_PATH, INTERFACE_NAME, ...args) => {
return new Client().client.call(
export const _getProperty = async (Client, OBJECT_PATH, INTERFACE_NAME, ...args) => {
const res = await new Client().client.call(
OBJECT_PATH, "org.freedesktop.DBus.Properties", "Get", [INTERFACE_NAME, ...args]
).then(res => res[0].v);
);
return res[0].v;
};

/**
Expand Down
16 changes: 14 additions & 2 deletions src/apis/localization.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,25 @@ export const getKeyboardConfiguration = async ({ onFail, onSuccess }) => {
};

const addEventListeners = () => {
taskProxy.addEventListener("Stopped", () => taskProxy.Finish().catch(onFail));
taskProxy.addEventListener("Stopped", async () => {
try {
await taskProxy.Finish();
} catch (error) {
onFail(error);
}
});
taskProxy.addEventListener("Succeeded", getTaskResult);
};

taskProxy.wait(() => {
addEventListeners();
taskProxy.Start().catch(onFail);
(async () => {
try {
await taskProxy.Start();
} catch (error) {
onFail(error);
}
})();
});
};

Expand Down
16 changes: 14 additions & 2 deletions src/apis/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,13 @@ export const runStorageTask = ({ onFail, onSuccess, task }) => {
task
);
const addEventListeners = () => {
taskProxy.addEventListener("Stopped", () => taskProxy.Finish().catch(onFail));
taskProxy.addEventListener("Stopped", async () => {
try {
await taskProxy.Finish();
} catch (error) {
onFail(error);
}
});
taskProxy.addEventListener("Succeeded", () => {
if (succeededEmitted) {
return;
Expand All @@ -129,7 +135,13 @@ export const runStorageTask = ({ onFail, onSuccess, task }) => {
};
taskProxy.wait(() => {
addEventListeners();
taskProxy.Start().catch(onFail);
(async () => {
try {
await taskProxy.Start();
} catch (error) {
onFail(error);
}
})();
});
};

Expand Down
68 changes: 32 additions & 36 deletions src/apis/storage_partitioning.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,14 @@ export const createPartitioning = ({ method }) => {
*
* @returns {Promise} The device tree object
*/
export const getDeviceTree = ({ partitioning }) => {
return new StorageClient().client.call(
export const getDeviceTree = async ({ partitioning }) => {
const res = await new StorageClient().client.call(
partitioning,
INTERFACE_NAME_PARTITIONING,
"GetDeviceTree",
[]
).then(res => res[0]);
);
return res[0];
};

/**
Expand All @@ -94,12 +95,10 @@ export const partitioningSetPassphrase = ({ partitioning, passphrase }) => {
* @param {string} partitioning DBus path to a partitioning
* @param {boolean} encrypt True if partitions should be encrypted, False otherwise
*/
export const partitioningSetEncrypt = ({ encrypt, partitioning }) => {
return getPartitioningRequest({ partitioning })
.then(request => {
request.encrypted = cockpit.variant("b", encrypt);
return setPartitioningRequest({ partitioning, request });
});
export const partitioningSetEncrypt = async ({ encrypt, partitioning }) => {
const request = await getPartitioningRequest({ partitioning });
request.encrypted = cockpit.variant("b", encrypt);
return setPartitioningRequest({ partitioning, request });
};

/* Create DBus request object for home reuse partitioning
Expand Down Expand Up @@ -148,39 +147,35 @@ export const partitioningSetHomeReuse = async ({ homeReuseOptions, partitioning
/**
* @returns {Promise} The request of automatic partitioning
*/
export const getPartitioningRequest = ({ partitioning }) => {
return (
new StorageClient().client.call(
partitioning,
"org.freedesktop.DBus.Properties",
"Get",
[
INTERFACE_NAME_PARTITIONING_AUTOMATIC,
"Request",
]
)
.then(res => res[0].v)
export const getPartitioningRequest = async ({ partitioning }) => {
const res = await new StorageClient().client.call(
partitioning,
"org.freedesktop.DBus.Properties",
"Get",
[
INTERFACE_NAME_PARTITIONING_AUTOMATIC,
"Request",
]
);
return res[0].v;
};

/**
* @param {string} partitioning DBus path to a partitioning
*
* @returns {Promise} The partitioning method
*/
export const getPartitioningMethod = ({ partitioning }) => {
return (
new StorageClient().client.call(
partitioning,
"org.freedesktop.DBus.Properties",
"Get",
[
INTERFACE_NAME_PARTITIONING,
"PartitioningMethod",
]
)
.then(res => res[0].v)
export const getPartitioningMethod = async ({ partitioning }) => {
const res = await new StorageClient().client.call(
partitioning,
"org.freedesktop.DBus.Properties",
"Get",
[
INTERFACE_NAME_PARTITIONING,
"PartitioningMethod",
]
);
return res[0].v;
};

/**
Expand Down Expand Up @@ -273,13 +268,14 @@ export const setManualPartitioningRequests = ({ partitioning, requests }) => {
*
* @returns {Promise} The gathered requests for manual partitioning
*/
export const gatherRequests = ({ partitioning }) => {
return new StorageClient().client.call(
export const gatherRequests = async ({ partitioning }) => {
const res = await new StorageClient().client.call(
partitioning,
INTERFACE_NAME_PARTITIONING_MANUAL,
"GatherRequests",
[]
).then(res => res[0]);
);
return res[0];
};

export const applyStorage = async ({ devices, luks, onFail, onSuccess, partitioning }) => {
Expand Down
12 changes: 8 additions & 4 deletions src/components/AnacondaHeader.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,14 @@ export const AnacondaHeader = ({ currentStepId, dispatch, isFormDisabled, onCrit
const isConnected = network.connected;

useEffect(() => {
getIsFinal().then(
isFinal => setBeta(!isFinal),
onCritFail({ context: N_("Reading installer version information failed.") })
);
(async () => {
try {
const isFinal = await getIsFinal();
setBeta(!isFinal);
} catch {
onCritFail({ context: N_("Reading installer version information failed.") });
}
})();
}, [onCritFail]);

return (
Expand Down
9 changes: 4 additions & 5 deletions src/components/Error.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,10 @@ export const BZReportModal = ({
// Let's make sure we have the latest logs from journal saved to /tmp/journal.log
// Let's not confuse users with syslog
// See https://issues.redhat.com/browse/INSTALLER-4210
cockpit.spawn(["journalctl", "-a"])
.then((output) => (
cockpit.file(JOURNAL_LOG)
.replace(output)
));
(async () => {
const output = await cockpit.spawn(["journalctl", "-a"]);
await cockpit.file(JOURNAL_LOG).replace(output);
})();
}, []);

const {
Expand Down
38 changes: 31 additions & 7 deletions src/components/app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,14 @@ export const Application = ({ conf, dispatch, isFetching, onCritFail, osRelease,
// Attach a click event listener to detect external link clicks
document.addEventListener("click", allowExternalNavigation);

Promise.all(clients.map(Client => new Client(address, dispatch).init()))
.then(() => {
setStoreInitialized(true);
}, onCritFail({ context: N_("Reading information about the computer failed.") }));
(async () => {
try {
await Promise.all(clients.map(Client => new Client(address, dispatch).init()));
setStoreInitialized(true);
} catch (error) {
onCritFail({ context: N_("Reading information about the computer failed.") })(error);
}
})();
}, [address, dispatch, onCritFail]);

// Postpone rendering anything until we read the dbus address and the default configuration
Expand Down Expand Up @@ -125,7 +129,14 @@ const useConf = ({ onCritFail }) => {
const [conf, setConf] = useState();

useEffect(() => {
readConf().then(setConf, onCritFail({ context: N_("Reading installer configuration failed.") }));
(async () => {
try {
const result = await readConf();
setConf(result);
} catch (error) {
onCritFail({ context: N_("Reading installer configuration failed.") })(error);
}
})();
}, [onCritFail]);

return conf;
Expand All @@ -135,7 +146,14 @@ const useOsRelease = ({ onCritFail }) => {
const [osRelease, setOsRelease] = useState();

useEffect(() => {
readOsRelease().then(setOsRelease, onCritFail({ context: N_("Reading information about the OS failed.") }));
(async () => {
try {
const result = await readOsRelease();
setOsRelease(result);
} catch (error) {
onCritFail({ context: N_("Reading information about the OS failed.") })(error);
}
})();
}, [onCritFail]);

return osRelease;
Expand Down Expand Up @@ -171,7 +189,13 @@ const useAppVersion = () => {
const [appVersion, setAppVersion] = useState(initialState);

useEffect(() => {
getAnacondaVersion().then(value => setAppVersion(obj => ({ ...obj, backend: value })));
(async () => {
try {
const value = await getAnacondaVersion();
setAppVersion(obj => ({ ...obj, backend: value }));
} catch (err) {
}
})();
}, []);
return appVersion;
};
Expand Down
Loading
Loading