Created
August 9, 2017 14:58
-
-
Save uchcode/c6d5513936ca6b60b3f73423d52c5fd3 to your computer and use it in GitHub Desktop.
electron-asar-launcher
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment