Unzip daemon on /static/ dir /build.sh
This commit is contained in:
parent
37375dfaba
commit
9f9746cf5e
3 changed files with 88 additions and 121 deletions
|
@ -11,23 +11,14 @@ if (Test-Path -Path dist\) {
|
||||||
}
|
}
|
||||||
New-Item -ItemType directory -Path dist\
|
New-Item -ItemType directory -Path dist\
|
||||||
|
|
||||||
|
|
||||||
# build ui
|
|
||||||
npm rebuild node-sass
|
|
||||||
node src\renderer\extractLocals.js
|
|
||||||
node_modules\.bin\node-sass --output dist\css --sourcemap=none src\renderer\scss\
|
|
||||||
node_modules\.bin\webpack --config src\renderer\webpack.prod.js
|
|
||||||
Copy-Item src\renderer\dist dist -recurse
|
|
||||||
|
|
||||||
|
|
||||||
# get daemon and cli executable
|
# get daemon and cli executable
|
||||||
$package_settings = (Get-Content package.json -Raw | ConvertFrom-Json).lbrySettings
|
$package_settings = (Get-Content package.json -Raw | ConvertFrom-Json).lbrySettings
|
||||||
$daemon_ver = $package_settings.lbrynetDaemonVersion
|
$daemon_ver = $package_settings.lbrynetDaemonVersion
|
||||||
$daemon_url_template = $package_settings.lbrynetDaemonUrlTemplate
|
$daemon_url_template = $package_settings.lbrynetDaemonUrlTemplate
|
||||||
$daemon_url = $daemon_url_template.Replace('OSNAME', 'windows').Replace('DAEMONVER', $daemon_ver)
|
$daemon_url = $daemon_url_template.Replace('OSNAME', 'windows').Replace('DAEMONVER', $daemon_ver)
|
||||||
Invoke-WebRequest -Uri $daemon_url -OutFile daemon.zip
|
Invoke-WebRequest -Uri $daemon_url -OutFile daemon.zip
|
||||||
Expand-Archive daemon.zip -DestinationPath dist\
|
Expand-Archive daemon.zip -DestinationPath static\daemon\
|
||||||
dir dist\ # verify that daemon binary is there
|
dir static\daemon\ # verify that daemon binary is there
|
||||||
rm daemon.zip
|
rm daemon.zip
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -40,26 +40,10 @@ else
|
||||||
fi
|
fi
|
||||||
|
|
||||||
[ -d "$ROOT/dist" ] && rm -rf "$ROOT/dist"
|
[ -d "$ROOT/dist" ] && rm -rf "$ROOT/dist"
|
||||||
mkdir -p "$ROOT/dist"
|
|
||||||
|
|
||||||
yarn install
|
yarn install
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
############
|
|
||||||
# UI #
|
|
||||||
############
|
|
||||||
echo -e "\033[0;32mCompiling UI\x1b[m"
|
|
||||||
(
|
|
||||||
npm rebuild node-sass
|
|
||||||
node src/renderer/extractLocals.js
|
|
||||||
node_modules/.bin/node-sass --output dist/css --sourcemap=none src/renderer/scss/
|
|
||||||
node_modules/.bin/webpack --config src/renderer/webpack.prod.js
|
|
||||||
cp -r src/renderer/dist/* "$ROOT/dist/"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
####################
|
####################
|
||||||
# daemon and cli #
|
# daemon and cli #
|
||||||
####################
|
####################
|
||||||
|
@ -74,9 +58,9 @@ DAEMON_URL_TEMPLATE=$(node -e "console.log(require(\"$ROOT/package.json\").lbryS
|
||||||
DAEMON_URL=$(echo ${DAEMON_URL_TEMPLATE//DAEMONVER/$DAEMON_VER} | sed "s/OSNAME/$OSNAME/g")
|
DAEMON_URL=$(echo ${DAEMON_URL_TEMPLATE//DAEMONVER/$DAEMON_VER} | sed "s/OSNAME/$OSNAME/g")
|
||||||
DAEMON_VER_PATH="$BUILD_DIR/daemon.ver"
|
DAEMON_VER_PATH="$BUILD_DIR/daemon.ver"
|
||||||
echo "$DAEMON_VER_PATH"
|
echo "$DAEMON_VER_PATH"
|
||||||
if [[ ! -f $DAEMON_VER_PATH || ! -f $ROOT/dist/lbrynet-daemon || "$(< "$DAEMON_VER_PATH")" != "$DAEMON_VER" ]]; then
|
if [[ ! -f $DAEMON_VER_PATH || ! -f $ROOT/static/daemon/lbrynet-daemon || "$(< "$DAEMON_VER_PATH")" != "$DAEMON_VER" ]]; then
|
||||||
curl -sL -o "$BUILD_DIR/daemon.zip" "$DAEMON_URL"
|
curl -sL -o "$BUILD_DIR/daemon.zip" "$DAEMON_URL"
|
||||||
unzip "$BUILD_DIR/daemon.zip" -d "$ROOT/dist/"
|
unzip "$BUILD_DIR/daemon.zip" -d "$ROOT/static/daemon/"
|
||||||
rm "$BUILD_DIR/daemon.zip"
|
rm "$BUILD_DIR/daemon.zip"
|
||||||
echo "$DAEMON_VER" > "$DAEMON_VER_PATH"
|
echo "$DAEMON_VER" > "$DAEMON_VER_PATH"
|
||||||
else
|
else
|
||||||
|
|
174
src/main/main.js
174
src/main/main.js
|
@ -12,7 +12,7 @@ const keytar = require('keytar');
|
||||||
const kill = require('tree-kill');
|
const kill = require('tree-kill');
|
||||||
const child_process = require('child_process');
|
const child_process = require('child_process');
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
const {version: localVersion} = require(app.getAppPath() + '/package.json');
|
const localVersion = app.getVersion();
|
||||||
const setMenu = require('./menu/main-menu.js');
|
const setMenu = require('./menu/main-menu.js');
|
||||||
|
|
||||||
// Debug configs
|
// Debug configs
|
||||||
|
@ -39,7 +39,7 @@ if (isDebug) {
|
||||||
|
|
||||||
// Misc constants
|
// Misc constants
|
||||||
const LATEST_RELEASE_API_URL = 'https://api.github.com/repos/lbryio/lbry-app/releases/latest';
|
const LATEST_RELEASE_API_URL = 'https://api.github.com/repos/lbryio/lbry-app/releases/latest';
|
||||||
const DAEMON_PATH = process.env.LBRY_DAEMON || path.join(app.getAppPath(), 'dist', 'lbrynet-daemon');
|
const DAEMON_PATH = process.env.LBRY_DAEMON || path.join(__static, 'daemon/lbrynet-daemon');
|
||||||
|
|
||||||
let client = jayson.client.http({
|
let client = jayson.client.http({
|
||||||
host: 'localhost',
|
host: 'localhost',
|
||||||
|
@ -83,56 +83,13 @@ function processRequestedUri(uri) {
|
||||||
// lbry://channel/#claimid. We remove the slash here as well.
|
// lbry://channel/#claimid. We remove the slash here as well.
|
||||||
// On Linux and Mac, we just return the URI as given.
|
// On Linux and Mac, we just return the URI as given.
|
||||||
|
|
||||||
if (process.platform == 'win32') {
|
if (process.platform === 'win32') {
|
||||||
return uri.replace(/\/$/, '').replace('/#', '#');
|
return uri.replace(/\/$/, '').replace('/#', '#');
|
||||||
} else {
|
} else {
|
||||||
return uri;
|
return uri;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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}`,
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
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) {
|
|
||||||
if (win) {
|
|
||||||
win.webContents.send('version-info-received', null);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
const upgradeAvailable = semver.gt(formatRc(remoteVersion), formatRc(localVersion));
|
|
||||||
if (win) {
|
|
||||||
win.webContents.send('version-info-received', {remoteVersion, localVersion, upgradeAvailable});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
});
|
|
||||||
|
|
||||||
req.on('error', (err) => {
|
|
||||||
console.log('Failed to get current version from GitHub. Error:', err);
|
|
||||||
if (win) {
|
|
||||||
win.webContents.send('version-info-received', null);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
ipcMain.on('version-info-requested', checkForNewVersion);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Replacement for Electron's shell.openItem. The Electron version doesn't
|
* 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
|
* reliably work from the main process, and we need to be able to run it
|
||||||
|
@ -145,11 +102,11 @@ function openItem(fullPath) {
|
||||||
};
|
};
|
||||||
|
|
||||||
let child;
|
let child;
|
||||||
if (process.platform == 'darwin') {
|
if (process.platform === 'darwin') {
|
||||||
child = child_process.spawn('open', [fullPath], subprocOptions);
|
child = child_process.spawn('open', [fullPath], subprocOptions);
|
||||||
} else if (process.platform == 'linux') {
|
} else if (process.platform === 'linux') {
|
||||||
child = child_process.spawn('xdg-open', [fullPath], subprocOptions);
|
child = child_process.spawn('xdg-open', [fullPath], subprocOptions);
|
||||||
} else if (process.platform == 'win32') {
|
} else if (process.platform === 'win32') {
|
||||||
child = child_process.spawn(fullPath, Object.assign({}, subprocOptions, {shell: true}));
|
child = child_process.spawn(fullPath, Object.assign({}, subprocOptions, {shell: true}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -158,7 +115,7 @@ function openItem(fullPath) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function getPidsForProcessName(name) {
|
function getPidsForProcessName(name) {
|
||||||
if (process.platform == 'win32') {
|
if (process.platform === 'win32') {
|
||||||
const tasklistOut = child_process.execSync(`tasklist /fi "Imagename eq ${name}.exe" /nh`, {encoding: 'utf8'});
|
const tasklistOut = child_process.execSync(`tasklist /fi "Imagename eq ${name}.exe" /nh`, {encoding: 'utf8'});
|
||||||
if (tasklistOut.startsWith('INFO')) {
|
if (tasklistOut.startsWith('INFO')) {
|
||||||
return [];
|
return [];
|
||||||
|
@ -324,7 +281,6 @@ function handleDaemonSubprocessExited() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function launchDaemon() {
|
function launchDaemon() {
|
||||||
assert(!daemonSubprocess, 'Tried to launch daemon twice');
|
assert(!daemonSubprocess, 'Tried to launch daemon twice');
|
||||||
|
|
||||||
|
@ -338,7 +294,6 @@ function launchDaemon() {
|
||||||
daemonSubprocess.on('exit', handleDaemonSubprocessExited);
|
daemonSubprocess.on('exit', handleDaemonSubprocessExited);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Quits by first killing the daemon, the calling quitting for real.
|
* Quits by first killing the daemon, the calling quitting for real.
|
||||||
*/
|
*/
|
||||||
|
@ -375,19 +330,6 @@ if (isSecondaryInstance) { // We're not in the original process, so quit
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
app.on('ready', function() {
|
|
||||||
launchDaemonIfNotRunning();
|
|
||||||
if (process.platform === "linux") {
|
|
||||||
checkLinuxTraySupport( err => {
|
|
||||||
if (!err) createTray();
|
|
||||||
else minimize = false;
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
createTray();
|
|
||||||
}
|
|
||||||
createWindow();
|
|
||||||
});
|
|
||||||
|
|
||||||
function launchDaemonIfNotRunning() {
|
function launchDaemonIfNotRunning() {
|
||||||
// Check if the daemon is already running. If we get
|
// Check if the daemon is already running. If we get
|
||||||
// an error its because its not running
|
// an error its because its not running
|
||||||
|
@ -437,6 +379,20 @@ function forceKillAllDaemonsAndQuit() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
app.setAsDefaultProtocolClient('lbry');
|
||||||
|
|
||||||
|
app.on('ready', function() {
|
||||||
|
launchDaemonIfNotRunning();
|
||||||
|
if (process.platform === "linux") {
|
||||||
|
checkLinuxTraySupport( err => {
|
||||||
|
if (!err) createTray();
|
||||||
|
else minimize = false;
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
createTray();
|
||||||
|
}
|
||||||
|
createWindow();
|
||||||
|
});
|
||||||
|
|
||||||
// Quit when all windows are closed.
|
// Quit when all windows are closed.
|
||||||
app.on('window-all-closed', () => {
|
app.on('window-all-closed', () => {
|
||||||
|
@ -459,7 +415,6 @@ app.on('before-quit', (event) => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
app.on('activate', () => {
|
app.on('activate', () => {
|
||||||
// On macOS it's common to re-create a window in the app when the
|
// 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.
|
// dock icon is clicked and there are no other windows open.
|
||||||
|
@ -468,6 +423,14 @@ app.on('activate', () => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (process.platform === 'darwin') {
|
||||||
|
app.on('open-url', (event, uri) => {
|
||||||
|
handleOpenUriRequested(uri);
|
||||||
|
});
|
||||||
|
} else if (process.argv.length >= 2) {
|
||||||
|
handleOpenUriRequested(process.argv[1]);
|
||||||
|
}
|
||||||
|
|
||||||
// When a quit is attempted, this is called. It attempts to shutdown the daemon,
|
// When a quit is attempted, this is called. It attempts to shutdown the daemon,
|
||||||
// then calls quitNow() to quit for real.
|
// then calls quitNow() to quit for real.
|
||||||
function shutdownDaemonAndQuit(evenIfNotStartedByApp = false) {
|
function shutdownDaemonAndQuit(evenIfNotStartedByApp = false) {
|
||||||
|
@ -498,7 +461,23 @@ function shutdownDaemonAndQuit(evenIfNotStartedByApp = false) {
|
||||||
// If not, we should wait until the daemon is closed before we start the install.
|
// If not, we should wait until the daemon is closed before we start the install.
|
||||||
}
|
}
|
||||||
|
|
||||||
function upgrade(event, installerPath) {
|
// Taken from webtorrent-desktop
|
||||||
|
function checkLinuxTraySupport (cb) {
|
||||||
|
// Check that we're on Ubuntu (or another debian system) and that we have
|
||||||
|
// libappindicator1.
|
||||||
|
child_process.exec('dpkg --get-selections libappindicator1', function (err, stdout) {
|
||||||
|
if (err) return cb(err)
|
||||||
|
// Unfortunately there's no cleaner way, as far as I can tell, to check
|
||||||
|
// whether a debian package is installed:
|
||||||
|
if (stdout.endsWith('\tinstall\n')) {
|
||||||
|
cb(null)
|
||||||
|
} else {
|
||||||
|
cb(new Error('debian package not installed'))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
ipcMain.on('upgrade', (event, installerPath) => {
|
||||||
app.on('quit', () => {
|
app.on('quit', () => {
|
||||||
console.log('Launching upgrade installer at', installerPath);
|
console.log('Launching upgrade installer at', installerPath);
|
||||||
// This gets triggered called after *all* other quit-related events, so
|
// This gets triggered called after *all* other quit-related events, so
|
||||||
|
@ -516,35 +495,48 @@ function upgrade(event, installerPath) {
|
||||||
console.log('Update downloaded to', installerPath);
|
console.log('Update downloaded to', installerPath);
|
||||||
console.log('The app will close, and you will be prompted to install the latest version of LBRY.');
|
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.');
|
console.log('After the install is complete, please reopen the app.');
|
||||||
}
|
});
|
||||||
|
|
||||||
// Taken from webtorrent-desktop
|
ipcMain.on('version-info-requested', () => {
|
||||||
function checkLinuxTraySupport (cb) {
|
function formatRc(ver) {
|
||||||
// Check that we're on Ubuntu (or another debian system) and that we have
|
// Adds dash if needed to make RC suffix semver friendly
|
||||||
// libappindicator1.
|
return ver.replace(/([^-])rc/, '$1-rc');
|
||||||
child_process.exec('dpkg --get-selections libappindicator1', function (err, stdout) {
|
}
|
||||||
if (err) return cb(err)
|
|
||||||
// Unfortunately there's no cleaner way, as far as I can tell, to check
|
let result = '';
|
||||||
// whether a debian package is installed:
|
const opts = {
|
||||||
if (stdout.endsWith('\tinstall\n')) {
|
headers: {
|
||||||
cb(null)
|
'User-Agent': `LBRY/${localVersion}`,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
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) {
|
||||||
|
if (win) {
|
||||||
|
win.webContents.send('version-info-received', null);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
cb(new Error('debian package not installed'))
|
const upgradeAvailable = semver.gt(formatRc(remoteVersion), formatRc(localVersion));
|
||||||
|
if (win) {
|
||||||
|
win.webContents.send('version-info-received', {remoteVersion, localVersion, upgradeAvailable});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
|
||||||
|
|
||||||
ipcMain.on('upgrade', upgrade);
|
|
||||||
|
|
||||||
app.setAsDefaultProtocolClient('lbry');
|
|
||||||
|
|
||||||
if (process.platform == 'darwin') {
|
|
||||||
app.on('open-url', (event, uri) => {
|
|
||||||
handleOpenUriRequested(uri);
|
|
||||||
});
|
});
|
||||||
} else if (process.argv.length >= 2) {
|
|
||||||
handleOpenUriRequested(process.argv[1]);
|
req.on('error', (err) => {
|
||||||
}
|
console.log('Failed to get current version from GitHub. Error:', err);
|
||||||
|
if (win) {
|
||||||
|
win.webContents.send('version-info-received', null);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
ipcMain.on('get-auth-token', (event) => {
|
ipcMain.on('get-auth-token', (event) => {
|
||||||
keytar.getPassword("LBRY", "auth_token").then(token => {
|
keytar.getPassword("LBRY", "auth_token").then(token => {
|
||||||
|
|
Loading…
Reference in a new issue