Skip to content

Commit

Permalink
Updated webpack and package.json production build config (#122)
Browse files Browse the repository at this point in the history
* Updated webpack and package.json production build config

* Added publish Dockerfiles

* Configured auto-updating

* Updated repository url

* Fixed this context in general_restartInstallUpdate
  • Loading branch information
rBurgett authored Feb 2, 2021
1 parent 1d94bff commit 7658a87
Show file tree
Hide file tree
Showing 10 changed files with 166 additions and 13 deletions.
20 changes: 20 additions & 0 deletions Dockerfile-publish-linux
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM electronuserland/builder:latest

ARG GIT_BRANCH=""

# Pull app source from git
RUN mkdir -p /opt \
&& cd /opt \
&& git clone --depth 1 --branch $GIT_BRANCH https://github.com/blocknetdx/xlite.git \
&& cd /opt/xlite \
&& mkdir -p dist-native

# Install app dependencies
RUN cd /opt/xlite \
&& npm install --no-audit

WORKDIR /opt/xlite/
VOLUME /opt/xlite/dist-native

ENTRYPOINT ["npm"]
CMD ["run", "publish-native-linux"]
20 changes: 20 additions & 0 deletions Dockerfile-publish-win
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM electronuserland/builder:wine

ARG GIT_BRANCH=""

# Pull app source from git
RUN mkdir -p /opt \
&& cd /opt \
&& git clone --depth 1 --branch $GIT_BRANCH https://github.com/blocknetdx/xlite.git \
&& cd /opt/xlite \
&& mkdir -p dist-native

# Install app dependencies
RUN cd /opt/xlite \
&& npm install --no-audit

WORKDIR /opt/xlite/
VOLUME /opt/xlite/dist-native

ENTRYPOINT ["npm"]
CMD ["run", "publish-native-win"]
35 changes: 25 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
"build-native-mac": "npm run build && node ./native-build-scripts/01-copy-files.js mac && cd temp && npm install --no-audit --production && cd .. && electron-builder --dir --x64 --mac dir --publish never",
"build-native-linux": "npm run build && node ./native-build-scripts/01-copy-files.js linux && cd temp && npm install --no-audit --production && cd .. && electron-builder --dir --x64 --linux appImage deb tar.gz --publish never",
"build-native-linux2": "npm run build && node ./native-build-scripts/01-copy-files.js linux && cd temp && npm install --no-audit --production && cd .. && electron-builder --dir --x64 --linux appImage --publish never",
"publish-native-win": "cross-env NODE_ENV=production npm run build && node ./native-build-scripts/01-copy-files.js win && cd temp && npm install --no-audit --production && cd .. && electron-builder --win --publish always",
"publish-native-mac": "cross-env NODE_ENV=production npm run build && node ./native-build-scripts/01-copy-files.js mac && cd temp && npm install --no-audit --production && cd .. && electron-builder --publish always",
"publish-native-linux": "cross-env NODE_ENV=production npm run build && node ./native-build-scripts/01-copy-files.js linux && cd temp && npm install --no-audit --production && cd .. && electron-builder --publish always",
"publish-native-win": "cross-env NODE_ENV=production npm run download-binaries-win && npm run build && node ./native-build-scripts/01-copy-files.js win && cd temp && npm install --no-audit --production && cd .. && electron-builder --win --publish always",
"publish-native-mac": "cross-env NODE_ENV=production npm run download-binaries-mac && npm run build && node ./native-build-scripts/01-copy-files.js mac && cd temp && npm install --no-audit --production && cd .. && electron-builder --publish always",
"publish-native-linux": "cross-env NODE_ENV=production npm run download-binaries-linux && npm run build && node ./native-build-scripts/01-copy-files.js linux && cd temp && npm install --no-audit --production && cd .. && electron-builder --publish always",
"pack-native": "cross-env NODE_ENV=production npm run build && node ./native-build-scripts/01-copy-files.js && cd temp && npm install --production && cd .. && electron-builder",
"publish-native": "cross-env NODE_ENV=production npm run build && node ./native-build-scripts/01-copy-files.js && cd temp && npm install --production && cd .. && electron-builder --publish always",
"download-binaries": "npm run download-binaries-win && npm run download-binaries-linux && npm run download-binaries-mac",
Expand All @@ -43,7 +43,7 @@
},
"repository": {
"type": "git",
"url": "git+https://github.com/blocknetdx/litewallet.git"
"url": "git+https://github.com/blocknetdx/xlite.git"
},
"author": "Blocknet <[email protected]>",
"contributors": [
Expand All @@ -54,9 +54,9 @@
],
"license": "MIT",
"bugs": {
"url": "https://github.com/blocknetdx/litewallet/issues"
"url": "https://github.com/blocknetdx/xlite/issues"
},
"homepage": "https://github.com/blocknetdx/litewallet#readme",
"homepage": "https://github.com/blocknetdx/xlite#readme",
"devDependencies": {
"@babel/plugin-proposal-class-properties": "^7.10.4",
"@babel/plugin-transform-modules-amd": "^7.10.5",
Expand All @@ -82,7 +82,7 @@
"rmrf-promise": "^1.1.0",
"should": "^13.2.3",
"webpack": "^4.44.1",
"webpack-cli": "^3.3.12",
"webpack-cli": "^4.4.0",
"xvfb-maybe": "^0.2.1"
},
"dependencies": {
Expand Down Expand Up @@ -168,9 +168,24 @@
},
"linux": {
"target": [
"appImage",
"tar.gz",
"deb"
{
"target": "appImage",
"arch": [
"x64"
]
},
{
"target": "deb",
"arch": [
"x64"
]
},
{
"target": "tar.gz",
"arch": [
"x64"
]
}
],
"icon": "./src/static/images/linux/",
"synopsis": "Copyright © 2020-2021 Blocknet",
Expand Down
20 changes: 20 additions & 0 deletions src/app/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ export const apiConstants = {
general_onZoomReset: 'general_onZoomReset',
general_getPlatform: 'general_getPlatform',
general_onShutdown: 'general_onShutdown',
general_onUpdateAvailable: 'general_onUpdateAvailable',
general_onUpdateDownloaded: 'general_onUpdateDownloaded',
general_downloadAvailableUpdate: 'general_downloadAvailableUpdate',
general_restartInstallUpdate: 'general_restartInstallUpdate',

contextMenu_showCopyMenu: 'contextMenu_showCopyMenu',
contextMenu_showPasteMenu: 'contextMenu_showPasteMenu',
Expand Down Expand Up @@ -181,6 +185,22 @@ const general_API = {
callback();
});
},
[apiConstants.general_onUpdateAvailable]: callback => {
ipcRenderer.on(apiConstants.general_onUpdateAvailable, (evt, version) => {
callback(version);
});
},
[apiConstants.general_onUpdateDownloaded]: callback => {
ipcRenderer.on(apiConstants.general_onUpdateDownloaded, (evt, version) => {
callback(version);
});
},
[apiConstants.general_downloadAvailableUpdate]: () => {
ipcRenderer.send(apiConstants.general_downloadAvailableUpdate);
},
[apiConstants.general_restartInstallUpdate]: () => {
ipcRenderer.send(apiConstants.general_restartInstallUpdate);
},
};

