This commit is contained in:
Edwin Joassart 2025-07-18 18:19:43 +02:00
parent fdf8820b5a
commit aeaa832bdd
No known key found for this signature in database
GPG Key ID: 6337EBE5AC716051

View File

@ -106,22 +106,25 @@ export async function sudo(
});
// we don't spawn directly in the promise otherwise resolving stop the process
return new Promise((resolve, reject) => {
setInterval(() => {
const checkElevation = setInterval(() => {
if (result.status === 'waiting') {
// Still waiting for user input, don't resolve or reject yet
return;
} else if (result.status === 'granted') {
// User accepted the UAC prompt, process started
clearInterval(checkElevation);
resolve({ cancelled: false });
} else if (result.status === 'cancelled') {
// User cancelled the UAC prompt
clearInterval(checkElevation);
resolve({ cancelled: true });
} else {
// An error occurred, reject the promise
reject(new Error(`Elevation failed: ${result.status}`));
}
}, 300);
// if the elevation didn't occured in 30 seconds we reject the promise
setTimeout(() => {
clearInterval(checkElevation);
reject(new Error('Elevation timeout'));
}, 30000);
});
} catch (error) {
throw new Error(`Can't elevate process ${error}`);