Skip to content

Commit

Permalink
fix: bad if on os.plateform()
Browse files Browse the repository at this point in the history
  • Loading branch information
hrenaud committed Oct 9, 2024
1 parent 9e9cd63 commit d20f80a
Showing 1 changed file with 32 additions and 38 deletions.
70 changes: 32 additions & 38 deletions src/main/handlers/initHandlers/plugin_canInstall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,44 +73,38 @@ export const initSudoFixNpmDirRights = (
const mainLog = getMainLog().scope(
'main/initialization/initSudoFixNpmDirRights'
)
if (os.platform() === 'darwin' || os.platform() === 'linux') {
mainLog.debug(`Fix User rights on NPM Dir with sudo.`)
const toReturned = new ConfigData('fix_npm_user_rights')
return new Promise<ConfigData>((resolve) => {
const libPath = path.join(`lib`, `node_modules`)
let cmd = ``
if (os.platform() === 'win32') {
cmd = `mkdir $(npm config get prefix)/${libPath} && chown -R $USER $(npm config get prefix)/{${libPath},bin,share} && echo "Done"`
} else {
cmd = `mkdir -p $(npm config get prefix)/${libPath} && chown -R $USER $(npm config get prefix)/{${libPath},bin,share} && echo "Done"`
}
sudoPrompt.exec(
cmd,
{ name: 'Fix user permissions on Node' },
(error, stdout, stderr) => {
if (error) {
mainLog.error(`exec error: ${error}`)
toReturned.error = error
toReturned.message = `CAN'T fix Npm user rights`
return resolve(toReturned)
}
if (stderr) mainLog.debug(`stderr: ${stderr}`)
if (stdout) {
const returned: string = (stdout as string).trim()
toReturned.result = true
toReturned.message = `User rights FIXED returned ${returned}`
// getMainWindow().webContents.send(
// channels.HOST_INFORMATIONS_BACK,
// toReturned
// )
return resolve(toReturned)
}
mainLog.debug(`Fix User rights on NPM Dir with sudo.`)
const toReturned = new ConfigData('fix_npm_user_rights')
return new Promise<ConfigData>((resolve) => {
const libPath = path.join(`lib`, `node_modules`)
let cmd = ``
if (os.platform() === 'win32') {
cmd = `mkdir $(npm config get prefix)/${libPath} && chown -R $USER $(npm config get prefix)/{${libPath},bin,share} && echo "Done"`
} else {
cmd = `mkdir -p $(npm config get prefix)/${libPath} && chown -R $USER $(npm config get prefix)/{${libPath},bin,share} && echo "Done"`
}
sudoPrompt.exec(
cmd,
{ name: 'Fix user permissions on Node' },
(error, stdout, stderr) => {
if (error) {
mainLog.error(`exec error: ${error}`)
toReturned.error = error
toReturned.message = `CAN'T fix Npm user rights`
return resolve(toReturned)
}
)
})
} else {
mainLog.debug(
`NOT ON DARWIN/LINUX PLATFORM, CAN'T Fix User rights on NPM Dir.`
if (stderr) mainLog.debug(`stderr: ${stderr}`)
if (stdout) {
const returned: string = (stdout as string).trim()
toReturned.result = true
toReturned.message = `User rights FIXED returned ${returned}`
// getMainWindow().webContents.send(
// channels.HOST_INFORMATIONS_BACK,
// toReturned
// )
return resolve(toReturned)
}
}
)
}
})
}

0 comments on commit d20f80a

Please sign in to comment.