electron-asar-launcher
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleAllowMixedLocalizations</key>
<true/>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>js</string>
</array>
<key>CFBundleTypeName</key>
<string>JavaScript source</string>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
</dict>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>asar</string>
</array>
<key>CFBundleTypeName</key>
<string>Electron Archive</string>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
</dict>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>eald</string>
</array>
<key>CFBundleTypeName</key>
<string>Electron script bundle</string>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>LSTypeIsPackage</key>
<true/>
</dict>
</array>
<key>CFBundleExecutable</key>
<string>droplet</string>
<key>CFBundleIconFile</key>
<string>droplet</string>
<key>CFBundleIdentifier</key>
<string>io.github.uchcode.electron-asar-launcher</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>electron-asar-launcher</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleSignature</key>
<string>dplt</string>
<key>LSMinimumSystemVersionByArchitecture</key>
<dict>
<key>x86_64</key>
<string>10.6</string>
</dict>
<key>LSRequiresCarbon</key>
<true/>
<key>LSUIElement</key>
<true/>
</dict>
</plist>
app = Application.currentApplication()
app.includeStandardAdditions = true
se = Application('System Events')
function sh(script, opt={}) {
return app.doShellScript(script, {
administratorPrivileges: !!opt.withPrompt,
withPrompt: opt.withPrompt || '',
alteringLineEndings: opt.alteringLineEndings || false
}).replace(/\n$/,'')
}
function launchElectron() {
let searchString = 'Electron.app/Contents/MacOS/Electron'
try {
var pid = sh(`ps aux`)
.split('\n')
.filter(e=>e.endsWith(searchString))[0]
.replace(/\s+/g,' ')
.split(' ')[1]
} catch(e) {
var pid = undefined
}
if (!pid) {
sh('open -n -a Electron')
return
}
let el = se.processes.whose({unixId:pid})
if (!el) {
sh('open -n -a Electron')
return
}
el[0].frontmost = true
}
function launchElectronWith(path) {
try {
var pid = sh(`ps aux`)
.split('\n')
.filter(e=>e.endsWith(path))[0]
.replace(/\s+/g,' ')
.split(' ')[1]
} catch(e) {
var pid = undefined
}
if (!pid) {
sh(`open -n -a Electron --args "${path}"`)
return
}
let el = se.processes.whose({unixId:pid})
if (!el) {
sh(`open -n -a Electron --args "${path}"`)
return
}
el[0].frontmost = true
}
function openDocuments(docs) {
for (let d of docs) {
let doc = d.toString()
let ext = $(doc).pathExtension.js
if (ext == 'asar' || ext == 'js') {
launchElectronWith(doc)
} else if (ext == 'eald') {
launchElectronWith(`${doc}/Contents/Resources/main.js`)
}
}
}
function run() {
launchElectron()
}