Skip to content

Commit

Permalink
fix: #1 et #11 try fixing
Browse files Browse the repository at this point in the history
  • Loading branch information
hrenaud committed Oct 7, 2024
1 parent 12128b4 commit 16f8e4d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 57 deletions.
26 changes: 1 addition & 25 deletions src/main/handlers/Initalization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,7 @@ export const initialization = async (
initializedDatas.initPluginCanInstall =
getPluginCanInstallReturned.result as boolean
mainLog.log(getPluginCanInstallReturned)
if (
(os.platform() === 'darwin' || os.platform() === 'linux') &&
!initializedDatas.initPluginCanInstall
) {
if (!initializedDatas.initPluginCanInstall) {
mainLog.debug(`os.platform():`, os.platform())
mainLog.debug(
`!initializedDatas.initPluginCanInstall`,
Expand All @@ -274,27 +271,6 @@ export const initialization = async (
mainLog.log(errorOnFixingUserRights)
return false
}
} else if (
!(os.platform() === 'darwin' || os.platform() === 'linux') &&
!initializedDatas.initPluginCanInstall
) {
mainLog.debug(`os.platform():`, os.platform())
mainLog.debug(
`!initializedDatas.initPluginCanInstall`,
!initializedDatas.initPluginCanInstall
)
// #region Can't Fix User rights
const cantFixUserRights = new ConfigData(
'app_can_not_be_launched',
'error_type_cant_fix_user_rights'
)
cantFixUserRights.error = `Can't fix user rights`
cantFixUserRights.message = `Need to fix user rights on ${os.platform()}`
getMainWindow().webContents.send(
channels.INITIALIZATION_DATAS,
cantFixUserRights
)
return false
} else {
mainLog.log(`User can install plugins`)
}
Expand Down
58 changes: 26 additions & 32 deletions src/main/handlers/initHandlers/plugin_canInstall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,38 +72,32 @@ export const initSudoFixNpmDirRights = (
const mainLog = getMainLog().scope(
'main/initialization/initSudoFixNpmDirRights'
)
if (os.platform() === 'darwin') {
mainLog.debug(`Fix User rights on NPM Dir with sudo.`)
const toReturned = new ConfigData('fix_npm_user_rights')
return new Promise<ConfigData>((resolve) => {
const cmd = `chown -R $USER $(npm config get prefix)/{lib/node_modules,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 cmd = `chown -R $USER $(npm config get prefix)/{lib/node_modules,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 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 16f8e4d

Please sign in to comment.