Skip to content

Commit

Permalink
Add fixLinuxExecPath() and properly escape Exec path with reserved ca…
Browse files Browse the repository at this point in the history
…racters

In Linux, according to the freedesktop standard about .desktop files,
Exec key needs to have its reserved characters properly escaped.

This fixes #99

Signed-off-by: Alexandre Demers <[email protected]>
  • Loading branch information
Oxalin committed Nov 30, 2023
1 parent 4d0938e commit 39d80e0
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/index.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ module.exports = class AutoLaunch
@opts.appPath = path

else if versions? and (versions.nw? or versions['node-webkit']? or versions.electron?)
# This appPath will need to be fixed later depending of the OS used
@opts.appPath = process.execPath

else
Expand Down Expand Up @@ -75,13 +76,25 @@ module.exports = class AutoLaunch
path = path.replace /\.app\/Contents\/MacOS\/[^\/]*$/, '.app' unless macOptions.useLaunchAgent
return path

# Under Linux and FreeBSD, fix the ExecPath when packaged as AppImage and escape the spaces correctly
# path - {String}
# Returns a {String}
fixLinuxExecPath: (path) ->
# As stated in the .desktop spec, Exec key's value must be properly escaped with reserved characters.
path = path.replace(/(\s+)/g, '\\$1')

return path


fixOpts: =>
@opts.appPath = @opts.appPath.replace /\/$/, ''

if /darwin/.test process.platform
@opts.appPath = @fixMacExecPath(@opts.appPath, @opts.mac)

if (/linux/.test process.platform) or (/freebsd/.test process.platform)
@opts.appPath = @fixLinuxExecPath(@opts.appPath)

if @opts.appPath.indexOf('/') isnt -1
tempPath = @opts.appPath.split '/'
@opts.appName = tempPath[tempPath.length - 1]
Expand Down

0 comments on commit 39d80e0

Please sign in to comment.