2017-03-22 11:47:44 +01:00
|
|
|
const {app, BrowserWindow, ipcMain} = require('electron');
|
2017-04-27 08:52:14 +02:00
|
|
|
const url = require('url');
|
2017-05-21 20:07:02 +02:00
|
|
|
const isDebug = process.env.NODE_ENV === 'development'
|
2017-04-07 07:15:22 +02:00
|
|
|
|
2017-05-21 20:07:02 +02:00
|
|
|
if (isDebug) {
|
2017-06-26 16:47:49 +02:00
|
|
|
try
|
|
|
|
{
|
|
|
|
require('electron-debug')({showDevTools: true});
|
|
|
|
}
|
|
|
|
catch (err) // electron-debug is in devDependencies, but some
|
|
|
|
{
|
|
|
|
console.error(err)
|
|
|
|
}
|
2017-05-21 20:07:02 +02:00
|
|
|
}
|
2017-04-07 07:15:22 +02:00
|
|
|
|
2017-02-23 19:46:25 +01:00
|
|
|
const path = require('path');
|
|
|
|
const jayson = require('jayson');
|
2017-04-27 08:52:14 +02:00
|
|
|
const semver = require('semver');
|
|
|
|
const https = require('https');
|
2017-06-26 16:47:49 +02:00
|
|
|
const keytar = require('keytar');
|
2017-02-10 20:11:26 +01:00
|
|
|
// tree-kill has better cross-platform handling of
|
|
|
|
// killing a process. child-process.kill was unreliable
|
2017-02-23 19:46:25 +01:00
|
|
|
const kill = require('tree-kill');
|
2017-03-22 11:47:44 +01:00
|
|
|
const child_process = require('child_process');
|
2017-03-24 00:07:08 +01:00
|
|
|
const assert = require('assert');
|
2017-04-27 08:52:14 +02:00
|
|
|
const {version: localVersion} = require(app.getAppPath() + '/package.json');
|
|
|
|
|
|
|
|
const VERSION_CHECK_INTERVAL = 30 * 60 * 1000;
|
|
|
|
const LATEST_RELEASE_API_URL = 'https://api.github.com/repos/lbryio/lbry-app/releases/latest';
|
2017-01-16 20:06:53 +01:00
|
|
|
|
|
|
|
|
2017-06-03 10:04:58 +02:00
|
|
|
let client = jayson.client.http({
|
|
|
|
host: 'localhost',
|
|
|
|
port: 5279,
|
|
|
|
path: '/lbryapi',
|
|
|
|
timeout: 1000
|
|
|
|
});
|
|
|
|
|
2017-01-16 20:06:53 +01:00
|
|
|
// Keep a global reference of the window object, if you don't, the window will
|
|
|
|
// be closed automatically when the JavaScript object is garbage collected.
|
2017-03-24 00:07:08 +01:00
|
|
|
let win;
|
2017-01-16 20:06:53 +01:00
|
|
|
// Also keep the daemon subprocess alive
|
2017-03-24 00:07:08 +01:00
|
|
|
let daemonSubprocess;
|
2017-01-16 20:06:53 +01:00
|
|
|
|
2017-03-24 08:04:30 +01:00
|
|
|
// This is set to true right before we try to shut the daemon subprocess --
|
|
|
|
// if it dies when we didn't ask it to shut down, we want to alert the user.
|
2017-04-13 23:30:53 +02:00
|
|
|
let daemonStopRequested = false;
|
2017-03-24 00:07:08 +01:00
|
|
|
|
|
|
|
// When a quit is attempted, we cancel the quit, do some preparations, then
|
|
|
|
// this is set to true and app.quit() is called again to quit for real.
|
|
|
|
let readyToQuit = false;
|
2017-01-16 20:06:53 +01:00
|
|
|
|
2017-05-08 11:04:11 +02:00
|
|
|
// If we receive a URI to open from an external app but there's no window to
|
|
|
|
// send it to, it's cached in this variable.
|
|
|
|
let openUri = null;
|
|
|
|
|
2017-06-28 09:25:02 +02:00
|
|
|
function processRequestedUri(uri) {
|
|
|
|
// Windows normalizes URIs when they're passed in from other apps. On Windows,
|
|
|
|
// this function tries to restore the original URI that was typed.
|
2017-05-11 05:40:07 +02:00
|
|
|
// - If the URI has no path, Windows adds a trailing slash. LBRY URIs
|
|
|
|
// can't have a slash with no path, so we just strip it off.
|
|
|
|
// - In a URI with a claim ID, like lbry://channel#claimid, Windows
|
|
|
|
// interprets the hash mark as an anchor and converts it to
|
|
|
|
// lbry://channel/#claimid. We remove the slash here as well.
|
2017-06-28 09:25:02 +02:00
|
|
|
// On Linux and Mac, we just return the URI as given.
|
2017-05-11 05:40:07 +02:00
|
|
|
|
|
|
|
if (process.platform == 'win32') {
|
|
|
|
return uri.replace(/\/$/, '').replace('/#', '#');
|
|
|
|
} else {
|
|
|
|
return uri;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-27 08:52:14 +02:00
|
|
|
function checkForNewVersion(callback) {
|
|
|
|
function formatRc(ver) {
|
|
|
|
// Adds dash if needed to make RC suffix semver friendly
|
|
|
|
return ver.replace(/([^-])rc/, '$1-rc');
|
|
|
|
}
|
|
|
|
|
|
|
|
let result = '';
|
|
|
|
const opts = {
|
|
|
|
headers: {
|
|
|
|
'User-Agent': `LBRY/${localVersion}`,
|
|
|
|
}
|
|
|
|
};
|
2017-05-25 20:29:28 +02:00
|
|
|
|
2017-04-27 08:52:14 +02:00
|
|
|
const req = https.get(Object.assign(opts, url.parse(LATEST_RELEASE_API_URL)), (res) => {
|
|
|
|
res.on('data', (data) => {
|
|
|
|
result += data;
|
|
|
|
});
|
|
|
|
res.on('end', () => {
|
|
|
|
const tagName = JSON.parse(result).tag_name;
|
|
|
|
const [_, remoteVersion] = tagName.match(/^v([\d.]+(?:-?rc\d+)?)$/);
|
|
|
|
if (!remoteVersion) {
|
2017-05-05 08:19:18 +02:00
|
|
|
if (win) {
|
|
|
|
win.webContents.send('version-info-received', null);
|
|
|
|
}
|
2017-04-27 08:52:14 +02:00
|
|
|
} else {
|
|
|
|
const upgradeAvailable = semver.gt(formatRc(remoteVersion), formatRc(localVersion));
|
2017-05-05 08:19:18 +02:00
|
|
|
if (win) {
|
2017-05-21 20:07:02 +02:00
|
|
|
win.webContents.send('version-info-received', {remoteVersion, localVersion, upgradeAvailable});
|
2017-05-05 08:19:18 +02:00
|
|
|
}
|
2017-04-27 08:52:14 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
|
|
|
req.on('error', (err) => {
|
|
|
|
console.log('Failed to get current version from GitHub. Error:', err);
|
2017-05-05 08:19:18 +02:00
|
|
|
if (win) {
|
2017-05-21 20:07:02 +02:00
|
|
|
win.webContents.send('version-info-received', null);
|
2017-05-05 08:19:18 +02:00
|
|
|
}
|
2017-04-27 08:52:14 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
ipcMain.on('version-info-requested', checkForNewVersion);
|
|
|
|
|
2017-03-23 19:08:14 +01:00
|
|
|
/*
|
|
|
|
* Replacement for Electron's shell.openItem. The Electron version doesn't
|
|
|
|
* reliably work from the main process, and we need to be able to run it
|
|
|
|
* when no windows are open.
|
|
|
|
*/
|
|
|
|
function openItem(fullPath) {
|
|
|
|
const subprocOptions = {
|
|
|
|
detached: true,
|
|
|
|
stdio: 'ignore',
|
|
|
|
};
|
|
|
|
|
|
|
|
let child;
|
|
|
|
if (process.platform == 'darwin') {
|
|
|
|
child = child_process.spawn('open', [fullPath], subprocOptions);
|
|
|
|
} else if (process.platform == 'linux') {
|
|
|
|
child = child_process.spawn('xdg-open', [fullPath], subprocOptions);
|
|
|
|
} else if (process.platform == 'win32') {
|
2017-06-01 10:21:25 +02:00
|
|
|
child = child_process.spawn(fullPath, Object.assign({}, subprocOptions, {shell: true}));
|
2017-03-23 19:08:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Causes child process reference to be garbage collected, allowing main process to exit
|
|
|
|
child.unref();
|
|
|
|
}
|
2017-02-20 19:59:03 +01:00
|
|
|
|
2017-03-24 08:06:54 +01:00
|
|
|
function getPidsForProcessName(name) {
|
2017-03-26 13:02:28 +02:00
|
|
|
if (process.platform == 'win32') {
|
|
|
|
const tasklistOut = child_process.execSync(`tasklist /fi "Imagename eq ${name}.exe" /nh`, {encoding: 'utf8'});
|
|
|
|
if (tasklistOut.startsWith('INFO')) {
|
|
|
|
return [];
|
|
|
|
} else {
|
|
|
|
return tasklistOut.match(/[^\r\n]+/g).map((line) => line.split(/\s+/)[1]); // Second column of every non-empty line
|
|
|
|
}
|
2017-03-24 08:06:54 +01:00
|
|
|
} else {
|
|
|
|
const pgrepOut = child_process.spawnSync('pgrep', ['-x', name], {encoding: 'utf8'}).stdout;
|
|
|
|
return pgrepOut.match(/\d+/g);
|
|
|
|
}
|
|
|
|
}
|
2017-02-20 19:59:03 +01:00
|
|
|
|
2017-01-16 20:06:53 +01:00
|
|
|
function createWindow () {
|
2017-04-15 00:23:42 +02:00
|
|
|
win = new BrowserWindow({backgroundColor: '#155B4A', minWidth: 800, minHeight: 600 }) //$color-primary
|
2017-05-08 11:22:38 +02:00
|
|
|
|
2017-01-16 20:06:53 +01:00
|
|
|
win.maximize()
|
2017-05-21 20:07:02 +02:00
|
|
|
if (isDebug) {
|
|
|
|
win.webContents.openDevTools();
|
|
|
|
}
|
2017-01-16 20:06:53 +01:00
|
|
|
win.loadURL(`file://${__dirname}/dist/index.html`)
|
2017-05-08 11:04:11 +02:00
|
|
|
if (openUri) { // We stored and received a URI that an external app requested before we had a window object
|
2017-05-08 11:22:38 +02:00
|
|
|
win.webContents.on('did-finish-load', () => {
|
2017-05-08 11:04:11 +02:00
|
|
|
win.webContents.send('open-uri-requested', openUri);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-01-16 20:06:53 +01:00
|
|
|
win.on('closed', () => {
|
|
|
|
win = null
|
|
|
|
})
|
2017-01-18 17:32:01 +01:00
|
|
|
};
|
|
|
|
|
2017-06-28 09:25:02 +02:00
|
|
|
function handleOpenUriRequested(uri) {
|
|
|
|
if (!win) {
|
|
|
|
// Window not created yet, so store up requested URI for when it is
|
2017-06-29 06:56:59 +02:00
|
|
|
openUri = processRequestedUri(uri);
|
2017-06-28 09:25:02 +02:00
|
|
|
} else {
|
|
|
|
if (win.isMinimized()) {
|
|
|
|
win.restore();
|
|
|
|
}
|
|
|
|
win.focus();
|
|
|
|
win.webContents.send('open-uri-requested', processRequestedUri(uri));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-24 00:07:08 +01:00
|
|
|
function handleDaemonSubprocessExited() {
|
|
|
|
console.log('The daemon has exited.');
|
|
|
|
daemonSubprocess = null;
|
2017-04-13 23:30:53 +02:00
|
|
|
if (!daemonStopRequested) {
|
|
|
|
// We didn't request to stop the daemon, so display a
|
2017-03-24 00:07:08 +01:00
|
|
|
// warning and schedule a quit.
|
|
|
|
//
|
|
|
|
// TODO: maybe it would be better to restart the daemon?
|
|
|
|
if (win) {
|
2017-03-24 08:04:30 +01:00
|
|
|
console.log('Did not request daemon stop, so quitting in 5 seconds.');
|
2017-03-24 00:07:08 +01:00
|
|
|
win.loadURL(`file://${__dirname}/dist/warning.html`);
|
2017-03-24 08:04:30 +01:00
|
|
|
setTimeout(quitNow, 5000);
|
|
|
|
} else {
|
|
|
|
console.log('Did not request daemon stop, so quitting.');
|
|
|
|
quitNow();
|
2017-03-24 00:07:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-23 20:01:23 +01:00
|
|
|
|
2017-03-17 10:06:02 +01:00
|
|
|
function launchDaemon() {
|
2017-03-24 00:07:08 +01:00
|
|
|
assert(!daemonSubprocess, 'Tried to launch daemon twice');
|
|
|
|
|
2017-02-23 21:15:09 +01:00
|
|
|
if (process.env.LBRY_DAEMON) {
|
|
|
|
executable = process.env.LBRY_DAEMON;
|
|
|
|
} else {
|
|
|
|
executable = path.join(__dirname, 'dist', 'lbrynet-daemon');
|
|
|
|
}
|
2017-03-24 08:04:30 +01:00
|
|
|
console.log('Launching daemon:', executable)
|
2017-03-24 00:07:08 +01:00
|
|
|
daemonSubprocess = child_process.spawn(executable)
|
2017-02-10 20:11:26 +01:00
|
|
|
// Need to handle the data event instead of attaching to
|
|
|
|
// process.stdout because the latter doesn't work. I believe on
|
|
|
|
// windows it buffers stdout and we don't get any meaningful output
|
2017-03-24 00:07:08 +01:00
|
|
|
daemonSubprocess.stdout.on('data', (buf) => {console.log(String(buf).trim());});
|
|
|
|
daemonSubprocess.stderr.on('data', (buf) => {console.log(String(buf).trim());});
|
|
|
|
daemonSubprocess.on('exit', handleDaemonSubprocessExited);
|
2017-01-16 20:06:53 +01:00
|
|
|
}
|
|
|
|
|
2017-03-24 00:07:08 +01:00
|
|
|
/*
|
2017-03-24 08:04:30 +01:00
|
|
|
* Quits without any preparation. When a quit is requested (either through the
|
|
|
|
* interface or through app.quit()), we abort the quit, try to shut down the daemon,
|
|
|
|
* and then call this to quit for real.
|
2017-03-24 00:07:08 +01:00
|
|
|
*/
|
|
|
|
function quitNow() {
|
|
|
|
readyToQuit = true;
|
|
|
|
app.quit();
|
|
|
|
}
|
|
|
|
|
2017-05-11 09:30:23 +02:00
|
|
|
if (process.platform != 'linux') {
|
|
|
|
// On Linux, this is always returning true due to an Electron bug,
|
|
|
|
// so for now we just don't support single-instance apps on Linux.
|
|
|
|
const isSecondaryInstance = app.makeSingleInstance((argv) => {
|
2017-06-28 09:25:02 +02:00
|
|
|
if (argv.length >= 2) {
|
|
|
|
handleOpenUriRequested(argv[1]); // This will handle restoring and focusing the window
|
|
|
|
} else if (win) {
|
2017-05-11 09:30:23 +02:00
|
|
|
if (win.isMinimized()) {
|
|
|
|
win.restore();
|
|
|
|
}
|
|
|
|
win.focus();
|
2017-05-11 06:03:39 +02:00
|
|
|
}
|
2017-05-11 09:30:23 +02:00
|
|
|
});
|
2017-05-10 10:44:06 +02:00
|
|
|
|
2017-05-11 09:30:23 +02:00
|
|
|
if (isSecondaryInstance) { // We're not in the original process, so quit
|
|
|
|
quitNow();
|
|
|
|
return;
|
|
|
|
}
|
2017-05-10 10:44:06 +02:00
|
|
|
}
|
2017-02-23 19:46:25 +01:00
|
|
|
|
2017-01-16 20:06:53 +01:00
|
|
|
app.on('ready', function(){
|
2017-02-23 20:01:23 +01:00
|
|
|
launchDaemonIfNotRunning();
|
|
|
|
createWindow();
|
2017-02-23 19:46:25 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
function launchDaemonIfNotRunning() {
|
2017-02-23 20:01:23 +01:00
|
|
|
// Check if the daemon is already running. If we get
|
|
|
|
// an error its because its not running
|
|
|
|
console.log('Checking for lbrynet daemon');
|
|
|
|
client.request(
|
|
|
|
'status', [],
|
|
|
|
function (err, res) {
|
|
|
|
if (err) {
|
|
|
|
console.log('lbrynet daemon needs to be launched')
|
2017-03-17 10:06:02 +01:00
|
|
|
launchDaemon();
|
2017-02-23 20:01:23 +01:00
|
|
|
} else {
|
|
|
|
console.log('lbrynet daemon is already running')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
2017-02-23 19:46:25 +01:00
|
|
|
}
|
2017-01-16 20:06:53 +01:00
|
|
|
|
2017-03-22 11:47:44 +01:00
|
|
|
/*
|
|
|
|
* Last resort for killing unresponsive daemon instances.
|
|
|
|
* Looks for any processes called "lbrynet-daemon" and
|
|
|
|
* tries to force kill them.
|
|
|
|
*/
|
2017-03-24 00:07:08 +01:00
|
|
|
function forceKillAllDaemonsAndQuit() {
|
2017-03-22 19:55:12 +01:00
|
|
|
console.log('Attempting to force kill any running lbrynet-daemon instances...');
|
2017-03-22 11:47:44 +01:00
|
|
|
|
2017-03-24 08:06:54 +01:00
|
|
|
const daemonPids = getPidsForProcessName('lbrynet-daemon');
|
2017-03-22 11:47:44 +01:00
|
|
|
if (!daemonPids) {
|
|
|
|
console.log('No lbrynet-daemon found running.');
|
2017-03-24 00:07:08 +01:00
|
|
|
quitNow();
|
2017-03-22 11:47:44 +01:00
|
|
|
} else {
|
|
|
|
console.log(`Found ${daemonPids.length} running daemon instances. Attempting to force kill...`);
|
|
|
|
|
|
|
|
for (const pid of daemonPids) {
|
2017-03-26 13:02:54 +02:00
|
|
|
let daemonKillAttemptsComplete = 0;
|
2017-03-22 11:47:44 +01:00
|
|
|
kill(pid, 'SIGKILL', (err) => {
|
2017-03-24 00:07:08 +01:00
|
|
|
daemonKillAttemptsComplete++;
|
2017-03-22 11:47:44 +01:00
|
|
|
if (err) {
|
2017-03-26 13:02:54 +02:00
|
|
|
console.log(`Failed to force kill daemon task with pid ${pid}. Error message: ${err.message}`);
|
|
|
|
} else {
|
|
|
|
console.log(`Force killed daemon task with pid ${pid}.`);
|
2017-03-22 11:47:44 +01:00
|
|
|
}
|
2017-03-26 13:02:54 +02:00
|
|
|
if (daemonKillAttemptsComplete >= daemonPids.length - 1) {
|
2017-03-24 00:07:08 +01:00
|
|
|
quitNow();
|
|
|
|
}
|
2017-03-22 11:47:44 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-16 20:06:53 +01:00
|
|
|
|
|
|
|
// Quit when all windows are closed.
|
|
|
|
app.on('window-all-closed', () => {
|
|
|
|
// On macOS it is common for applications and their menu bar
|
|
|
|
// to stay active until the user quits explicitly with Cmd + Q
|
|
|
|
if (process.platform !== 'darwin') {
|
|
|
|
app.quit()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2017-02-23 19:46:25 +01:00
|
|
|
|
2017-01-18 17:32:01 +01:00
|
|
|
app.on('before-quit', (event) => {
|
2017-03-24 00:07:08 +01:00
|
|
|
if (!readyToQuit) {
|
2017-03-24 08:04:30 +01:00
|
|
|
// We need to shutdown the daemon before we're ready to actually quit. This
|
2017-03-24 00:07:08 +01:00
|
|
|
// event will be triggered re-entrantly once preparation is done.
|
|
|
|
event.preventDefault();
|
|
|
|
shutdownDaemonAndQuit();
|
|
|
|
} else {
|
|
|
|
console.log('Quitting.')
|
2017-01-18 17:32:01 +01:00
|
|
|
}
|
2017-03-24 00:07:08 +01:00
|
|
|
});
|
2017-01-18 17:32:01 +01:00
|
|
|
|
2017-02-20 19:59:03 +01:00
|
|
|
|
2017-01-16 20:06:53 +01:00
|
|
|
app.on('activate', () => {
|
|
|
|
// On macOS it's common to re-create a window in the app when the
|
|
|
|
// dock icon is clicked and there are no other windows open.
|
|
|
|
if (win === null) {
|
|
|
|
createWindow()
|
|
|
|
}
|
2017-03-24 00:07:08 +01:00
|
|
|
});
|
2017-02-20 19:59:03 +01:00
|
|
|
|
2017-03-24 08:04:30 +01:00
|
|
|
// When a quit is attempted, this is called. It attempts to shutdown the daemon,
|
|
|
|
// then calls quitNow() to quit for real.
|
|
|
|
function shutdownDaemonAndQuit(evenIfNotStartedByApp = false) {
|
2017-04-13 23:30:53 +02:00
|
|
|
function doShutdown() {
|
2017-05-11 19:46:41 +02:00
|
|
|
console.log('Shutting down daemon');
|
2017-04-13 23:30:53 +02:00
|
|
|
daemonStopRequested = true;
|
2017-03-22 11:47:44 +01:00
|
|
|
client.request('daemon_stop', [], (err, res) => {
|
|
|
|
if (err) {
|
2017-04-13 23:30:53 +02:00
|
|
|
console.log(`received error when stopping lbrynet-daemon. Error message: ${err.message}\n`);
|
|
|
|
console.log('You will need to manually kill the daemon.');
|
2017-03-24 00:07:08 +01:00
|
|
|
} else {
|
|
|
|
console.log('Successfully stopped daemon via RPC call.')
|
|
|
|
quitNow();
|
2017-03-22 11:47:44 +01:00
|
|
|
}
|
|
|
|
});
|
2017-04-13 23:30:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (daemonSubprocess) {
|
|
|
|
doShutdown();
|
|
|
|
} else if (!evenIfNotStartedByApp) {
|
2017-03-24 00:07:08 +01:00
|
|
|
console.log('Not killing lbrynet-daemon because app did not start it');
|
|
|
|
quitNow();
|
2017-04-13 23:30:53 +02:00
|
|
|
} else {
|
|
|
|
doShutdown();
|
2017-03-17 10:06:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Is it safe to start the installer before the daemon finishes running?
|
|
|
|
// If not, we should wait until the daemon is closed before we start the install.
|
|
|
|
}
|
|
|
|
|
|
|
|
function upgrade(event, installerPath) {
|
|
|
|
app.on('quit', () => {
|
2017-03-24 00:07:08 +01:00
|
|
|
console.log('Launching upgrade installer at', installerPath);
|
|
|
|
// This gets triggered called after *all* other quit-related events, so
|
|
|
|
// we'll only get here if we're fully prepared and quitting for real.
|
2017-03-23 19:08:14 +01:00
|
|
|
openItem(installerPath);
|
2017-02-20 19:59:03 +01:00
|
|
|
});
|
2017-03-23 19:08:14 +01:00
|
|
|
|
2017-03-17 10:06:02 +01:00
|
|
|
if (win) {
|
|
|
|
win.loadURL(`file://${__dirname}/dist/upgrade.html`);
|
|
|
|
}
|
2017-03-24 00:07:08 +01:00
|
|
|
|
2017-03-26 13:02:54 +02:00
|
|
|
shutdownDaemonAndQuit(true);
|
2017-03-17 23:05:25 +01:00
|
|
|
// wait for daemon to shut down before upgrading
|
|
|
|
// what to do if no shutdown in a long time?
|
2017-03-24 00:07:08 +01:00
|
|
|
console.log('Update downloaded to', installerPath);
|
2017-03-17 23:05:25 +01:00
|
|
|
console.log('The app will close, and you will be prompted to install the latest version of LBRY.');
|
|
|
|
console.log('After the install is complete, please reopen the app.');
|
2017-02-20 19:59:03 +01:00
|
|
|
}
|
|
|
|
|
2017-03-17 10:06:02 +01:00
|
|
|
ipcMain.on('upgrade', upgrade);
|
2017-05-05 11:15:58 +02:00
|
|
|
|
2017-05-10 10:05:55 +02:00
|
|
|
app.setAsDefaultProtocolClient('lbry');
|
2017-05-10 10:44:06 +02:00
|
|
|
|
2017-05-05 11:15:58 +02:00
|
|
|
if (process.platform == 'darwin') {
|
|
|
|
app.on('open-url', (event, uri) => {
|
2017-06-28 09:25:02 +02:00
|
|
|
handleOpenUriRequested(uri);
|
2017-05-05 11:15:58 +02:00
|
|
|
});
|
2017-05-11 03:27:57 +02:00
|
|
|
} else if (process.argv.length >= 2) {
|
2017-06-28 09:25:02 +02:00
|
|
|
handleOpenUriRequested(process.argv[1]);
|
2017-05-05 11:15:58 +02:00
|
|
|
}
|
2017-06-26 16:47:49 +02:00
|
|
|
|
|
|
|
ipcMain.on('get-auth-token', (event) => {
|
|
|
|
keytar.getPassword("LBRY", "auth_token").then(token => {
|
|
|
|
event.sender.send('auth-token-response', token ? token.toString().trim() : null)
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
ipcMain.on('set-auth-token', (event, token) => {
|
|
|
|
keytar.setPassword("LBRY", "auth_token", token ? token.toString().trim() : null);
|
|
|
|
});
|