-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from mischnic/node-4
Node 6
- Loading branch information
Showing
13 changed files
with
247 additions
and
228 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
const libui = require('..'); | ||
|
||
const win = new libui.UiWindow('Errors example', 320, 60, true); | ||
win.margined = true; | ||
|
||
const msg = (err) => { | ||
console.log('Another click will terminate the app.'); | ||
process.removeListener('uncaughtException', msg); | ||
}; | ||
|
||
process.on('uncaughtException', msg); | ||
|
||
const toolbar = new libui.UiHorizontalBox(); | ||
const setEntryBtn = new libui.UiButton('Uncaught error'); | ||
setEntryBtn.onClicked(() => { | ||
throw new Error('ciao'); | ||
}); | ||
toolbar.append(setEntryBtn, false); | ||
const setSearchBtn = new libui.UiButton('No errors'); | ||
setSearchBtn.onClicked(() => { | ||
console.log('clicked'); | ||
}); | ||
toolbar.append(setSearchBtn, false); | ||
const setPasswordBtn = new libui.UiButton('Set password'); | ||
setPasswordBtn.onClicked(() => {}); | ||
toolbar.append(setPasswordBtn, false); | ||
|
||
const setSpinboxBtn = new libui.UiButton('Set number'); | ||
setSpinboxBtn.onClicked(() => {}); | ||
toolbar.append(setSpinboxBtn, false); | ||
|
||
const toggleReadOnlyBtn = new libui.UiButton('Set ReadOnly'); | ||
toggleReadOnlyBtn.onClicked(() => { | ||
|
||
}); | ||
toolbar.append(toggleReadOnlyBtn, false); | ||
|
||
const box = new libui.UiVerticalBox(); | ||
box.padded = true; | ||
box.append(toolbar); | ||
win.setChild(box); | ||
|
||
win.onClosing(() => { | ||
win.close(); | ||
libui.stopLoop(); | ||
}); | ||
|
||
win.show(); | ||
|
||
libui.startLoop(); |
This file contains 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
This file contains 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
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const mv = require('mv'); | ||
const https = require('https'); | ||
const homePath = require('home-path'); | ||
const mkdirp = require('mkdirp'); | ||
|
||
const debug = require('debug')('libui-download'); | ||
|
||
const requestHttps = url => new Promise((resolve, reject) => { | ||
const req = https.get(url, resolve); | ||
req.on('error', reject); | ||
}); | ||
|
||
module.exports = function(project) { | ||
const PROJECT = project.toUpperCase(); | ||
return { | ||
requestHttps, | ||
mkCacheDir(cache) { | ||
try { | ||
mkdirp.sync(cache); | ||
return cache; | ||
} catch (err) { | ||
if (err.code !== 'EACCES') { | ||
debug('mkCacheDir error: ', err.stack); | ||
throw err; | ||
} | ||
|
||
// try local folder if homedir is off limits (e.g. some linuxes return '/' | ||
// as homedir) | ||
var localCache = path.resolve('./.' + project); | ||
|
||
mkdirp.sync(localCache); | ||
return localCache; | ||
} | ||
}, | ||
cacheDir(opts) { | ||
opts = opts || {}; | ||
var homeDir = homePath(); | ||
return opts.cache || path.join(homeDir, './.' + project); | ||
}, | ||
buildUrl(opts, filename) { | ||
var url = process.env[`NPM_CONFIG_${PROJECT}_MIRROR`] || | ||
process.env[`${PROJECT}_MIRROR`] || opts.mirror || | ||
`https://github.com/parro-it/${project}/releases/download/`; | ||
|
||
url += process.env[`${PROJECT}_CUSTOM_DIR`] || opts.customDir || opts.version; | ||
url += '/'; | ||
url += process.env[`${PROJECT}_CUSTOM_FILENAME`] || opts.customFilename || | ||
filename; | ||
return url; | ||
}, | ||
doDownload(res, url, target, cachedZip) { | ||
if (res.statusCode !== 200) { | ||
throw new Error(`Https request failed for ${ | ||
res.headers.location} with code ${res.statusCode}.`); | ||
} | ||
|
||
debug(`Https request for ${url} ok with code 200.`); | ||
|
||
const fileWrite = res.pipe(fs.createWriteStream(target)); | ||
|
||
return new Promise((resolve, reject) => { | ||
const finish = () => { | ||
debug('end stream reached', target, cachedZip); | ||
mv(target, cachedZip, function(err) { | ||
if (err) { | ||
reject(err); | ||
} else { | ||
resolve(cachedZip); | ||
} | ||
}); | ||
}; | ||
|
||
fileWrite.on('finish', finish); | ||
fileWrite.on('error', reject); | ||
}); | ||
} | ||
}; | ||
}; |
Oops, something went wrong.