// Context menu api
Expand Down
21 changes: 21 additions & 0 deletions src/app/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,27 @@ api.general_onShutdown(() => {
});
});

api.general_onUpdateAvailable(async function(version) {
const { isConfirmed } = await Alert.confirm(
Localize.text('New update available!', 'universal'),
Localize.text('Xlite v{{version}} is available. Would you like to download the update now?', 'universal', {version})
);
if(isConfirmed) {
api.general_downloadAvailableUpdate();
}
});
api.general_onUpdateDownloaded(async function(version) {
const { isConfirmed } = await Alert.confirm(
Localize.text('Update ready to install', 'universal'),
Localize.text('Xlite v{{version}} has been downloaded and will install on next restart. Would you like to restart now?', 'universal', {version}),
Localize.text('Yes, restart now', 'universal'),
Localize.text('No', 'universal')
);
if(isConfirmed) {
api.general_restartInstallUpdate();
}
});

// Add window event handlers
window.addEventListener('paste', async function(e) {
const type = $(e.target).attr('type');
Expand Down
32 changes: 32 additions & 0 deletions src/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import ZoomController from './modules/zoom-controller';
import ConfController from './modules/conf-controller';
import TokenManifest from '../app/modules/token-manifest';
import WalletController from './modules/wallet-controller';
const { autoUpdater } = require('electron-updater');

import {app, ipcMain, Menu} from 'electron';
import contextMenu from 'electron-context-menu';
Expand Down Expand Up @@ -241,6 +242,7 @@ app.on('ready', async () => {
pricing,
shutdownMgr,
contextMenuController,
autoUpdater,
);

// Notify of fatal error
Expand Down Expand Up @@ -287,3 +289,33 @@ app.on('ready', async () => {
});
}
});

