code
stringlengths
24
2.07M
docstring
stringlengths
25
85.3k
func_name
stringlengths
1
92
language
stringclasses
1 value
repo
stringlengths
5
64
path
stringlengths
4
172
url
stringlengths
44
218
license
stringclasses
7 values
function initParams(uri, options, callback) { var params = uri if (isFunction(options)) { callback = options if (typeof uri === "string") { params = {uri:uri} } } else { params = xtend(options, {uri: uri}) } params.callback = callback return params }
Loads a shader. @param {!WebGLContext} gl The WebGLContext to use. @param {string} shaderSource The shader source. @param {number} shaderType The type of shader. @param {function(string): void) opt_errorCallback callback for errors. @return {!WebGLShader} The created shader.
initParams
javascript
patriciogonzalezvivo/glslGallery
build/glslGallery.js
https://github.com/patriciogonzalezvivo/glslGallery/blob/master/build/glslGallery.js
MIT
function createXHR(uri, options, callback) { options = initParams(uri, options, callback) return _createXHR(options) }
Loads a shader. @param {!WebGLContext} gl The WebGLContext to use. @param {string} shaderSource The shader source. @param {number} shaderType The type of shader. @param {function(string): void) opt_errorCallback callback for errors. @return {!WebGLShader} The created shader.
createXHR
javascript
patriciogonzalezvivo/glslGallery
build/glslGallery.js
https://github.com/patriciogonzalezvivo/glslGallery/blob/master/build/glslGallery.js
MIT
function _createXHR(options) { if(typeof options.callback === "undefined"){ throw new Error("callback argument missing") } var called = false var callback = function cbOnce(err, response, body){ if(!called){ called = true options.callback(err, response, body) } } function readystatechange() { if (xhr.readyState === 4) { setTimeout(loadFunc, 0) } } function getBody() { // Chrome with requestType=blob throws errors arround when even testing access to responseText var body = undefined if (xhr.response) { body = xhr.response } else { body = xhr.responseText || getXml(xhr) } if (isJson) { try { body = JSON.parse(body) } catch (e) {} } return body } function errorFunc(evt) { clearTimeout(timeoutTimer) if(!(evt instanceof Error)){ evt = new Error("" + (evt || "Unknown XMLHttpRequest Error") ) } evt.statusCode = 0 return callback(evt, failureResponse) } // will load the data & process the response in a special response object function loadFunc() { if (aborted) return var status clearTimeout(timeoutTimer) if(options.useXDR && xhr.status===undefined) { //IE8 CORS GET successful response doesn't have a status field, but body is fine status = 200 } else { status = (xhr.status === 1223 ? 204 : xhr.status) } var response = failureResponse var err = null if (status !== 0){ response = { body: getBody(), statusCode: status, method: method, headers: {}, url: uri, rawRequest: xhr } if(xhr.getAllResponseHeaders){ //remember xhr can in fact be XDR for CORS in IE response.headers = parseHeaders(xhr.getAllResponseHeaders()) } } else { err = new Error("Internal XMLHttpRequest Error") } return callback(err, response, response.body) } var xhr = options.xhr || null if (!xhr) { if (options.cors || options.useXDR) { xhr = new createXHR.XDomainRequest() }else{ xhr = new createXHR.XMLHttpRequest() } } var key var aborted var uri = xhr.url = options.uri || options.url var method = xhr.method = options.method || "GET" var body = options.body || options.data var headers = xhr.headers = options.headers || {} var sync = !!options.sync var isJson = false var timeoutTimer var failureResponse = { body: undefined, headers: {}, statusCode: 0, method: method, url: uri, rawRequest: xhr } if ("json" in options && options.json !== false) { isJson = true headers["accept"] || headers["Accept"] || (headers["Accept"] = "application/json") //Don't override existing accept header declared by user if (method !== "GET" && method !== "HEAD") { headers["content-type"] || headers["Content-Type"] || (headers["Content-Type"] = "application/json") //Don't override existing accept header declared by user body = JSON.stringify(options.json === true ? body : options.json) } } xhr.onreadystatechange = readystatechange xhr.onload = loadFunc xhr.onerror = errorFunc // IE9 must have onprogress be set to a unique function. xhr.onprogress = function () { // IE must die } xhr.onabort = function(){ aborted = true; } xhr.ontimeout = errorFunc xhr.open(method, uri, !sync, options.username, options.password) //has to be after open if(!sync) { xhr.withCredentials = !!options.withCredentials } // Cannot set timeout with sync request // not setting timeout on the xhr object, because of old webkits etc. not handling that correctly // both npm's request and jquery 1.x use this kind of timeout, so this is being consistent if (!sync && options.timeout > 0 ) { timeoutTimer = setTimeout(function(){ if (aborted) return aborted = true//IE9 may still call readystatechange xhr.abort("timeout") var e = new Error("XMLHttpRequest timeout") e.code = "ETIMEDOUT" errorFunc(e) }, options.timeout ) } if (xhr.setRequestHeader) { for(key in headers){ if(headers.hasOwnProperty(key)){ xhr.setRequestHeader(key, headers[key]) } } } else if (options.headers && !isEmpty(options.headers)) { throw new Error("Headers cannot be set on an XDomainRequest object") } if ("responseType" in options) { xhr.responseType = options.responseType } if ("beforeSend" in options && typeof options.beforeSend === "function" ) { options.beforeSend(xhr) } // Microsoft Edge browser sends "undefined" when send is called with undefined value. // XMLHttpRequest spec says to pass null as body to indicate no body // See https://github.com/naugtur/xhr/issues/100. xhr.send(body || null) return xhr }
Loads a shader. @param {!WebGLContext} gl The WebGLContext to use. @param {string} shaderSource The shader source. @param {number} shaderType The type of shader. @param {function(string): void) opt_errorCallback callback for errors. @return {!WebGLShader} The created shader.
_createXHR
javascript
patriciogonzalezvivo/glslGallery
build/glslGallery.js
https://github.com/patriciogonzalezvivo/glslGallery/blob/master/build/glslGallery.js
MIT
callback = function cbOnce(err, response, body){ if(!called){ called = true options.callback(err, response, body) } }
Loads a shader. @param {!WebGLContext} gl The WebGLContext to use. @param {string} shaderSource The shader source. @param {number} shaderType The type of shader. @param {function(string): void) opt_errorCallback callback for errors. @return {!WebGLShader} The created shader.
callback
javascript
patriciogonzalezvivo/glslGallery
build/glslGallery.js
https://github.com/patriciogonzalezvivo/glslGallery/blob/master/build/glslGallery.js
MIT
function readystatechange() { if (xhr.readyState === 4) { setTimeout(loadFunc, 0) } }
Loads a shader. @param {!WebGLContext} gl The WebGLContext to use. @param {string} shaderSource The shader source. @param {number} shaderType The type of shader. @param {function(string): void) opt_errorCallback callback for errors. @return {!WebGLShader} The created shader.
readystatechange
javascript
patriciogonzalezvivo/glslGallery
build/glslGallery.js
https://github.com/patriciogonzalezvivo/glslGallery/blob/master/build/glslGallery.js
MIT
function getBody() { // Chrome with requestType=blob throws errors arround when even testing access to responseText var body = undefined if (xhr.response) { body = xhr.response } else { body = xhr.responseText || getXml(xhr) } if (isJson) { try { body = JSON.parse(body) } catch (e) {} } return body }
Loads a shader. @param {!WebGLContext} gl The WebGLContext to use. @param {string} shaderSource The shader source. @param {number} shaderType The type of shader. @param {function(string): void) opt_errorCallback callback for errors. @return {!WebGLShader} The created shader.
getBody
javascript
patriciogonzalezvivo/glslGallery
build/glslGallery.js
https://github.com/patriciogonzalezvivo/glslGallery/blob/master/build/glslGallery.js
MIT
function errorFunc(evt) { clearTimeout(timeoutTimer) if(!(evt instanceof Error)){ evt = new Error("" + (evt || "Unknown XMLHttpRequest Error") ) } evt.statusCode = 0 return callback(evt, failureResponse) }
Loads a shader. @param {!WebGLContext} gl The WebGLContext to use. @param {string} shaderSource The shader source. @param {number} shaderType The type of shader. @param {function(string): void) opt_errorCallback callback for errors. @return {!WebGLShader} The created shader.
errorFunc
javascript
patriciogonzalezvivo/glslGallery
build/glslGallery.js
https://github.com/patriciogonzalezvivo/glslGallery/blob/master/build/glslGallery.js
MIT
function loadFunc() { if (aborted) return var status clearTimeout(timeoutTimer) if(options.useXDR && xhr.status===undefined) { //IE8 CORS GET successful response doesn't have a status field, but body is fine status = 200 } else { status = (xhr.status === 1223 ? 204 : xhr.status) } var response = failureResponse var err = null if (status !== 0){ response = { body: getBody(), statusCode: status, method: method, headers: {}, url: uri, rawRequest: xhr } if(xhr.getAllResponseHeaders){ //remember xhr can in fact be XDR for CORS in IE response.headers = parseHeaders(xhr.getAllResponseHeaders()) } } else { err = new Error("Internal XMLHttpRequest Error") } return callback(err, response, response.body) }
Loads a shader. @param {!WebGLContext} gl The WebGLContext to use. @param {string} shaderSource The shader source. @param {number} shaderType The type of shader. @param {function(string): void) opt_errorCallback callback for errors. @return {!WebGLShader} The created shader.
loadFunc
javascript
patriciogonzalezvivo/glslGallery
build/glslGallery.js
https://github.com/patriciogonzalezvivo/glslGallery/blob/master/build/glslGallery.js
MIT
function getXml(xhr) { // xhr.responseXML will throw Exception "InvalidStateError" or "DOMException" // See https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/responseXML. try { if (xhr.responseType === "document") { return xhr.responseXML } var firefoxBugTakenEffect = xhr.responseXML && xhr.responseXML.documentElement.nodeName === "parsererror" if (xhr.responseType === "" && !firefoxBugTakenEffect) { return xhr.responseXML } } catch (e) {} return null }
Loads a shader. @param {!WebGLContext} gl The WebGLContext to use. @param {string} shaderSource The shader source. @param {number} shaderType The type of shader. @param {function(string): void) opt_errorCallback callback for errors. @return {!WebGLShader} The created shader.
getXml
javascript
patriciogonzalezvivo/glslGallery
build/glslGallery.js
https://github.com/patriciogonzalezvivo/glslGallery/blob/master/build/glslGallery.js
MIT
function extend() { var target = {} for (var i = 0; i < arguments.length; i++) { var source = arguments[i] for (var key in source) { if (hasOwnProperty.call(source, key)) { target[key] = source[key] } } } return target }
Loads a shader. @param {!WebGLContext} gl The WebGLContext to use. @param {string} shaderSource The shader source. @param {number} shaderType The type of shader. @param {function(string): void) opt_errorCallback callback for errors. @return {!WebGLShader} The created shader.
extend
javascript
patriciogonzalezvivo/glslGallery
build/glslGallery.js
https://github.com/patriciogonzalezvivo/glslGallery/blob/master/build/glslGallery.js
MIT
OpenFrameIcon = function OpenFrameIcon(parent) { var _this = this; _classCallCheck(this, OpenFrameIcon); this.parent = parent; this.el = document.createElement('div'); this.el.setAttribute('class', 'glslGallery_openFrameIcon'); this.el.innerHTML = '[o]'; this.el.addEventListener('click', function () { createOpenFrameArtwork(_this.parent, function () { console.log(event); }); }, true); this.parent.el.appendChild(this.el); }
Loads a shader. @param {!WebGLContext} gl The WebGLContext to use. @param {string} shaderSource The shader source. @param {number} shaderType The type of shader. @param {function(string): void) opt_errorCallback callback for errors. @return {!WebGLShader} The created shader.
OpenFrameIcon
javascript
patriciogonzalezvivo/glslGallery
build/glslGallery.js
https://github.com/patriciogonzalezvivo/glslGallery/blob/master/build/glslGallery.js
MIT
function createOpenFrameArtwork(item, callback) { var id = item.id; var title = item.title || 'unknow'; var author = item.author || 'unknow'; var xhr = new XMLHttpRequest(); callback = callback || function () {}; // anywhere in the API that user {id} is needed, the alias 'current' can be used for the logged-in user xhr.open('POST', 'http://openframe.io/api/users/current/owned_artwork', false); // set content type to JSON... xhr.setRequestHeader('Content-Type', 'application/json;charset=UTF-8'); // This is essential in order to include auth cookies: xhr.withCredentials = true; xhr.onload = function (event) { if (event.currentTarget.status === 404) { (function () { window.open('http://openframe.io/login-popup', 'login', 'width=500,height=600'); var successListener = function successListener(e) { if (e.data === 'success') { createOpenFrameArtwork(item, callback); } window.removeEventListener('message', successListener); }; window.addEventListener('message', successListener, false); })(); } else if (event.currentTarget.status === 200) { callback(true); } else { callback(false); } }; xhr.onerror = function (event) { console.log(event.currentTarget.status); }; var url = ''; if (id.match(/\d\d\/.*/)) { url = 'https://thebookofshaders.com/' + id; } else { url = 'https://thebookofshaders.com/log/' + id; } xhr.send(JSON.stringify({ title: title, author_name: author, is_public: false, format: 'openframe-glslviewer', url: url + '.frag', thumb_url: url + '.png' })); }
Loads a shader. @param {!WebGLContext} gl The WebGLContext to use. @param {string} shaderSource The shader source. @param {number} shaderType The type of shader. @param {function(string): void) opt_errorCallback callback for errors. @return {!WebGLShader} The created shader.
createOpenFrameArtwork
javascript
patriciogonzalezvivo/glslGallery
build/glslGallery.js
https://github.com/patriciogonzalezvivo/glslGallery/blob/master/build/glslGallery.js
MIT
successListener = function successListener(e) { if (e.data === 'success') { createOpenFrameArtwork(item, callback); } window.removeEventListener('message', successListener); }
Loads a shader. @param {!WebGLContext} gl The WebGLContext to use. @param {string} shaderSource The shader source. @param {number} shaderType The type of shader. @param {function(string): void) opt_errorCallback callback for errors. @return {!WebGLShader} The created shader.
successListener
javascript
patriciogonzalezvivo/glslGallery
build/glslGallery.js
https://github.com/patriciogonzalezvivo/glslGallery/blob/master/build/glslGallery.js
MIT
function GalleryItem(id, main, options) { var _this = this; _classCallCheck(this, GalleryItem); this.id = id; this.main = main; this.options = options; // Construct Item this.el = document.createElement('div'); this.el.setAttribute('class', 'glslGallery_item'); this.link = document.createElement('a'); this.link.setAttribute('target', '_blank'); this.img = document.createElement('img'); this.img.setAttribute('class', 'glslGallery_thumb'); this.credits = document.createElement('div'); this.credits.setAttribute('class', 'glslGallery_credits'); this.credits.style.visibility = 'hidden'; if (this.id.match(/\d\d\/.*/)) { this.link.setAttribute('href', 'https://thebookofshaders.com/edit.php#' + this.id + '.frag'); this.img.src = 'https://thebookofshaders.com/' + this.id + '.png'; } else { if (this.options.clickRun === "editor") { this.link.setAttribute('href', 'https://thebookofshaders.com/edit.php?log=' + this.id); this.img.src = 'https://thebookofshaders.com/log/' + this.id + '.png'; } else { this.link.setAttribute('href', 'http://' + this.options.clickRun + '.thebookofshaders.com/?log=' + this.id); this.img.src = 'https://thebookofshaders.com/log/' + this.id + '.png'; } } this.link.appendChild(this.img); this.el.appendChild(this.link); this.el.appendChild(this.credits); this.main.container.appendChild(this.el); // Add events if (this.options.hoverPreview) { this.el.addEventListener('mouseenter', function () { onEnter(_this); }); this.el.addEventListener('mouseleave', function () { onLeave(_this); }); } if (this.options.openFrameIcon) { this.openFrameIcon = new _addonsOpenFrameIcon2['default'](this); } this.init(); }
Loads a shader. @param {!WebGLContext} gl The WebGLContext to use. @param {string} shaderSource The shader source. @param {number} shaderType The type of shader. @param {function(string): void) opt_errorCallback callback for errors. @return {!WebGLShader} The created shader.
GalleryItem
javascript
patriciogonzalezvivo/glslGallery
build/glslGallery.js
https://github.com/patriciogonzalezvivo/glslGallery/blob/master/build/glslGallery.js
MIT
function initCanvas() { if (!window.glslGallery_canvas) { var canvas = document.createElement('canvas'); canvas.setAttribute('class', 'glslGallery_canvas'); canvas.style.width = '250px'; canvas.style.height = '250px'; canvas.width = '250px'; canvas.height = '250px'; window.glslGallery_canvas = new _glslCanvas2['default'](canvas); } }
Loads a shader. @param {!WebGLContext} gl The WebGLContext to use. @param {string} shaderSource The shader source. @param {number} shaderType The type of shader. @param {function(string): void) opt_errorCallback callback for errors. @return {!WebGLShader} The created shader.
initCanvas
javascript
patriciogonzalezvivo/glslGallery
build/glslGallery.js
https://github.com/patriciogonzalezvivo/glslGallery/blob/master/build/glslGallery.js
MIT
function onEnter(item) { initCanvas(); if (item.getCode()) { item.load(item.getCode()); } else { var url = ''; if (item.id.match(/\d\d\/.*/)) { url = 'https://thebookofshaders.com/' + item.id + '.frag'; } else { url = 'https://thebookofshaders.com/log/' + item.id + '.frag'; } _xhr2['default'].get(url, function (error, res, body) { if (error) { console.error('Error downloading ', error); return; } item.load(body); }); } }
Loads a shader. @param {!WebGLContext} gl The WebGLContext to use. @param {string} shaderSource The shader source. @param {number} shaderType The type of shader. @param {function(string): void) opt_errorCallback callback for errors. @return {!WebGLShader} The created shader.
onEnter
javascript
patriciogonzalezvivo/glslGallery
build/glslGallery.js
https://github.com/patriciogonzalezvivo/glslGallery/blob/master/build/glslGallery.js
MIT
function onLeave(item) { initCanvas(); if (item.el.getElementsByClassName('glslGallery_canvas') > 0) { // Remove glslCanvas instance from item item.el.removeChild(window.glslGallery_canvas.canvas); } }
Loads a shader. @param {!WebGLContext} gl The WebGLContext to use. @param {string} shaderSource The shader source. @param {number} shaderType The type of shader. @param {function(string): void) opt_errorCallback callback for errors. @return {!WebGLShader} The created shader.
onLeave
javascript
patriciogonzalezvivo/glslGallery
build/glslGallery.js
https://github.com/patriciogonzalezvivo/glslGallery/blob/master/build/glslGallery.js
MIT
function GlslGallery(selector, options) { _classCallCheck(this, GlslGallery); if (typeof selector === 'object' && selector.nodeType && selector.nodeType === 1) { this.container = selector; } else if (typeof selector === 'string') { this.container = document.querySelector(selector); } else { console.log('Error, type ' + typeof selector + ' of ' + selector + ' is unknown'); return; } this.options = options || {}; if (!this.options.showAuthor) { this.options.showAuthor = true; } if (!this.options.showTitle) { this.options.showTitle = true; } if (!this.options.hoverPreview) { this.options.hoverPreview = true; } if (!this.options.openFrameIcon) { this.options.openFrameIcon = true; } if (!this.options.clickRun) { this.options.clickRun = 'player'; } this.items = []; if (selector.hasAttribute('data-properties')) { var prop = selector.getAttribute('data-properties').split(','); for (var i in prop) { var values = prop[i].split(':'); if (values.length === 1) { this.options[values[0]] = true; } else if (values.length === 2) { this.options[values[0]] = values[1] === 'true' || values[1] === 'false' ? values[1] === 'true' : values[1]; } } } if (selector.hasAttribute('data')) { this.addItems(selector.getAttribute('data')); } if (this.options.logs) { this.addItems(this.options.logs); } return this; }
Loads a shader. @param {!WebGLContext} gl The WebGLContext to use. @param {string} shaderSource The shader source. @param {number} shaderType The type of shader. @param {function(string): void) opt_errorCallback callback for errors. @return {!WebGLShader} The created shader.
GlslGallery
javascript
patriciogonzalezvivo/glslGallery
build/glslGallery.js
https://github.com/patriciogonzalezvivo/glslGallery/blob/master/build/glslGallery.js
MIT
function glslGalleryLoadAll() { if (!window.GlslGallery) { window.GlslGallery = GlslGallery; } var list = document.getElementsByClassName('glslGallery'); if (list.length > 0) { window.glslGalleries = []; for (var i = 0; i < list.length; i++) { var gallery = new GlslGallery(list[i]); window.glslGalleries.push(gallery); } } }
Loads a shader. @param {!WebGLContext} gl The WebGLContext to use. @param {string} shaderSource The shader source. @param {number} shaderType The type of shader. @param {function(string): void) opt_errorCallback callback for errors. @return {!WebGLShader} The created shader.
glslGalleryLoadAll
javascript
patriciogonzalezvivo/glslGallery
build/glslGallery.js
https://github.com/patriciogonzalezvivo/glslGallery/blob/master/build/glslGallery.js
MIT
Point = (x, y, r) => { return { x, y, radius: r }; }
Tests for server/lib/util.js This is mostly a regression suite, to make sure behavior is preserved throughout changes to the server infrastructure.
Point
javascript
owenashurst/agar.io-clone
test/util.js
https://github.com/owenashurst/agar.io-clone/blob/master/test/util.js
MIT
Point = (x, y, r) => { return { x, y, radius: r }; }
Tests for server/lib/util.js This is mostly a regression suite, to make sure behavior is preserved throughout changes to the server infrastructure.
Point
javascript
owenashurst/agar.io-clone
test/util.js
https://github.com/owenashurst/agar.io-clone/blob/master/test/util.js
MIT
function build () { console.log('Installing node_modules...') rimraf.sync(NODE_MODULES_PATH) cp.execSync('npm ci', { stdio: 'inherit' }) console.log('Nuking dist/ and build/...') rimraf.sync(DIST_PATH) rimraf.sync(BUILD_PATH) console.log('Build: Transpiling to ES5...') cp.execSync('npm run build', { NODE_ENV: 'production', stdio: 'inherit' }) console.log('Build: Transpiled to ES5.') const platform = argv._[0] if (platform === 'darwin') { buildDarwin(printDone) } else if (platform === 'win32') { buildWin32(printDone) } else if (platform === 'linux') { buildLinux(printDone) } else { buildDarwin(function (err) { printDone(err) buildWin32(function (err) { printDone(err) buildLinux(printDone) }) }) } }
Builds app binaries for Mac, Windows, and Linux.
build
javascript
webtorrent/webtorrent-desktop
bin/package.js
https://github.com/webtorrent/webtorrent-desktop/blob/master/bin/package.js
MIT
function buildDarwin (cb) { const plist = require('plist') console.log('Mac: Packaging electron...') electronPackager(Object.assign({}, all, darwin)).then(function (buildPath) { console.log('Mac: Packaged electron. ' + buildPath) const appPath = path.join(buildPath[0], config.APP_NAME + '.app') const contentsPath = path.join(appPath, 'Contents') const resourcesPath = path.join(contentsPath, 'Resources') const infoPlistPath = path.join(contentsPath, 'Info.plist') const infoPlist = plist.parse(fs.readFileSync(infoPlistPath, 'utf8')) infoPlist.CFBundleDocumentTypes = [ { CFBundleTypeExtensions: ['torrent'], CFBundleTypeIconFile: path.basename(config.APP_FILE_ICON) + '.icns', CFBundleTypeName: 'BitTorrent Document', CFBundleTypeRole: 'Editor', LSHandlerRank: 'Owner', LSItemContentTypes: ['org.bittorrent.torrent'] }, { CFBundleTypeName: 'Any', CFBundleTypeOSTypes: ['****'], CFBundleTypeRole: 'Editor', LSHandlerRank: 'Owner', LSTypeIsPackage: false } ] infoPlist.CFBundleURLTypes = [ { CFBundleTypeRole: 'Editor', CFBundleURLIconFile: path.basename(config.APP_FILE_ICON) + '.icns', CFBundleURLName: 'BitTorrent Magnet URL', CFBundleURLSchemes: ['magnet'] }, { CFBundleTypeRole: 'Editor', CFBundleURLIconFile: path.basename(config.APP_FILE_ICON) + '.icns', CFBundleURLName: 'BitTorrent Stream-Magnet URL', CFBundleURLSchemes: ['stream-magnet'] } ] infoPlist.UTExportedTypeDeclarations = [ { UTTypeConformsTo: [ 'public.data', 'public.item', 'com.bittorrent.torrent' ], UTTypeDescription: 'BitTorrent Document', UTTypeIconFile: path.basename(config.APP_FILE_ICON) + '.icns', UTTypeIdentifier: 'org.bittorrent.torrent', UTTypeReferenceURL: 'http://www.bittorrent.org/beps/bep_0000.html', UTTypeTagSpecification: { 'com.apple.ostype': 'TORR', 'public.filename-extension': ['torrent'], 'public.mime-type': 'application/x-bittorrent' } } ] fs.writeFileSync(infoPlistPath, plist.build(infoPlist)) // Copy torrent file icon into app bundle cp.execSync(`cp ${config.APP_FILE_ICON + '.icns'} ${resourcesPath}`) if (process.platform === 'darwin') { if (argv.sign) { signApp(function (err) { if (err) return cb(err) pack(cb) }) } else { printWarning() pack(cb) } } else { printWarning() } function signApp (cb) { const sign = require('electron-osx-sign') const { notarize } = require('electron-notarize') /* * Sign the app with Apple Developer ID certificates. We sign the app for 2 reasons: * - So the auto-updater (Squirrrel.Mac) can check that app updates are signed by * the same author as the current version. * - So users will not a see a warning about the app coming from an "Unidentified * Developer" when they open it for the first time (Mac Gatekeeper). * * To sign an Mac app for distribution outside the App Store, the following are * required: * - Xcode * - Xcode Command Line Tools (xcode-select --install) * - Membership in the Apple Developer Program */ const signOpts = { verbose: true, app: appPath, platform: 'darwin', identity: 'Developer ID Application: WebTorrent, LLC (5MAMC8G3L8)', hardenedRuntime: true, entitlements: path.join(config.ROOT_PATH, 'bin', 'darwin-entitlements.plist'), 'entitlements-inherit': path.join(config.ROOT_PATH, 'bin', 'darwin-entitlements.plist'), 'signature-flags': 'library' } const notarizeOpts = { appBundleId: darwin.appBundleId, appPath, appleId: '[email protected]', appleIdPassword: '@keychain:AC_PASSWORD' } console.log('Mac: Signing app...') sign(signOpts, function (err) { if (err) return cb(err) console.log('Mac: Signed app.') console.log('Mac: Notarizing app...') notarize(notarizeOpts).then( function () { console.log('Mac: Notarized app.') cb(null) }, function (err) { cb(err) }) }) } function pack (cb) { packageZip() // always produce .zip file, used for automatic updates if (argv.package === 'dmg' || argv.package === 'all') { packageDmg(cb) } } function packageZip () { // Create .zip file (used by the auto-updater) console.log('Mac: Creating zip...') const inPath = path.join(buildPath[0], config.APP_NAME + '.app') const outPath = path.join(DIST_PATH, BUILD_NAME + '-darwin.zip') zip.zipSync(inPath, outPath) console.log('Mac: Created zip.') } function packageDmg (cb) { console.log('Mac: Creating dmg...') const appDmg = require('appdmg') const targetPath = path.join(DIST_PATH, BUILD_NAME + '.dmg') rimraf.sync(targetPath) // Create a .dmg (Mac disk image) file, for easy user installation. const dmgOpts = { basepath: config.ROOT_PATH, target: targetPath, specification: { title: config.APP_NAME, icon: config.APP_ICON + '.icns', background: path.join(config.STATIC_PATH, 'appdmg.png'), 'icon-size': 128, contents: [ { x: 122, y: 240, type: 'file', path: appPath }, { x: 380, y: 240, type: 'link', path: '/Applications' }, // Hide hidden icons out of view, for users who have hidden files shown. // https://github.com/LinusU/node-appdmg/issues/45#issuecomment-153924954 { x: 50, y: 500, type: 'position', path: '.background' }, { x: 100, y: 500, type: 'position', path: '.DS_Store' }, { x: 150, y: 500, type: 'position', path: '.Trashes' }, { x: 200, y: 500, type: 'position', path: '.VolumeIcon.icns' } ] } } const dmg = appDmg(dmgOpts) dmg.once('error', cb) dmg.on('progress', function (info) { if (info.type === 'step-begin') console.log(info.title + '...') }) dmg.once('finish', function (info) { console.log('Mac: Created dmg.') cb(null) }) } }).catch(function (err) { cb(err) }) }
Builds app binaries for Mac, Windows, and Linux.
buildDarwin
javascript
webtorrent/webtorrent-desktop
bin/package.js
https://github.com/webtorrent/webtorrent-desktop/blob/master/bin/package.js
MIT
function signApp (cb) { const sign = require('electron-osx-sign') const { notarize } = require('electron-notarize') /* * Sign the app with Apple Developer ID certificates. We sign the app for 2 reasons: * - So the auto-updater (Squirrrel.Mac) can check that app updates are signed by * the same author as the current version. * - So users will not a see a warning about the app coming from an "Unidentified * Developer" when they open it for the first time (Mac Gatekeeper). * * To sign an Mac app for distribution outside the App Store, the following are * required: * - Xcode * - Xcode Command Line Tools (xcode-select --install) * - Membership in the Apple Developer Program */ const signOpts = { verbose: true, app: appPath, platform: 'darwin', identity: 'Developer ID Application: WebTorrent, LLC (5MAMC8G3L8)', hardenedRuntime: true, entitlements: path.join(config.ROOT_PATH, 'bin', 'darwin-entitlements.plist'), 'entitlements-inherit': path.join(config.ROOT_PATH, 'bin', 'darwin-entitlements.plist'), 'signature-flags': 'library' } const notarizeOpts = { appBundleId: darwin.appBundleId, appPath, appleId: '[email protected]', appleIdPassword: '@keychain:AC_PASSWORD' } console.log('Mac: Signing app...') sign(signOpts, function (err) { if (err) return cb(err) console.log('Mac: Signed app.') console.log('Mac: Notarizing app...') notarize(notarizeOpts).then( function () { console.log('Mac: Notarized app.') cb(null) }, function (err) { cb(err) }) }) }
Builds app binaries for Mac, Windows, and Linux.
signApp
javascript
webtorrent/webtorrent-desktop
bin/package.js
https://github.com/webtorrent/webtorrent-desktop/blob/master/bin/package.js
MIT
function pack (cb) { packageZip() // always produce .zip file, used for automatic updates if (argv.package === 'dmg' || argv.package === 'all') { packageDmg(cb) } }
Builds app binaries for Mac, Windows, and Linux.
pack
javascript
webtorrent/webtorrent-desktop
bin/package.js
https://github.com/webtorrent/webtorrent-desktop/blob/master/bin/package.js
MIT
function packageZip () { // Create .zip file (used by the auto-updater) console.log('Mac: Creating zip...') const inPath = path.join(buildPath[0], config.APP_NAME + '.app') const outPath = path.join(DIST_PATH, BUILD_NAME + '-darwin.zip') zip.zipSync(inPath, outPath) console.log('Mac: Created zip.') }
Builds app binaries for Mac, Windows, and Linux.
packageZip
javascript
webtorrent/webtorrent-desktop
bin/package.js
https://github.com/webtorrent/webtorrent-desktop/blob/master/bin/package.js
MIT
function packageDmg (cb) { console.log('Mac: Creating dmg...') const appDmg = require('appdmg') const targetPath = path.join(DIST_PATH, BUILD_NAME + '.dmg') rimraf.sync(targetPath) // Create a .dmg (Mac disk image) file, for easy user installation. const dmgOpts = { basepath: config.ROOT_PATH, target: targetPath, specification: { title: config.APP_NAME, icon: config.APP_ICON + '.icns', background: path.join(config.STATIC_PATH, 'appdmg.png'), 'icon-size': 128, contents: [ { x: 122, y: 240, type: 'file', path: appPath }, { x: 380, y: 240, type: 'link', path: '/Applications' }, // Hide hidden icons out of view, for users who have hidden files shown. // https://github.com/LinusU/node-appdmg/issues/45#issuecomment-153924954 { x: 50, y: 500, type: 'position', path: '.background' }, { x: 100, y: 500, type: 'position', path: '.DS_Store' }, { x: 150, y: 500, type: 'position', path: '.Trashes' }, { x: 200, y: 500, type: 'position', path: '.VolumeIcon.icns' } ] } } const dmg = appDmg(dmgOpts) dmg.once('error', cb) dmg.on('progress', function (info) { if (info.type === 'step-begin') console.log(info.title + '...') }) dmg.once('finish', function (info) { console.log('Mac: Created dmg.') cb(null) }) }
Builds app binaries for Mac, Windows, and Linux.
packageDmg
javascript
webtorrent/webtorrent-desktop
bin/package.js
https://github.com/webtorrent/webtorrent-desktop/blob/master/bin/package.js
MIT
function buildWin32 (cb) { const installer = require('electron-winstaller') console.log('Windows: Packaging electron...') /* * Path to folder with the following files: * - Windows Authenticode private key and cert (authenticode.p12) * - Windows Authenticode password file (authenticode.txt) */ let CERT_PATH try { fs.accessSync('D:') CERT_PATH = 'D:' } catch (err) { CERT_PATH = path.join(os.homedir(), 'Desktop') } electronPackager(Object.assign({}, all, win32)).then(function (buildPath) { console.log('Windows: Packaged electron. ' + buildPath) let signWithParams if (process.platform === 'win32') { if (argv.sign) { const certificateFile = path.join(CERT_PATH, 'authenticode.p12') const certificatePassword = fs.readFileSync(path.join(CERT_PATH, 'authenticode.txt'), 'utf8') const timestampServer = 'http://timestamp.comodoca.com' signWithParams = `/a /f "${certificateFile}" /p "${certificatePassword}" /tr "${timestampServer}" /td sha256` } else { printWarning() } } else { printWarning() } const tasks = [] buildPath.forEach(function (filesPath) { if (argv.package === 'exe' || argv.package === 'all') { tasks.push((cb) => packageInstaller(filesPath, cb)) } if (argv.package === 'portable' || argv.package === 'all') { tasks.push((cb) => packagePortable(filesPath, cb)) } }) series(tasks, cb) function packageInstaller (filesPath, cb) { console.log('Windows: Creating installer...') installer.createWindowsInstaller({ appDirectory: filesPath, authors: config.APP_TEAM, description: config.APP_NAME, exe: config.APP_NAME + '.exe', iconUrl: config.GITHUB_URL_RAW + '/static/' + config.APP_NAME + '.ico', loadingGif: path.join(config.STATIC_PATH, 'loading.gif'), name: config.APP_NAME, noMsi: true, outputDirectory: DIST_PATH, productName: config.APP_NAME, // TODO: Re-enable Windows 64-bit delta updates when we confirm that they // work correctly in the presence of the "ia32" .nupkg files. I // (feross) noticed them listed in the 64-bit RELEASES file and // manually edited them out for the v0.17 release. Shipping only // full updates for now will work fine, with no ill-effects. // remoteReleases: config.GITHUB_URL, /** * If you hit a "GitHub API rate limit exceeded" error, set this token! */ // remoteToken: process.env.WEBTORRENT_GITHUB_API_TOKEN, setupExe: config.APP_NAME + 'Setup-v' + config.APP_VERSION + '.exe', setupIcon: config.APP_ICON + '.ico', signWithParams, title: config.APP_NAME, usePackageJson: false, version: pkg.version }) .then(function () { console.log('Windows: Created installer.') /** * Delete extraneous Squirrel files (i.e. *.nupkg delta files for older * versions of the app) */ fs.readdirSync(DIST_PATH) .filter((name) => name.endsWith('.nupkg') && !name.includes(pkg.version)) .forEach((filename) => { fs.unlinkSync(path.join(DIST_PATH, filename)) }) cb(null) }) .catch(cb) } function packagePortable (filesPath, cb) { console.log('Windows: Creating portable app...') const portablePath = path.join(filesPath, 'Portable Settings') fs.mkdirSync(portablePath, { recursive: true }) const downloadsPath = path.join(portablePath, 'Downloads') fs.mkdirSync(downloadsPath, { recursive: true }) const tempPath = path.join(portablePath, 'Temp') fs.mkdirSync(tempPath, { recursive: true }) const inPath = path.join(DIST_PATH, path.basename(filesPath)) const outPath = path.join(DIST_PATH, BUILD_NAME + '-win.zip') zip.zipSync(inPath, outPath) console.log('Windows: Created portable app.') cb(null) } }).catch(function (err) { cb(err) }) }
Builds app binaries for Mac, Windows, and Linux.
buildWin32
javascript
webtorrent/webtorrent-desktop
bin/package.js
https://github.com/webtorrent/webtorrent-desktop/blob/master/bin/package.js
MIT
function packageInstaller (filesPath, cb) { console.log('Windows: Creating installer...') installer.createWindowsInstaller({ appDirectory: filesPath, authors: config.APP_TEAM, description: config.APP_NAME, exe: config.APP_NAME + '.exe', iconUrl: config.GITHUB_URL_RAW + '/static/' + config.APP_NAME + '.ico', loadingGif: path.join(config.STATIC_PATH, 'loading.gif'), name: config.APP_NAME, noMsi: true, outputDirectory: DIST_PATH, productName: config.APP_NAME, // TODO: Re-enable Windows 64-bit delta updates when we confirm that they // work correctly in the presence of the "ia32" .nupkg files. I // (feross) noticed them listed in the 64-bit RELEASES file and // manually edited them out for the v0.17 release. Shipping only // full updates for now will work fine, with no ill-effects. // remoteReleases: config.GITHUB_URL, /** * If you hit a "GitHub API rate limit exceeded" error, set this token! */ // remoteToken: process.env.WEBTORRENT_GITHUB_API_TOKEN, setupExe: config.APP_NAME + 'Setup-v' + config.APP_VERSION + '.exe', setupIcon: config.APP_ICON + '.ico', signWithParams, title: config.APP_NAME, usePackageJson: false, version: pkg.version }) .then(function () { console.log('Windows: Created installer.') /** * Delete extraneous Squirrel files (i.e. *.nupkg delta files for older * versions of the app) */ fs.readdirSync(DIST_PATH) .filter((name) => name.endsWith('.nupkg') && !name.includes(pkg.version)) .forEach((filename) => { fs.unlinkSync(path.join(DIST_PATH, filename)) }) cb(null) }) .catch(cb) }
Builds app binaries for Mac, Windows, and Linux.
packageInstaller
javascript
webtorrent/webtorrent-desktop
bin/package.js
https://github.com/webtorrent/webtorrent-desktop/blob/master/bin/package.js
MIT
function packagePortable (filesPath, cb) { console.log('Windows: Creating portable app...') const portablePath = path.join(filesPath, 'Portable Settings') fs.mkdirSync(portablePath, { recursive: true }) const downloadsPath = path.join(portablePath, 'Downloads') fs.mkdirSync(downloadsPath, { recursive: true }) const tempPath = path.join(portablePath, 'Temp') fs.mkdirSync(tempPath, { recursive: true }) const inPath = path.join(DIST_PATH, path.basename(filesPath)) const outPath = path.join(DIST_PATH, BUILD_NAME + '-win.zip') zip.zipSync(inPath, outPath) console.log('Windows: Created portable app.') cb(null) }
Delete extraneous Squirrel files (i.e. *.nupkg delta files for older versions of the app)
packagePortable
javascript
webtorrent/webtorrent-desktop
bin/package.js
https://github.com/webtorrent/webtorrent-desktop/blob/master/bin/package.js
MIT
function buildLinux (cb) { console.log('Linux: Packaging electron...') electronPackager(Object.assign({}, all, linux)).then(function (buildPath) { console.log('Linux: Packaged electron. ' + buildPath) const tasks = [] buildPath.forEach(function (filesPath) { const destArch = filesPath.split('-').pop() if (argv.package === 'deb' || argv.package === 'all') { tasks.push((cb) => packageDeb(filesPath, destArch, cb)) } if (argv.package === 'rpm' || argv.package === 'all') { tasks.push((cb) => packageRpm(filesPath, destArch, cb)) } if (argv.package === 'zip' || argv.package === 'all') { tasks.push((cb) => packageZip(filesPath, destArch, cb)) } }) series(tasks, cb) }).catch(function (err) { cb(err) }) function packageDeb (filesPath, destArch, cb) { // Linux convention for Debian based 'x64' is 'amd64' if (destArch === 'x64') { destArch = 'amd64' } // Create .deb file for Debian-based platforms console.log(`Linux: Creating ${destArch} deb...`) const installer = require('electron-installer-debian') const options = { src: filesPath + '/', dest: DIST_PATH, arch: destArch, bin: 'WebTorrent', icon: { '48x48': path.join(config.STATIC_PATH, 'linux/share/icons/hicolor/48x48/apps/webtorrent-desktop.png'), '256x256': path.join(config.STATIC_PATH, 'linux/share/icons/hicolor/256x256/apps/webtorrent-desktop.png') }, categories: ['Network', 'FileTransfer', 'P2P'], mimeType: ['application/x-bittorrent', 'x-scheme-handler/magnet', 'x-scheme-handler/stream-magnet'], desktopTemplate: path.join(config.STATIC_PATH, 'linux/webtorrent-desktop.ejs'), lintianOverrides: [ 'unstripped-binary-or-object', 'embedded-library', 'missing-dependency-on-libc', 'changelog-file-missing-in-native-package', 'description-synopsis-is-duplicated', 'setuid-binary', 'binary-without-manpage', 'shlib-with-executable-bit' ] } installer(options).then( () => { console.log(`Linux: Created ${destArch} deb.`) cb(null) }, (err) => cb(err) ) } function packageRpm (filesPath, destArch, cb) { // Linux convention for RedHat based 'x64' is 'x86_64' if (destArch === 'x64') { destArch = 'x86_64' } // Create .rpm file for RedHat-based platforms console.log(`Linux: Creating ${destArch} rpm...`) const installer = require('electron-installer-redhat') const options = { src: filesPath + '/', dest: DIST_PATH, arch: destArch, bin: 'WebTorrent', icon: { '48x48': path.join(config.STATIC_PATH, 'linux/share/icons/hicolor/48x48/apps/webtorrent-desktop.png'), '256x256': path.join(config.STATIC_PATH, 'linux/share/icons/hicolor/256x256/apps/webtorrent-desktop.png') }, categories: ['Network', 'FileTransfer', 'P2P'], mimeType: ['application/x-bittorrent', 'x-scheme-handler/magnet', 'x-scheme-handler/stream-magnet'], desktopTemplate: path.join(config.STATIC_PATH, 'linux/webtorrent-desktop.ejs') } installer(options).then( () => { console.log(`Linux: Created ${destArch} rpm.`) cb(null) }, (err) => cb(err) ) } function packageZip (filesPath, destArch, cb) { // Create .zip file for Linux console.log(`Linux: Creating ${destArch} zip...`) const inPath = path.join(DIST_PATH, path.basename(filesPath)) const outPath = path.join(DIST_PATH, `${BUILD_NAME}-linux-${destArch}.zip`) zip.zipSync(inPath, outPath) console.log(`Linux: Created ${destArch} zip.`) cb(null) } }
Delete extraneous Squirrel files (i.e. *.nupkg delta files for older versions of the app)
buildLinux
javascript
webtorrent/webtorrent-desktop
bin/package.js
https://github.com/webtorrent/webtorrent-desktop/blob/master/bin/package.js
MIT
function packageDeb (filesPath, destArch, cb) { // Linux convention for Debian based 'x64' is 'amd64' if (destArch === 'x64') { destArch = 'amd64' } // Create .deb file for Debian-based platforms console.log(`Linux: Creating ${destArch} deb...`) const installer = require('electron-installer-debian') const options = { src: filesPath + '/', dest: DIST_PATH, arch: destArch, bin: 'WebTorrent', icon: { '48x48': path.join(config.STATIC_PATH, 'linux/share/icons/hicolor/48x48/apps/webtorrent-desktop.png'), '256x256': path.join(config.STATIC_PATH, 'linux/share/icons/hicolor/256x256/apps/webtorrent-desktop.png') }, categories: ['Network', 'FileTransfer', 'P2P'], mimeType: ['application/x-bittorrent', 'x-scheme-handler/magnet', 'x-scheme-handler/stream-magnet'], desktopTemplate: path.join(config.STATIC_PATH, 'linux/webtorrent-desktop.ejs'), lintianOverrides: [ 'unstripped-binary-or-object', 'embedded-library', 'missing-dependency-on-libc', 'changelog-file-missing-in-native-package', 'description-synopsis-is-duplicated', 'setuid-binary', 'binary-without-manpage', 'shlib-with-executable-bit' ] } installer(options).then( () => { console.log(`Linux: Created ${destArch} deb.`) cb(null) }, (err) => cb(err) ) }
Delete extraneous Squirrel files (i.e. *.nupkg delta files for older versions of the app)
packageDeb
javascript
webtorrent/webtorrent-desktop
bin/package.js
https://github.com/webtorrent/webtorrent-desktop/blob/master/bin/package.js
MIT
function packageRpm (filesPath, destArch, cb) { // Linux convention for RedHat based 'x64' is 'x86_64' if (destArch === 'x64') { destArch = 'x86_64' } // Create .rpm file for RedHat-based platforms console.log(`Linux: Creating ${destArch} rpm...`) const installer = require('electron-installer-redhat') const options = { src: filesPath + '/', dest: DIST_PATH, arch: destArch, bin: 'WebTorrent', icon: { '48x48': path.join(config.STATIC_PATH, 'linux/share/icons/hicolor/48x48/apps/webtorrent-desktop.png'), '256x256': path.join(config.STATIC_PATH, 'linux/share/icons/hicolor/256x256/apps/webtorrent-desktop.png') }, categories: ['Network', 'FileTransfer', 'P2P'], mimeType: ['application/x-bittorrent', 'x-scheme-handler/magnet', 'x-scheme-handler/stream-magnet'], desktopTemplate: path.join(config.STATIC_PATH, 'linux/webtorrent-desktop.ejs') } installer(options).then( () => { console.log(`Linux: Created ${destArch} rpm.`) cb(null) }, (err) => cb(err) ) }
Delete extraneous Squirrel files (i.e. *.nupkg delta files for older versions of the app)
packageRpm
javascript
webtorrent/webtorrent-desktop
bin/package.js
https://github.com/webtorrent/webtorrent-desktop/blob/master/bin/package.js
MIT
function packageZip (filesPath, destArch, cb) { // Create .zip file for Linux console.log(`Linux: Creating ${destArch} zip...`) const inPath = path.join(DIST_PATH, path.basename(filesPath)) const outPath = path.join(DIST_PATH, `${BUILD_NAME}-linux-${destArch}.zip`) zip.zipSync(inPath, outPath) console.log(`Linux: Created ${destArch} zip.`) cb(null) }
Delete extraneous Squirrel files (i.e. *.nupkg delta files for older versions of the app)
packageZip
javascript
webtorrent/webtorrent-desktop
bin/package.js
https://github.com/webtorrent/webtorrent-desktop/blob/master/bin/package.js
MIT
function printDone (err) { if (err) console.error(err.message || err) }
Delete extraneous Squirrel files (i.e. *.nupkg delta files for older versions of the app)
printDone
javascript
webtorrent/webtorrent-desktop
bin/package.js
https://github.com/webtorrent/webtorrent-desktop/blob/master/bin/package.js
MIT
function printWarning () { console.log(fs.readFileSync(path.join(__dirname, 'warning.txt'), 'utf8')) }
Delete extraneous Squirrel files (i.e. *.nupkg delta files for older versions of the app)
printWarning
javascript
webtorrent/webtorrent-desktop
bin/package.js
https://github.com/webtorrent/webtorrent-desktop/blob/master/bin/package.js
MIT
function init () { const get = require('simple-get') get.concat(ANNOUNCEMENT_URL, onResponse) }
In certain situations, the WebTorrent team may need to show an announcement to all WebTorrent Desktop users. For example: a security notice, or an update notification (if the auto-updater stops working). When there is an announcement, the `ANNOUNCEMENT_URL` endpoint should return an HTTP 200 status code with a JSON object like this: { "title": "WebTorrent Desktop Announcement", "message": "Security Issue in v0.xx", "detail": "Please update to v0.xx as soon as possible..." }
init
javascript
webtorrent/webtorrent-desktop
src/main/announcement.js
https://github.com/webtorrent/webtorrent-desktop/blob/master/src/main/announcement.js
MIT
function onResponse (err, res, data) { if (err) return log(`Failed to retrieve announcement: ${err.message}`) if (res.statusCode !== 200) return log('No announcement available') try { data = JSON.parse(data.toString()) } catch (err) { // Support plaintext announcement messages, using a default title. data = { title: 'WebTorrent Desktop Announcement', message: data.toString(), detail: data.toString() } } dialog.showMessageBox({ type: 'info', buttons: ['OK'], title: data.title, message: data.message, detail: data.detail }) }
In certain situations, the WebTorrent team may need to show an announcement to all WebTorrent Desktop users. For example: a security notice, or an update notification (if the auto-updater stops working). When there is an announcement, the `ANNOUNCEMENT_URL` endpoint should return an HTTP 200 status code with a JSON object like this: { "title": "WebTorrent Desktop Announcement", "message": "Security Issue in v0.xx", "detail": "Please update to v0.xx as soon as possible..." }
onResponse
javascript
webtorrent/webtorrent-desktop
src/main/announcement.js
https://github.com/webtorrent/webtorrent-desktop/blob/master/src/main/announcement.js
MIT
function openSeedFile () { if (!windows.main.win) return log('openSeedFile') const opts = { title: 'Select a file for the torrent.', properties: ['openFile'] } showOpenSeed(opts) }
Show open dialog to create a single-file torrent.
openSeedFile
javascript
webtorrent/webtorrent-desktop
src/main/dialog.js
https://github.com/webtorrent/webtorrent-desktop/blob/master/src/main/dialog.js
MIT
function openSeedDirectory () { if (!windows.main.win) return log('openSeedDirectory') const opts = process.platform === 'darwin' ? { title: 'Select a file or folder for the torrent.', properties: ['openFile', 'openDirectory'] } : { title: 'Select a folder for the torrent.', properties: ['openDirectory'] } showOpenSeed(opts) }
Show open dialog to create a single-file torrent.
openSeedDirectory
javascript
webtorrent/webtorrent-desktop
src/main/dialog.js
https://github.com/webtorrent/webtorrent-desktop/blob/master/src/main/dialog.js
MIT
function openFiles () { if (!windows.main.win) return log('openFiles') const opts = process.platform === 'darwin' ? { title: 'Select a file or folder to add.', properties: ['openFile', 'openDirectory'] } : { title: 'Select a file to add.', properties: ['openFile'] } setTitle(opts.title) const selectedPaths = dialog.showOpenDialogSync(windows.main.win, opts) resetTitle() if (!Array.isArray(selectedPaths)) return windows.main.dispatch('onOpen', selectedPaths) }
Show open dialog to create a single-file torrent.
openFiles
javascript
webtorrent/webtorrent-desktop
src/main/dialog.js
https://github.com/webtorrent/webtorrent-desktop/blob/master/src/main/dialog.js
MIT
function openTorrentFile () { if (!windows.main.win) return log('openTorrentFile') const opts = { title: 'Select a .torrent file.', filters: [{ name: 'Torrent Files', extensions: ['torrent'] }], properties: ['openFile', 'multiSelections'] } setTitle(opts.title) const selectedPaths = dialog.showOpenDialogSync(windows.main.win, opts) resetTitle() if (!Array.isArray(selectedPaths)) return selectedPaths.forEach(selectedPath => { windows.main.dispatch('addTorrent', selectedPath) }) }
Show open dialog to create a single-file torrent.
openTorrentFile
javascript
webtorrent/webtorrent-desktop
src/main/dialog.js
https://github.com/webtorrent/webtorrent-desktop/blob/master/src/main/dialog.js
MIT
function openTorrentAddress () { log('openTorrentAddress') windows.main.dispatch('openTorrentAddress') }
Show open dialog to create a single-file torrent.
openTorrentAddress
javascript
webtorrent/webtorrent-desktop
src/main/dialog.js
https://github.com/webtorrent/webtorrent-desktop/blob/master/src/main/dialog.js
MIT
function setTitle (title) { if (process.platform === 'darwin') { windows.main.dispatch('setTitle', title) } }
Dialogs on do not show a title on Mac, so the window title is used instead.
setTitle
javascript
webtorrent/webtorrent-desktop
src/main/dialog.js
https://github.com/webtorrent/webtorrent-desktop/blob/master/src/main/dialog.js
MIT
function showOpenSeed (opts) { setTitle(opts.title) const selectedPaths = dialog.showOpenDialogSync(windows.main.win, opts) resetTitle() if (!Array.isArray(selectedPaths)) return windows.main.dispatch('showCreateTorrent', selectedPaths) }
Pops up an Open File dialog with the given options. After the user selects files / folders, shows the Create Torrent page.
showOpenSeed
javascript
webtorrent/webtorrent-desktop
src/main/dialog.js
https://github.com/webtorrent/webtorrent-desktop/blob/master/src/main/dialog.js
MIT
function init () { if (!app.dock) return const menu = Menu.buildFromTemplate(getMenuTemplate()) app.dock.setMenu(menu) }
Add a right-click menu to the dock icon. (Mac)
init
javascript
webtorrent/webtorrent-desktop
src/main/dock.js
https://github.com/webtorrent/webtorrent-desktop/blob/master/src/main/dock.js
MIT
function downloadFinished (path) { if (!app.dock) return log(`downloadFinished: ${path}`) app.dock.downloadFinished(path) }
Bounce the Downloads stack if `path` is inside the Downloads folder. (Mac)
downloadFinished
javascript
webtorrent/webtorrent-desktop
src/main/dock.js
https://github.com/webtorrent/webtorrent-desktop/blob/master/src/main/dock.js
MIT
function setBadge (count) { if (process.platform === 'darwin' || (process.platform === 'linux' && app.isUnityRunning())) { log(`setBadge: ${count}`) app.badgeCount = Number(count) } }
Display a counter badge for the app. (Mac, Linux)
setBadge
javascript
webtorrent/webtorrent-desktop
src/main/dock.js
https://github.com/webtorrent/webtorrent-desktop/blob/master/src/main/dock.js
MIT
function getMenuTemplate () { return [ { label: 'Create New Torrent...', accelerator: 'CmdOrCtrl+N', click: () => dialog.openSeedDirectory() }, { label: 'Open Torrent File...', accelerator: 'CmdOrCtrl+O', click: () => dialog.openTorrentFile() }, { label: 'Open Torrent Address...', accelerator: 'CmdOrCtrl+U', click: () => dialog.openTorrentAddress() } ] }
Display a counter badge for the app. (Mac, Linux)
getMenuTemplate
javascript
webtorrent/webtorrent-desktop
src/main/dock.js
https://github.com/webtorrent/webtorrent-desktop/blob/master/src/main/dock.js
MIT
function registerProtocolHandlerWin32 (protocol, name, icon, command) { const protocolKey = new Registry({ hive: Registry.HKCU, // HKEY_CURRENT_USER key: '\\Software\\Classes\\' + protocol }) setProtocol() function setProtocol (err) { if (err) return log.error(err.message) protocolKey.set('', Registry.REG_SZ, name, setURLProtocol) } function setURLProtocol (err) { if (err) return log.error(err.message) protocolKey.set('URL Protocol', Registry.REG_SZ, '', setIcon) } function setIcon (err) { if (err) return log.error(err.message) const iconKey = new Registry({ hive: Registry.HKCU, key: `\\Software\\Classes\\${protocol}\\DefaultIcon` }) iconKey.set('', Registry.REG_SZ, icon, setCommand) } function setCommand (err) { if (err) return log.error(err.message) const commandKey = new Registry({ hive: Registry.HKCU, key: `\\Software\\Classes\\${protocol}\\shell\\open\\command` }) commandKey.set('', Registry.REG_SZ, `${commandToArgs(command)} "%1"`, done) } function done (err) { if (err) return log.error(err.message) } }
To add a protocol handler, the following keys must be added to the Windows registry: HKEY_CLASSES_ROOT $PROTOCOL (Default) = "$NAME" URL Protocol = "" DefaultIcon (Default) = "$ICON" shell open command (Default) = "$COMMAND" "%1" Source: https://msdn.microsoft.com/en-us/library/aa767914.aspx However, the "HKEY_CLASSES_ROOT" key can only be written by the Administrator user. So, we instead write to "HKEY_CURRENT_USER\Software\Classes", which is inherited by "HKEY_CLASSES_ROOT" anyway, and can be written by unprivileged users.
registerProtocolHandlerWin32
javascript
webtorrent/webtorrent-desktop
src/main/handlers.js
https://github.com/webtorrent/webtorrent-desktop/blob/master/src/main/handlers.js
MIT
function setProtocol (err) { if (err) return log.error(err.message) protocolKey.set('', Registry.REG_SZ, name, setURLProtocol) }
To add a protocol handler, the following keys must be added to the Windows registry: HKEY_CLASSES_ROOT $PROTOCOL (Default) = "$NAME" URL Protocol = "" DefaultIcon (Default) = "$ICON" shell open command (Default) = "$COMMAND" "%1" Source: https://msdn.microsoft.com/en-us/library/aa767914.aspx However, the "HKEY_CLASSES_ROOT" key can only be written by the Administrator user. So, we instead write to "HKEY_CURRENT_USER\Software\Classes", which is inherited by "HKEY_CLASSES_ROOT" anyway, and can be written by unprivileged users.
setProtocol
javascript
webtorrent/webtorrent-desktop
src/main/handlers.js
https://github.com/webtorrent/webtorrent-desktop/blob/master/src/main/handlers.js
MIT
function setURLProtocol (err) { if (err) return log.error(err.message) protocolKey.set('URL Protocol', Registry.REG_SZ, '', setIcon) }
To add a protocol handler, the following keys must be added to the Windows registry: HKEY_CLASSES_ROOT $PROTOCOL (Default) = "$NAME" URL Protocol = "" DefaultIcon (Default) = "$ICON" shell open command (Default) = "$COMMAND" "%1" Source: https://msdn.microsoft.com/en-us/library/aa767914.aspx However, the "HKEY_CLASSES_ROOT" key can only be written by the Administrator user. So, we instead write to "HKEY_CURRENT_USER\Software\Classes", which is inherited by "HKEY_CLASSES_ROOT" anyway, and can be written by unprivileged users.
setURLProtocol
javascript
webtorrent/webtorrent-desktop
src/main/handlers.js
https://github.com/webtorrent/webtorrent-desktop/blob/master/src/main/handlers.js
MIT
function setIcon (err) { if (err) return log.error(err.message) const iconKey = new Registry({ hive: Registry.HKCU, key: `\\Software\\Classes\\${protocol}\\DefaultIcon` }) iconKey.set('', Registry.REG_SZ, icon, setCommand) }
To add a protocol handler, the following keys must be added to the Windows registry: HKEY_CLASSES_ROOT $PROTOCOL (Default) = "$NAME" URL Protocol = "" DefaultIcon (Default) = "$ICON" shell open command (Default) = "$COMMAND" "%1" Source: https://msdn.microsoft.com/en-us/library/aa767914.aspx However, the "HKEY_CLASSES_ROOT" key can only be written by the Administrator user. So, we instead write to "HKEY_CURRENT_USER\Software\Classes", which is inherited by "HKEY_CLASSES_ROOT" anyway, and can be written by unprivileged users.
setIcon
javascript
webtorrent/webtorrent-desktop
src/main/handlers.js
https://github.com/webtorrent/webtorrent-desktop/blob/master/src/main/handlers.js
MIT
function setCommand (err) { if (err) return log.error(err.message) const commandKey = new Registry({ hive: Registry.HKCU, key: `\\Software\\Classes\\${protocol}\\shell\\open\\command` }) commandKey.set('', Registry.REG_SZ, `${commandToArgs(command)} "%1"`, done) }
To add a protocol handler, the following keys must be added to the Windows registry: HKEY_CLASSES_ROOT $PROTOCOL (Default) = "$NAME" URL Protocol = "" DefaultIcon (Default) = "$ICON" shell open command (Default) = "$COMMAND" "%1" Source: https://msdn.microsoft.com/en-us/library/aa767914.aspx However, the "HKEY_CLASSES_ROOT" key can only be written by the Administrator user. So, we instead write to "HKEY_CURRENT_USER\Software\Classes", which is inherited by "HKEY_CLASSES_ROOT" anyway, and can be written by unprivileged users.
setCommand
javascript
webtorrent/webtorrent-desktop
src/main/handlers.js
https://github.com/webtorrent/webtorrent-desktop/blob/master/src/main/handlers.js
MIT
function done (err) { if (err) return log.error(err.message) }
To add a protocol handler, the following keys must be added to the Windows registry: HKEY_CLASSES_ROOT $PROTOCOL (Default) = "$NAME" URL Protocol = "" DefaultIcon (Default) = "$ICON" shell open command (Default) = "$COMMAND" "%1" Source: https://msdn.microsoft.com/en-us/library/aa767914.aspx However, the "HKEY_CLASSES_ROOT" key can only be written by the Administrator user. So, we instead write to "HKEY_CURRENT_USER\Software\Classes", which is inherited by "HKEY_CLASSES_ROOT" anyway, and can be written by unprivileged users.
done
javascript
webtorrent/webtorrent-desktop
src/main/handlers.js
https://github.com/webtorrent/webtorrent-desktop/blob/master/src/main/handlers.js
MIT
function registerFileHandlerWin32 (ext, id, name, icon, command) { setExt() function setExt () { const extKey = new Registry({ hive: Registry.HKCU, // HKEY_CURRENT_USER key: `\\Software\\Classes\\${ext}` }) extKey.set('', Registry.REG_SZ, id, setId) } function setId (err) { if (err) return log.error(err.message) const idKey = new Registry({ hive: Registry.HKCU, key: `\\Software\\Classes\\${id}` }) idKey.set('', Registry.REG_SZ, name, setIcon) } function setIcon (err) { if (err) return log.error(err.message) const iconKey = new Registry({ hive: Registry.HKCU, key: `\\Software\\Classes\\${id}\\DefaultIcon` }) iconKey.set('', Registry.REG_SZ, icon, setCommand) } function setCommand (err) { if (err) return log.error(err.message) const commandKey = new Registry({ hive: Registry.HKCU, key: `\\Software\\Classes\\${id}\\shell\\open\\command` }) commandKey.set('', Registry.REG_SZ, `${commandToArgs(command)} "%1"`, done) } function done (err) { if (err) return log.error(err.message) } }
To add a file handler, the following keys must be added to the Windows registry: HKEY_CLASSES_ROOT $EXTENSION (Default) = "$EXTENSION_ID" $EXTENSION_ID (Default) = "$NAME" DefaultIcon (Default) = "$ICON" shell open command (Default) = "$COMMAND" "%1"
registerFileHandlerWin32
javascript
webtorrent/webtorrent-desktop
src/main/handlers.js
https://github.com/webtorrent/webtorrent-desktop/blob/master/src/main/handlers.js
MIT
function setExt () { const extKey = new Registry({ hive: Registry.HKCU, // HKEY_CURRENT_USER key: `\\Software\\Classes\\${ext}` }) extKey.set('', Registry.REG_SZ, id, setId) }
To add a file handler, the following keys must be added to the Windows registry: HKEY_CLASSES_ROOT $EXTENSION (Default) = "$EXTENSION_ID" $EXTENSION_ID (Default) = "$NAME" DefaultIcon (Default) = "$ICON" shell open command (Default) = "$COMMAND" "%1"
setExt
javascript
webtorrent/webtorrent-desktop
src/main/handlers.js
https://github.com/webtorrent/webtorrent-desktop/blob/master/src/main/handlers.js
MIT
function setId (err) { if (err) return log.error(err.message) const idKey = new Registry({ hive: Registry.HKCU, key: `\\Software\\Classes\\${id}` }) idKey.set('', Registry.REG_SZ, name, setIcon) }
To add a file handler, the following keys must be added to the Windows registry: HKEY_CLASSES_ROOT $EXTENSION (Default) = "$EXTENSION_ID" $EXTENSION_ID (Default) = "$NAME" DefaultIcon (Default) = "$ICON" shell open command (Default) = "$COMMAND" "%1"
setId
javascript
webtorrent/webtorrent-desktop
src/main/handlers.js
https://github.com/webtorrent/webtorrent-desktop/blob/master/src/main/handlers.js
MIT
function setIcon (err) { if (err) return log.error(err.message) const iconKey = new Registry({ hive: Registry.HKCU, key: `\\Software\\Classes\\${id}\\DefaultIcon` }) iconKey.set('', Registry.REG_SZ, icon, setCommand) }
To add a file handler, the following keys must be added to the Windows registry: HKEY_CLASSES_ROOT $EXTENSION (Default) = "$EXTENSION_ID" $EXTENSION_ID (Default) = "$NAME" DefaultIcon (Default) = "$ICON" shell open command (Default) = "$COMMAND" "%1"
setIcon
javascript
webtorrent/webtorrent-desktop
src/main/handlers.js
https://github.com/webtorrent/webtorrent-desktop/blob/master/src/main/handlers.js
MIT
function setCommand (err) { if (err) return log.error(err.message) const commandKey = new Registry({ hive: Registry.HKCU, key: `\\Software\\Classes\\${id}\\shell\\open\\command` }) commandKey.set('', Registry.REG_SZ, `${commandToArgs(command)} "%1"`, done) }
To add a file handler, the following keys must be added to the Windows registry: HKEY_CLASSES_ROOT $EXTENSION (Default) = "$EXTENSION_ID" $EXTENSION_ID (Default) = "$NAME" DefaultIcon (Default) = "$ICON" shell open command (Default) = "$COMMAND" "%1"
setCommand
javascript
webtorrent/webtorrent-desktop
src/main/handlers.js
https://github.com/webtorrent/webtorrent-desktop/blob/master/src/main/handlers.js
MIT
function done (err) { if (err) return log.error(err.message) }
To add a file handler, the following keys must be added to the Windows registry: HKEY_CLASSES_ROOT $EXTENSION (Default) = "$EXTENSION_ID" $EXTENSION_ID (Default) = "$NAME" DefaultIcon (Default) = "$ICON" shell open command (Default) = "$COMMAND" "%1"
done
javascript
webtorrent/webtorrent-desktop
src/main/handlers.js
https://github.com/webtorrent/webtorrent-desktop/blob/master/src/main/handlers.js
MIT
function uninstallWin32 () { const Registry = require('winreg') unregisterProtocolHandlerWin32('magnet', EXEC_COMMAND) unregisterProtocolHandlerWin32('stream-magnet', EXEC_COMMAND) unregisterFileHandlerWin32('.torrent', 'io.webtorrent.torrent', EXEC_COMMAND) function unregisterProtocolHandlerWin32 (protocol, command) { getCommand() function getCommand () { const commandKey = new Registry({ hive: Registry.HKCU, // HKEY_CURRENT_USER key: `\\Software\\Classes\\${protocol}\\shell\\open\\command` }) commandKey.get('', (err, item) => { if (!err && item.value.indexOf(commandToArgs(command)) >= 0) { destroyProtocol() } }) } function destroyProtocol () { const protocolKey = new Registry({ hive: Registry.HKCU, key: `\\Software\\Classes\\${protocol}` }) protocolKey.destroy(() => {}) } } function unregisterFileHandlerWin32 (ext, id, command) { eraseId() function eraseId () { const idKey = new Registry({ hive: Registry.HKCU, // HKEY_CURRENT_USER key: `\\Software\\Classes\\${id}` }) idKey.destroy(getExt) } function getExt () { const extKey = new Registry({ hive: Registry.HKCU, key: `\\Software\\Classes\\${ext}` }) extKey.get('', (err, item) => { if (!err && item.value === id) { destroyExt() } }) } function destroyExt () { const extKey = new Registry({ hive: Registry.HKCU, // HKEY_CURRENT_USER key: `\\Software\\Classes\\${ext}` }) extKey.destroy(() => {}) } } }
To add a file handler, the following keys must be added to the Windows registry: HKEY_CLASSES_ROOT $EXTENSION (Default) = "$EXTENSION_ID" $EXTENSION_ID (Default) = "$NAME" DefaultIcon (Default) = "$ICON" shell open command (Default) = "$COMMAND" "%1"
uninstallWin32
javascript
webtorrent/webtorrent-desktop
src/main/handlers.js
https://github.com/webtorrent/webtorrent-desktop/blob/master/src/main/handlers.js
MIT
function unregisterProtocolHandlerWin32 (protocol, command) { getCommand() function getCommand () { const commandKey = new Registry({ hive: Registry.HKCU, // HKEY_CURRENT_USER key: `\\Software\\Classes\\${protocol}\\shell\\open\\command` }) commandKey.get('', (err, item) => { if (!err && item.value.indexOf(commandToArgs(command)) >= 0) { destroyProtocol() } }) } function destroyProtocol () { const protocolKey = new Registry({ hive: Registry.HKCU, key: `\\Software\\Classes\\${protocol}` }) protocolKey.destroy(() => {}) } }
To add a file handler, the following keys must be added to the Windows registry: HKEY_CLASSES_ROOT $EXTENSION (Default) = "$EXTENSION_ID" $EXTENSION_ID (Default) = "$NAME" DefaultIcon (Default) = "$ICON" shell open command (Default) = "$COMMAND" "%1"
unregisterProtocolHandlerWin32
javascript
webtorrent/webtorrent-desktop
src/main/handlers.js
https://github.com/webtorrent/webtorrent-desktop/blob/master/src/main/handlers.js
MIT
function getCommand () { const commandKey = new Registry({ hive: Registry.HKCU, // HKEY_CURRENT_USER key: `\\Software\\Classes\\${protocol}\\shell\\open\\command` }) commandKey.get('', (err, item) => { if (!err && item.value.indexOf(commandToArgs(command)) >= 0) { destroyProtocol() } }) }
To add a file handler, the following keys must be added to the Windows registry: HKEY_CLASSES_ROOT $EXTENSION (Default) = "$EXTENSION_ID" $EXTENSION_ID (Default) = "$NAME" DefaultIcon (Default) = "$ICON" shell open command (Default) = "$COMMAND" "%1"
getCommand
javascript
webtorrent/webtorrent-desktop
src/main/handlers.js
https://github.com/webtorrent/webtorrent-desktop/blob/master/src/main/handlers.js
MIT
function destroyProtocol () { const protocolKey = new Registry({ hive: Registry.HKCU, key: `\\Software\\Classes\\${protocol}` }) protocolKey.destroy(() => {}) }
To add a file handler, the following keys must be added to the Windows registry: HKEY_CLASSES_ROOT $EXTENSION (Default) = "$EXTENSION_ID" $EXTENSION_ID (Default) = "$NAME" DefaultIcon (Default) = "$ICON" shell open command (Default) = "$COMMAND" "%1"
destroyProtocol
javascript
webtorrent/webtorrent-desktop
src/main/handlers.js
https://github.com/webtorrent/webtorrent-desktop/blob/master/src/main/handlers.js
MIT
function unregisterFileHandlerWin32 (ext, id, command) { eraseId() function eraseId () { const idKey = new Registry({ hive: Registry.HKCU, // HKEY_CURRENT_USER key: `\\Software\\Classes\\${id}` }) idKey.destroy(getExt) } function getExt () { const extKey = new Registry({ hive: Registry.HKCU, key: `\\Software\\Classes\\${ext}` }) extKey.get('', (err, item) => { if (!err && item.value === id) { destroyExt() } }) } function destroyExt () { const extKey = new Registry({ hive: Registry.HKCU, // HKEY_CURRENT_USER key: `\\Software\\Classes\\${ext}` }) extKey.destroy(() => {}) } }
To add a file handler, the following keys must be added to the Windows registry: HKEY_CLASSES_ROOT $EXTENSION (Default) = "$EXTENSION_ID" $EXTENSION_ID (Default) = "$NAME" DefaultIcon (Default) = "$ICON" shell open command (Default) = "$COMMAND" "%1"
unregisterFileHandlerWin32
javascript
webtorrent/webtorrent-desktop
src/main/handlers.js
https://github.com/webtorrent/webtorrent-desktop/blob/master/src/main/handlers.js
MIT
function eraseId () { const idKey = new Registry({ hive: Registry.HKCU, // HKEY_CURRENT_USER key: `\\Software\\Classes\\${id}` }) idKey.destroy(getExt) }
To add a file handler, the following keys must be added to the Windows registry: HKEY_CLASSES_ROOT $EXTENSION (Default) = "$EXTENSION_ID" $EXTENSION_ID (Default) = "$NAME" DefaultIcon (Default) = "$ICON" shell open command (Default) = "$COMMAND" "%1"
eraseId
javascript
webtorrent/webtorrent-desktop
src/main/handlers.js
https://github.com/webtorrent/webtorrent-desktop/blob/master/src/main/handlers.js
MIT
function getExt () { const extKey = new Registry({ hive: Registry.HKCU, key: `\\Software\\Classes\\${ext}` }) extKey.get('', (err, item) => { if (!err && item.value === id) { destroyExt() } }) }
To add a file handler, the following keys must be added to the Windows registry: HKEY_CLASSES_ROOT $EXTENSION (Default) = "$EXTENSION_ID" $EXTENSION_ID (Default) = "$NAME" DefaultIcon (Default) = "$ICON" shell open command (Default) = "$COMMAND" "%1"
getExt
javascript
webtorrent/webtorrent-desktop
src/main/handlers.js
https://github.com/webtorrent/webtorrent-desktop/blob/master/src/main/handlers.js
MIT
function destroyExt () { const extKey = new Registry({ hive: Registry.HKCU, // HKEY_CURRENT_USER key: `\\Software\\Classes\\${ext}` }) extKey.destroy(() => {}) }
To add a file handler, the following keys must be added to the Windows registry: HKEY_CLASSES_ROOT $EXTENSION (Default) = "$EXTENSION_ID" $EXTENSION_ID (Default) = "$NAME" DefaultIcon (Default) = "$ICON" shell open command (Default) = "$COMMAND" "%1"
destroyExt
javascript
webtorrent/webtorrent-desktop
src/main/handlers.js
https://github.com/webtorrent/webtorrent-desktop/blob/master/src/main/handlers.js
MIT
function commandToArgs (command) { return command.map((arg) => `"${arg}"`).join(' ') }
To add a file handler, the following keys must be added to the Windows registry: HKEY_CLASSES_ROOT $EXTENSION (Default) = "$EXTENSION_ID" $EXTENSION_ID (Default) = "$NAME" DefaultIcon (Default) = "$ICON" shell open command (Default) = "$COMMAND" "%1"
commandToArgs
javascript
webtorrent/webtorrent-desktop
src/main/handlers.js
https://github.com/webtorrent/webtorrent-desktop/blob/master/src/main/handlers.js
MIT
function log (...args) { if (app.ipcReady) { windows.main.send('log', ...args) } else { app.once('ipcReady', () => windows.main.send('log', ...args)) } }
In the main electron process, we do not use console.log() statements because they do not show up in a convenient location when running the packaged (i.e. production) version of the app. Instead use this module, which sends the logs to the main window where they can be viewed in Developer Tools.
log
javascript
webtorrent/webtorrent-desktop
src/main/log.js
https://github.com/webtorrent/webtorrent-desktop/blob/master/src/main/log.js
MIT
function error (...args) { if (app.ipcReady) { windows.main.send('error', ...args) } else { app.once('ipcReady', () => windows.main.send('error', ...args)) } }
In the main electron process, we do not use console.log() statements because they do not show up in a convenient location when running the packaged (i.e. production) version of the app. Instead use this module, which sends the logs to the main window where they can be viewed in Developer Tools.
error
javascript
webtorrent/webtorrent-desktop
src/main/log.js
https://github.com/webtorrent/webtorrent-desktop/blob/master/src/main/log.js
MIT
function enable () { if (powerSaveBlocker.isStarted(blockId)) { // If a power saver block already exists, do nothing. return } blockId = powerSaveBlocker.start('prevent-display-sleep') log(`powerSaveBlocker.enable: ${blockId}`) }
Block the system from entering low-power (sleep) mode or turning off the display.
enable
javascript
webtorrent/webtorrent-desktop
src/main/power-save-blocker.js
https://github.com/webtorrent/webtorrent-desktop/blob/master/src/main/power-save-blocker.js
MIT
function disable () { if (!powerSaveBlocker.isStarted(blockId)) { // If a power saver block does not exist, do nothing. return } powerSaveBlocker.stop(blockId) log(`powerSaveBlocker.disable: ${blockId}`) }
Stop blocking the system from entering low-power mode.
disable
javascript
webtorrent/webtorrent-desktop
src/main/power-save-blocker.js
https://github.com/webtorrent/webtorrent-desktop/blob/master/src/main/power-save-blocker.js
MIT
function showItemInFolder (path) { log(`showItemInFolder: ${path}`) shell.showItemInFolder(path) }
Show the given file in a file manager. If possible, select the file.
showItemInFolder
javascript
webtorrent/webtorrent-desktop
src/main/shell.js
https://github.com/webtorrent/webtorrent-desktop/blob/master/src/main/shell.js
MIT
function moveItemToTrash (path) { log(`moveItemToTrash: ${path}`) shell.trashItem(path) }
Move the given file to trash and returns a boolean status for the operation.
moveItemToTrash
javascript
webtorrent/webtorrent-desktop
src/main/shell.js
https://github.com/webtorrent/webtorrent-desktop/blob/master/src/main/shell.js
MIT
function enable () { buttons = [ { tooltip: 'Previous Track', icon: PREV_ICON, click: () => windows.main.dispatch('previousTrack') }, { tooltip: 'Pause', icon: PAUSE_ICON, click: () => windows.main.dispatch('playPause') }, { tooltip: 'Next Track', icon: NEXT_ICON, click: () => windows.main.dispatch('nextTrack') } ] update() }
Show the Windows thumbnail toolbar buttons.
enable
javascript
webtorrent/webtorrent-desktop
src/main/thumbar.js
https://github.com/webtorrent/webtorrent-desktop/blob/master/src/main/thumbar.js
MIT
function disable () { buttons = [] update() }
Hide the Windows thumbnail toolbar buttons.
disable
javascript
webtorrent/webtorrent-desktop
src/main/thumbar.js
https://github.com/webtorrent/webtorrent-desktop/blob/master/src/main/thumbar.js
MIT
function onPlayerPause () { if (!isEnabled()) return buttons[PLAY_PAUSE].tooltip = 'Play' buttons[PLAY_PAUSE].icon = PLAY_ICON update() }
Hide the Windows thumbnail toolbar buttons.
onPlayerPause
javascript
webtorrent/webtorrent-desktop
src/main/thumbar.js
https://github.com/webtorrent/webtorrent-desktop/blob/master/src/main/thumbar.js
MIT
function onPlayerPlay () { if (!isEnabled()) return buttons[PLAY_PAUSE].tooltip = 'Pause' buttons[PLAY_PAUSE].icon = PAUSE_ICON update() }
Hide the Windows thumbnail toolbar buttons.
onPlayerPlay
javascript
webtorrent/webtorrent-desktop
src/main/thumbar.js
https://github.com/webtorrent/webtorrent-desktop/blob/master/src/main/thumbar.js
MIT
function onPlayerUpdate (state) { if (!isEnabled()) return buttons[PREV].flags = [state.hasPrevious ? 'enabled' : 'disabled'] buttons[NEXT].flags = [state.hasNext ? 'enabled' : 'disabled'] update() }
Hide the Windows thumbnail toolbar buttons.
onPlayerUpdate
javascript
webtorrent/webtorrent-desktop
src/main/thumbar.js
https://github.com/webtorrent/webtorrent-desktop/blob/master/src/main/thumbar.js
MIT
function isEnabled () { return buttons.length > 0 }
Hide the Windows thumbnail toolbar buttons.
isEnabled
javascript
webtorrent/webtorrent-desktop
src/main/thumbar.js
https://github.com/webtorrent/webtorrent-desktop/blob/master/src/main/thumbar.js
MIT
function hasTray () { return !!tray }
Returns true if there a tray icon is active.
hasTray
javascript
webtorrent/webtorrent-desktop
src/main/tray.js
https://github.com/webtorrent/webtorrent-desktop/blob/master/src/main/tray.js
MIT
function setWindowFocus (flag) { if (!tray) return updateTrayMenu() }
Returns true if there a tray icon is active.
setWindowFocus
javascript
webtorrent/webtorrent-desktop
src/main/tray.js
https://github.com/webtorrent/webtorrent-desktop/blob/master/src/main/tray.js
MIT
function initLinux () { checkLinuxTraySupport(err => { if (!err) createTray() }) }
Returns true if there a tray icon is active.
initLinux
javascript
webtorrent/webtorrent-desktop
src/main/tray.js
https://github.com/webtorrent/webtorrent-desktop/blob/master/src/main/tray.js
MIT
function checkLinuxTraySupport (cb) { const cp = require('child_process') // Check that libappindicator libraries are installed in system. cp.exec('ldconfig -p | grep libappindicator', (err, stdout) => { if (err) return cb(err) cb(null) }) }
Check for libappindicator support before creating tray icon.
checkLinuxTraySupport
javascript
webtorrent/webtorrent-desktop
src/main/tray.js
https://github.com/webtorrent/webtorrent-desktop/blob/master/src/main/tray.js
MIT
function createTray () { tray = new Tray(getIconPath()) // On Windows, left click opens the app, right click opens the context menu. // On Linux, any click (left or right) opens the context menu. tray.on('click', () => windows.main.show()) // Show the tray context menu, and keep the available commands up to date updateTrayMenu() }
Check for libappindicator support before creating tray icon.
createTray
javascript
webtorrent/webtorrent-desktop
src/main/tray.js
https://github.com/webtorrent/webtorrent-desktop/blob/master/src/main/tray.js
MIT
function updateTrayMenu () { const contextMenu = Menu.buildFromTemplate(getMenuTemplate()) tray.setContextMenu(contextMenu) }
Check for libappindicator support before creating tray icon.
updateTrayMenu
javascript
webtorrent/webtorrent-desktop
src/main/tray.js
https://github.com/webtorrent/webtorrent-desktop/blob/master/src/main/tray.js
MIT
function getMenuTemplate () { return [ getToggleItem(), { label: 'Quit', click: () => app.quit() } ] function getToggleItem () { if (windows.main.win.isVisible()) { return { label: 'Hide to tray', click: () => windows.main.hide() } } else { return { label: 'Show WebTorrent', click: () => windows.main.show() } } } }
Check for libappindicator support before creating tray icon.
getMenuTemplate
javascript
webtorrent/webtorrent-desktop
src/main/tray.js
https://github.com/webtorrent/webtorrent-desktop/blob/master/src/main/tray.js
MIT
function getToggleItem () { if (windows.main.win.isVisible()) { return { label: 'Hide to tray', click: () => windows.main.hide() } } else { return { label: 'Show WebTorrent', click: () => windows.main.show() } } }
Check for libappindicator support before creating tray icon.
getToggleItem
javascript
webtorrent/webtorrent-desktop
src/main/tray.js
https://github.com/webtorrent/webtorrent-desktop/blob/master/src/main/tray.js
MIT
function getIconPath () { return process.platform === 'win32' ? config.APP_ICON + '.ico' : config.APP_ICON + '.png' }
Check for libappindicator support before creating tray icon.
getIconPath
javascript
webtorrent/webtorrent-desktop
src/main/tray.js
https://github.com/webtorrent/webtorrent-desktop/blob/master/src/main/tray.js
MIT
function init () { if (process.platform !== 'win32') return app.setUserTasks(getUserTasks()) }
Add a user task menu to the app icon on right-click. (Windows)
init
javascript
webtorrent/webtorrent-desktop
src/main/user-tasks.js
https://github.com/webtorrent/webtorrent-desktop/blob/master/src/main/user-tasks.js
MIT
function getUserTasks () { return [ { arguments: '-n', title: 'Create New Torrent...', description: 'Create a new torrent' }, { arguments: '-o', title: 'Open Torrent File...', description: 'Open a .torrent file' }, { arguments: '-u', title: 'Open Torrent Address...', description: 'Open a torrent from a URL' } ].map(getUserTasksItem) }
Add a user task menu to the app icon on right-click. (Windows)
getUserTasks
javascript
webtorrent/webtorrent-desktop
src/main/user-tasks.js
https://github.com/webtorrent/webtorrent-desktop/blob/master/src/main/user-tasks.js
MIT
function getUserTasksItem (item) { return Object.assign(item, { program: process.execPath, iconPath: process.execPath, iconIndex: 0 }) }
Add a user task menu to the app icon on right-click. (Windows)
getUserTasksItem
javascript
webtorrent/webtorrent-desktop
src/main/user-tasks.js
https://github.com/webtorrent/webtorrent-desktop/blob/master/src/main/user-tasks.js
MIT
function setAspectRatio (aspectRatio) { if (!main.win) return main.win.setAspectRatio(aspectRatio) }
Enforce window aspect ratio. Remove with 0. (Mac)
setAspectRatio
javascript
webtorrent/webtorrent-desktop
src/main/windows/main.js
https://github.com/webtorrent/webtorrent-desktop/blob/master/src/main/windows/main.js
MIT
function setBounds (bounds, maximize) { // Do nothing in fullscreen if (!main.win || main.win.isFullScreen()) { log('setBounds: not setting bounds because already in full screen mode') return } // Maximize or minimize, if the second argument is present if (maximize === true && !main.win.isMaximized()) { log('setBounds: maximizing') main.win.maximize() } else if (maximize === false && main.win.isMaximized()) { log('setBounds: minimizing') main.win.unmaximize() } const willBeMaximized = typeof maximize === 'boolean' ? maximize : main.win.isMaximized() // Assuming we're not maximized or maximizing, set the window size if (!willBeMaximized) { log(`setBounds: setting bounds to ${JSON.stringify(bounds)}`) if (bounds.x === null && bounds.y === null) { // X and Y not specified? By default, center on current screen const scr = screen.getDisplayMatching(main.win.getBounds()) bounds.x = Math.round(scr.bounds.x + (scr.bounds.width / 2) - (bounds.width / 2)) bounds.y = Math.round(scr.bounds.y + (scr.bounds.height / 2) - (bounds.height / 2)) log(`setBounds: centered to ${JSON.stringify(bounds)}`) } // Resize the window's content area (so window border doesn't need to be taken // into account) if (bounds.contentBounds) { main.win.setContentBounds(bounds, true) } else { main.win.setBounds(bounds, true) } } else { log('setBounds: not setting bounds because of window maximization') } }
Change the size of the window. TODO: Clean this up? Seems overly complicated.
setBounds
javascript
webtorrent/webtorrent-desktop
src/main/windows/main.js
https://github.com/webtorrent/webtorrent-desktop/blob/master/src/main/windows/main.js
MIT
function setProgress (progress) { if (!main.win) return main.win.setProgressBar(progress) }
Set progress bar to [0, 1]. Indeterminate when > 1. Remove with < 0.
setProgress
javascript
webtorrent/webtorrent-desktop
src/main/windows/main.js
https://github.com/webtorrent/webtorrent-desktop/blob/master/src/main/windows/main.js
MIT
function setTitle (title) { if (!main.win) return main.win.setTitle(title) }
Set progress bar to [0, 1]. Indeterminate when > 1. Remove with < 0.
setTitle
javascript
webtorrent/webtorrent-desktop
src/main/windows/main.js
https://github.com/webtorrent/webtorrent-desktop/blob/master/src/main/windows/main.js
MIT
function show () { if (!main.win) return main.win.show() }
Set progress bar to [0, 1]. Indeterminate when > 1. Remove with < 0.
show
javascript
webtorrent/webtorrent-desktop
src/main/windows/main.js
https://github.com/webtorrent/webtorrent-desktop/blob/master/src/main/windows/main.js
MIT
function toggleAlwaysOnTop (flag) { if (!main.win) return if (flag == null) { flag = !main.win.isAlwaysOnTop() } log(`toggleAlwaysOnTop ${flag}`) main.win.setAlwaysOnTop(flag) menu.onToggleAlwaysOnTop(flag) }
Set progress bar to [0, 1]. Indeterminate when > 1. Remove with < 0.
toggleAlwaysOnTop
javascript
webtorrent/webtorrent-desktop
src/main/windows/main.js
https://github.com/webtorrent/webtorrent-desktop/blob/master/src/main/windows/main.js
MIT