// Auto-updater setup

autoUpdater.autoDownload = false;
autoUpdater.autoInstallOnAppQuit = true;

autoUpdater.on('update-downloaded', ({ version }) => {
logger.info(`Version ${version} update downloaded.`);
appWindow.getWindow().send(apiConstants.general_onUpdateDownloaded, version);
});
autoUpdater.on('update-available', ({ version }) => {
logger.info(`Version ${version} update available.`);
appWindow.getWindow().send(apiConstants.general_onUpdateAvailable, version);
});
autoUpdater.on('error', err => {
logger.error(err.message + '\n' + err.stack);
});
const checkForUpdates = async function() {
if(!isDev) {
try {
logger.info('Check for updates');
await autoUpdater.checkForUpdates();
} catch(err) {
logger.error(err.message + '\n' + err.stack);
}
}
};
setTimeout(() => {
checkForUpdates();
}, 10000);
20 changes: 19 additions & 1 deletion src/server/modules/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ class Api {
*/
_contextMenu = null;

/**
* @type {AppUpdater}
* @private
*/
_autoUpdater = null;

/**
* If true this will allow electron to open external links.
* @type {boolean}
Expand All @@ -110,7 +116,7 @@ class Api {
constructor(storage, app, proc, err,
cloudChains = null, confController = null,
walletController = null, zoomController = null,
pricing = null, shutdown = null, contextMenu) {
pricing = null, shutdown = null, contextMenu, autoUpdater) {
this._storage = storage;
this._app = app;
this._proc = proc;
Expand All @@ -122,6 +128,7 @@ class Api {
this._pricing = pricing;
this._shutdown = shutdown;
this._contextMenu = contextMenu;
this._autoUpdater = autoUpdater;
this._init();
}

Expand Down Expand Up @@ -246,6 +253,17 @@ class Api {
evt.returnValue = process.platform;
});
} // end zoomController

// Audo-updating
this._proc.on(apiConstants.general_downloadAvailableUpdate, () => {
logger.info('User confirmed download available update');
this._autoUpdater.downloadUpdate();
});
this._proc.on(apiConstants.general_restartInstallUpdate, async () => {
logger.info('User confirmed install downloaded update');
await this._shutdown.shutdown();
this._autoUpdater.quitAndInstall();
});
}

_initContextMenu() {
Expand Down
5 changes: 5 additions & 0 deletions src/server/windows/app-window.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ import {storageKeys} from '../constants';

import _ from 'lodash';
import electron from 'electron';
// import fs from 'fs-extra';
import path from 'path';

// const { version } = fs.readJsonSync(path.resolve(__dirname, '../../../package.json'));

const openAppWindow = (file, storage, devtools) => {
let { height, width } = electron.screen.getPrimaryDisplay().workAreaSize;
// Set last known screen size, otherwise use the default size
Expand All @@ -32,6 +35,8 @@ const openAppWindow = (file, storage, devtools) => {
windowOptions.minHeight = MIN_WINDOW_HEIGHT;
windowOptions.width = Math.floor(screenWidth);
windowOptions.height = Math.floor(screenHeight);
windowOptions.title = 'XLite';
// windowOptions.title = `XLite ${version}`;

return new BrowserWindow({
filePath: file,
Expand Down
1 change: 0 additions & 1 deletion src/static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; script-src 'self'; img-src 'self' data:;
style-src 'self'; font-src 'self'; form-action 'self'; object-src 'none'">
<title>XLite</title>
<link rel="stylesheet" href="./css/main.css">
</head>
<body>
Expand Down
5 changes: 4 additions & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ const mainjs = {
sourceMapFilename: '[file].map', // string
libraryTarget: 'umd'
},
target: 'web'
target: 'web',
optimization: {
minimize: false
}
};

_.merge(errorjs, common);
Expand Down

0 comments on commit 7658a87

Please sign in to comment.