Mise à jour effectuée, merci de nous signaler tout dysfonctionnement ! | Upgrade done, please let us know about any dysfunction!

Commit 55656ee2 authored by Benoit Lavenier's avatar Benoit Lavenier

[fix] Better debug option. Add SDK build

parent 0aa792b5
Pipeline #8992 failed
......@@ -7,47 +7,35 @@ tmp
.idea
.local
src/nw/lib
src/nw/locales
src/nw/node_modules
src/nw/pnacl
src/nw/nw*
src/nw/*.bin
src/nw/chromedriver
src/nw/credits.html
src/nw/*.dat
src/nw/*.pak
src/nw/nacl*
src/nw/minidump*
src/nw/payload*
src/nw/yarn.lock
src/nw/package-lock.json
src/nw/cesium
src/nw/swiftshader/libEGL.so
src/nw/swiftshader/libGLESv2.so
www
arch/linux/.vagrant
arch/linux/cesium-*
arch/linux/*.js*
arch/linux/yarn*
arch/linux/splash.html
arch/linux/package.json
arch/linux/yarn.lock
arch/linux/LICENSE.txt
arch/linux/ubuntu*
arch/linux/nw*
arch/windows/.vagrant
arch/windows/cesium-*
arch/windows/*.js*
arch/windows/yarn*
arch/windows/ubuntu*
arch/windows/nw*
arch/windows/splash.html
arch/windows/package.json
arch/windows/yarn.lock
arch/windows/LICENSE.txt
arch/windows/LICENSE.txt
arch/windows/*.box
arch/windows/.directory
arch/osx/.vagrant
arch/osx/cesium-*
arch/osx/yarn.*
arch/osx/splash.html
arch/osx/package.json
arch/osx/yarn.lock
arch/osx/LICENSE.txt
arch/osx/*.xip
arch/osx/*.box
arch/osx/*.dmg
desktop
downloads
......@@ -10,34 +10,25 @@ export NVM_DIR="$HOME/.nvm"
# Prepare
NVER=$(node -v)
TAG=
NW_VERSION=0.42.2
NW_RELEASE="v${NW_VERSION}"
# Can be override with 'nwjs-sdk'
[[ "_$NW_BASENAME" == "_" ]] && NW_BASENAME="nwjs"
NW="${NW_BASENAME}-${NW_RELEASE}-linux-x64"
NW_GZ="${NW}.tar.gz"
NW_RELEASE=v${NW_VERSION}
NW_BASENAME=nwjs
#NW_BASENAME=nwjs-sdk
NW=${NW_BASENAME}-${NW_RELEASE}-linux-x64
NW_GZ=${NW}.tar.gz
# Folders
ROOT=$(pwd)
DOWNLOADS="${ROOT}/downloads"
RELEASES="${ROOT}/releases"
mkdir -p "${DOWNLOADS}"
# -----------
# Clean sources + releases
# -----------
rm -rf "${DOWNLOADS}/${PROJECT_NAME}"
rm -rf "${RELEASES}"
rm -rf /vagrant/*.deb
rm -rf /vagrant/*.tar.gz
DOWNLOADS=${ROOT}/downloads
RELEASES=${ROOT}/releases
# -----------
# Downloads
# -----------
cd "${DOWNLOADS}"
mkdir -p "${DOWNLOADS}" && cd "${DOWNLOADS}" || exit 1
rm -rf "${DOWNLOADS}/${PROJECT_NAME}"
mkdir -p "${DOWNLOADS}/${PROJECT_NAME}"
if [ ! -d "${DOWNLOADS}/${PROJECT_NAME}_src" ]; then
......@@ -51,26 +42,31 @@ else
fi
# Get release tag
COMMIT=`git rev-list --tags --max-count=1`
TAG=`echo $(git describe --tags $COMMIT) | sed 's/^v//'`
cd ..
ZIP_BASENAME="${PROJECT_NAME}-v$TAG-web"
echo "Checking that ${PROJECT_NAME} binary has been downloaded"
if [ ! -e "${DOWNLOADS}/${ZIP_BASENAME}.zip" ]; then
echo "Have to download it into ${DOWNLOADS}"
cd ${PROJECT_NAME}
wget -kL "${REPO_PUBLIC_URL}/releases/download/v${TAG}/${ZIP_BASENAME}.zip"
unzip ${ZIP_BASENAME}.zip
rm ${ZIP_BASENAME}.zip
cd ..
COMMIT=$(git rev-list --tags --max-count=1)
PROJECT_VERSION=`echo $(git describe --tags $COMMIT) | sed 's/^v//'`
WEB_BASENAME=${PROJECT_NAME}-v${PROJECT_VERSION}-web
WEB_ZIP_FILE=${WEB_BASENAME}.zip
# Compute output base name
if [[ "${NW_BASENAME}" == "nwjs-sdk" ]]; then
echo " SDK: true"
OUTPUT_BASENAME=${PROJECT_NAME}-desktop-v${PROJECT_VERSION}-sdk-linux-x64
else
OUTPUT_BASENAME=${PROJECT_NAME}-desktop-v${PROJECT_VERSION}-linux-x64
fi
DEB_VER=" $TAG"
TAG="v$TAG"
if [ ! -d "${DOWNLOADS}/${WEB_ZIP_FILE}" ]; then
cd ${DOWNLOADS}
echo "Downloading ${WEB_ZIP_FILE} into ${DOWNLOADS} ..."
wget -kL "${REPO_PUBLIC_URL}/releases/download/v${PROJECT_VERSION}/${WEB_ZIP_FILE}"
rm -rf ${PROJECT_NAME} && mkdir -p ${PROJECT_NAME} || exit 1
unzip -o ${WEB_ZIP_FILE} -d "${DOWNLOADS}/${PROJECT_NAME}"
rm ${WEB_ZIP_FILE}
fi
# Get NW.js
if [[ ! -d "${DOWNLOADS}/$NW" ]]; then
if [[ ! -d "${DOWNLOADS}/${NW}" ]]; then
cd ${DOWNLOADS}
echo "Downloading ${NW_GZ}..."
wget -kL https://dl.nwjs.io/${NW_RELEASE}/${NW_GZ}
......@@ -81,13 +77,17 @@ fi
# Releases
# -----------
# Clean previous artifacts
rm -rf "/vagrant/${OUTPUT_BASENAME}.deb"
rm -rf "/vagrant/${OUTPUT_BASENAME}.tar.gz"
# Clean previous releases directory
rm -rf "${RELEASES}"
mkdir -p "${RELEASES}"
cp -r "${DOWNLOADS}/${PROJECT_NAME}" "${RELEASES}/${PROJECT_NAME}"
# Releases builds
cd "${RELEASES}/${PROJECT_NAME}"
mv "${DOWNLOADS}/${PROJECT_NAME}" "${RELEASES}/" && cd "${RELEASES}/${PROJECT_NAME}" || exit 1
# Remove git files
rm -Rf .git
# Remove unused files (API, maps)
......@@ -109,14 +109,16 @@ mkdir -p "${RELEASES}/desktop_release"
cp -r "${DOWNLOADS}/${NW}" "${RELEASES}/desktop_release/nw"
cp -r "${RELEASES}/${PROJECT_NAME}" "${RELEASES}/desktop_release/nw/"
ls "${RELEASES}/desktop_release/nw/"
# Specific desktop files
# Copy Cesium desktop sources files
cp -r /vagrant/package.json "${RELEASES}/desktop_release/nw/"
cp -r /vagrant/yarn.lock "${RELEASES}/desktop_release/nw/"
cp -r /vagrant/cesium-desktop.js "${RELEASES}/desktop_release/nw"
cp -r /vagrant/splash.html "${RELEASES}/desktop_release/nw"
# Injection
sed -i 's/<script src="config.js"><\/script>/<script src="config.js"><\/script><script src="..\/cesium-desktop.js"><\/script>/' "${RELEASES}/desktop_release/nw/${PROJECT_NAME}/index.html" || exit 1
sed -i 's/<script src="config.js"[^>]*><\/script>/<script src="config.js"><\/script><script src="..\/cesium-desktop.js"><\/script>/' ${RELEASES}/desktop_release/nw/${PROJECT_NAME}/index*.html || exit 1
# Specific desktop dependencies (for reading Duniter conf, ...)
cd "${RELEASES}/desktop_release/nw"
......@@ -125,7 +127,7 @@ yarn
# Releases
cp -R "${RELEASES}/desktop_release" "${RELEASES}/desktop_release_tgz"
cd "${RELEASES}/desktop_release_tgz"
tar czf /vagrant/${PROJECT_NAME}-desktop-${TAG}-linux-x64.tar.gz * --exclude ".git" --exclude "coverage" --exclude "test"
tar czf /vagrant/${OUTPUT_BASENAME}.tar.gz * --exclude ".git" --exclude "coverage" --exclude "test"
# -------------------------------------------------
# Build Desktop version .deb
......@@ -136,11 +138,12 @@ cp -r "/vagrant/package" "${RELEASES}/${PROJECT_NAME}-x64" || exit 1
mkdir -p "${RELEASES}/${PROJECT_NAME}-x64/opt/${PROJECT_NAME}/" || exit 1
chmod 755 ${RELEASES}/${PROJECT_NAME}-x64/DEBIAN/post*
chmod 755 ${RELEASES}/${PROJECT_NAME}-x64/DEBIAN/pre*
sed -i "s/Version:.*/Version:$DEB_VER/g" ${RELEASES}/${PROJECT_NAME}-x64/DEBIAN/control || exit 1
sed -i "s/Version:.*/Version:${PROJECT_VERSION}/g" ${RELEASES}/${PROJECT_NAME}-x64/DEBIAN/control || exit 1
cd "${RELEASES}/desktop_release/nw" || exit 1
zip -qr "${RELEASES}/${PROJECT_NAME}-x64/opt/${PROJECT_NAME}/nw.nwb" *
sed -i "s/Package: .*/Package: ${PROJECT_NAME}-desktop/g" "${RELEASES}/${PROJECT_NAME}-x64/DEBIAN/control" || exit 1
cd ${RELEASES}/ || exit 1
fakeroot dpkg-deb --build "${PROJECT_NAME}-x64" || exit 1
mv "${PROJECT_NAME}-x64.deb" "/vagrant/${PROJECT_NAME}-desktop-${TAG}-linux-x64.deb" || exit 1
mv "${PROJECT_NAME}-x64.deb" "/vagrant/${OUTPUT_BASENAME}.deb" || exit 1
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: Cesium
Upstream-Contact: Duniter Team <contact@duniter.org>
Source: https://git.duniter.org/clients/cesium-grp/cesium
Copyright: 2017-2020 Benoit Lavenier
License: GPL-3+
Files: *
......@@ -19,8 +19,8 @@
<script src="cesium-desktop.js"></script>
<!-- Preload JS files here -->
<!-- Preload JS files here
<script src="cesium/dist_js/cesium.js" async></script>
<script src="cesium/dist_js/vendor.js" async></script>
<script src="cesium/dist_js/vendor.js" async></script>-->
</body>
</html>
// Rename "require" to avoid conflicts with pure JS libraries
requireNodejs = require
require = undefined
const expectedCurrency = "g1"
/**** NODEJS MODULES ****/
const fs = requireNodejs('fs');
const path = requireNodejs('path');
const yaml = requireNodejs('js-yaml');
const bs58 = requireNodejs('bs58');
const clc = requireNodejs('cli-color');
const gui = requireNodejs('nw.gui');
Base58 = {
encode: (bytes) => bs58.encode(new Buffer(bytes)),
decode: (data) => new Uint8Array(bs58.decode(data))
}
/**** Program ****/
const HOME = requireNodejs('os').homedir();
const CESIUM_HOME = path.resolve(HOME, '.config/cesium/');
const CESIUM_KEYRING = path.resolve(CESIUM_HOME, 'keyring.yml');
const DUNITER_HOME = path.resolve(HOME, '.config/duniter/duniter_default');
const DUNITER_CONF = path.resolve(DUNITER_HOME, 'conf.json');
const DUNITER_KEYRING = path.resolve(DUNITER_HOME, 'keyring.yml');
const DEFAULT_CESIUM_SETTINGS = {
"useRelative": false,
"timeWarningExpire": 2592000,
"useLocalStorage": true,
"rememberMe": true,
"keepAuthIdle": 600,
"helptip": {
"enable": false
},
"plugins": {
"es": {
"enable": true,
"askEnable": false,
"useRemoteStorage": false,
"host": "g1.data.duniter.fr",
"port": "443",
"notifications": {
"txSent": true,
"txReceived": true,
"certSent": true,
"certReceived": true
}
}
},
"showUDHistory": true
};
const I18N = {
"fr": {
"MENU" : {
"FILE": "Fichier",
"QUIT_ITEM": "Quitter",
"WINDOW": "Fenêtre",
"NEW_WINDOW_ITEM": "Nouvelle fenêtre"
}
},
"en": {
"MENU" : {
"FILE": "File",
"QUIT_ITEM": "Quit",
"WINDOW": "Window",
"NEW_WINDOW_ITEM": "New window"
}
}
};
function isSdkMode () {
return gui && (window.navigator.plugins.namedItem('Native Client') !== null);
}
function isMainWin() {
return gui && gui.Window.get().title && true;
}
/**** Process command line args ****/
var commands = gui && gui.App && gui.App.argv;
var options = {
debug: false,
menu: false
};
if (commands && commands.length) {
for (i in commands) {
switch (commands[i]) {
case "--debug":
options.debug = true;
// Open the DEV tool (need a SDK version of NW)
if (isSdkMode() /*&& isMainWin()*/) {
gui.Window.get().showDevTools();
}
break;
case "--menu":
options.menu = true;
break;
}
}
}
/**** Re-routing console log ****/
if (!isSdkMode() || !options.debug) {
var oldConsole = {
log: console.log,
debug: console.debug,
info: console.info,
warn: console.warn,
error: console.error,
}
if (debug) {
console.debug = function (message) {
process.stdout.write(clc.green("[DEBUG] ") + message + "\n");
oldConsole.debug.apply(this, arguments);
};
console.log = function(message) {
process.stdout.write(clc.blue("[CONSOLE] ") + message + "\n");
oldConsole.log.apply(this, arguments);
}
}
console.info = function(message) {
process.stdout.write(clc.blue("[INFO] ") + message + "\n");
oldConsole.info.apply(this, arguments);
};
console.warn = function(message) {
process.stdout.write(clc.yellow("[WARN] ") + message + "\n");
oldConsole.warn.apply(this, arguments);
};
console.error = function(message) {
if (typeof message == "object") {
process.stderr.write(clc.red("[ERROR] ") + JSON.stringify(message) + "\n");
}
else {
process.stderr.write(clc.red("[ERROR] ") + message + "\n");
}
oldConsole.error.apply(this, arguments);
};
}
/**** Starting (main win) ****/
if (isMainWin()) {
//const nww = requireNodejs('nw');
let settingsStr = window.localStorage.getItem('settings');
let settings = (settingsStr && JSON.parse(settingsStr));
const locale = (settings && settings.locale && settings.locale.id).split('-')[0] || 'en';
console.debug("[NW] User home {" + HOME + "}");
console.debug("[NW] Using locale {" + locale + "}");
if (options.debug) console.info("[NW] Enabling debug mode (--debug)");
if (options.menu) console.info("[NW] Enabling menu bar(--menu)");
/**** Menu bar ****/
if (options.menu) {
var menuBar = new gui.Menu({ type: 'menubar' });
// File
var filemenu = new gui.Menu();
let quitItem = new gui.MenuItem({
label: I18N[locale].MENU.QUIT_ITEM,
click: function() {
console.log("[NW] Closing...");
gui.App.closeAllWindows();
},});
filemenu.append(quitItem);
menuBar.append(new gui.MenuItem({
label: I18N[locale].MENU.FILE,
submenu: filemenu
}));
// Window
var winmenu = new gui.Menu();
let newWinItem = new gui.MenuItem({
label: I18N[locale].MENU.NEW_WINDOW_ITEM,
click: function() {
console.log("[NW] Opening new window...");
gui.Window.open("cesium/index.html");
},});
winmenu.append(newWinItem);
// Window > Accounts
var accountMenu = new gui.Menu();
let openAccountItem = new gui.MenuItem({
label: I18N[locale].MENU.OPEN_ACCOUNT||'Wallet 1',
click: function() {
console.log("[NW] Opening wallet 1...");
gui.Window.open("cesium/index.html", {
focus: true
},
function(win){
win.window.localStorage.setItem('pubkey', "38MEAZN68Pz1DTvT3tqgxx4yQP6snJCQhPqEFxbDk4aE");
console.log("[NW] Loading wallet 1...");
});
},});
accountMenu.append(openAccountItem);
winmenu.append(new gui.MenuItem({
label: I18N[locale].MENU.ACCOUNTS||'Accounts',
submenu: accountMenu
}));
menuBar.append(new gui.MenuItem({
label: I18N[locale].MENU.WINDOW,
submenu: winmenu
}));
gui.Window.get().menu = menuBar;
}
/**** Checking Cesium keyring file ****/
let keyringRaw, keyring, keyPairOK;
let pubkey = settings && window.localStorage.getItem('pubkey');
var rememberMe = (!settings && DEFAULT_CESIUM_SETTINGS.rememberMe) || settings.rememberMe == true;
var keyringFile = settings && settings.keyringFile || CESIUM_KEYRING;
if (rememberMe && fs.existsSync(keyringFile)) {
console.debug("[NW] Keyring file detected at {" + keyringFile + "}...");
keyringRaw = fs.readFileSync(keyringFile);
keyring = yaml.safeLoad(keyringRaw);
keyPairOK = keyring.pub && keyring.sec && true;
if (!keyPairOK) {
console.warn("[NW] Invalid keyring file: missing 'pub' or 'sec' field! Skipping auto-login.");
// Store settings
settings = settings || DEFAULT_CESIUM_SETTINGS;
if (settings.keyringFile) {
delete settings.keyringFile;
window.localStorage.setItem('settings', JSON.stringify(settings));
}
} else {
console.debug("[NW] Auto-login user on {" + keyring.pub + "}");
window.localStorage.setItem('pubkey', keyring.pub);
const keepAuthSession = !settings || (settings.keepAuthIdle == 9999);
if (keepAuthSession) {
console.debug("[NW] Auto-authenticate on account (using keyring file)");
window.sessionStorage.setItem('seckey', keyring.sec);
}
// Store settings
settings = settings || DEFAULT_CESIUM_SETTINGS;
if (!settings.keyringFile || settings.keyringFile != keyringFile) {
settings.keyringFile = keyringFile;
window.localStorage.setItem('settings', JSON.stringify(settings));
}
}
} else if (settings && settings.keyringFile) {
console.warn("[NW] Unable to found keyring file define in Cesium settings. Skipping auto-login");
// Store settings
settings = settings || DEFAULT_CESIUM_SETTINGS;
if (settings.keyringFile) {
delete settings.keyringFile;
window.localStorage.setItem('settings', JSON.stringify(settings));
}
}
/**** Checking Duniter configuration files ****/
if (!keyPairOK && fs.existsSync(DUNITER_CONF) && fs.existsSync(DUNITER_KEYRING)) {
const duniterConf = requireNodejs(DUNITER_CONF);
keyringRaw = fs.readFileSync(DUNITER_KEYRING);
keyring = yaml.safeLoad(keyringRaw);
console.log('Duniter conf = ', duniterConf);
console.log('Duniter keyring pubkey = ', keyring.pub);
const local_host = duniterConf.ipv4 || duniterConf.ipv6;
const local_port = duniterConf.port;
let keyPairOK = pubkey && true;
if (keyPairOK) {
console.log('Compte connecté dans Cesium. Comparaison avec celui du nœud local...')
keyPairOK = pubkey === keyring.pub;
if (!keyPairOK) {
console.log('Le compte Cesium est différent de celui du nœud.')
// Check is need to ask user to use node keyring
if (settings && settings.askLocalNodeKeyring === false) {
console.log("L'utilisateur a demander ultérieurement d'ignorer le basculement sur le nœud local.");
keyPairOK = true;
}
} else {
console.log('Compte Cesium déjà identique au nœud local.');
// Configuration de la clef privée, si autorisé dans les paramètres
const keepAuthSession = !settings || (settings.keepAuthIdle == 9999);
if (keepAuthSession) {
console.debug('Configuring Cesium secret key...');
window.sessionStorage.setItem('seckey', keyring.sec);
}
}
}
if (duniterConf.currency === expectedCurrency
&& (!keyPairOK
|| (settings && settings.node &&
(settings.node.host != local_host || settings.node.port != local_port))
)) {
const confirmationMessage = (locale === 'fr') ?
'Un nœud pour la monnaie ' + expectedCurrency + ' a été détecté sur cet ordinateur, voulez-vous que Cesium s\'y connecte ?' :
'A node for currency ' + expectedCurrency + ' has been detected on this computer. Do you want Cesium to connect it?';
if (confirm(confirmationMessage)) {
console.debug('Configuring Cesium on local node...');
// Generate settings, on local node (with node's keyring)
const keepAuthSession = !settings || (settings.keepAuthIdle == 9999);
settings = settings || DEFAULT_CESIUM_SETTINGS;
settings.node = {
"host": local_host,
"port": local_port
};
settings.rememberMe = true;
settings.useLocalStorage = true;
if (keepAuthSession) {
settings.keepAuthIdle = 9999;
}
settings.plugins = settings.plugins || DEFAULT_CESIUM_SETTINGS.plugins;
settings.plugins.es = settings.plugins.es || DEFAULT_CESIUM_SETTINGS.plugins.es;
if (locale === "fr") {
settings.plugins.es.defaultCountry = "France";
}
// Store settings
window.localStorage.setItem('settings', JSON.stringify(settings));
// Store pubkey and seckey (if allowed)
window.localStorage.setItem('pubkey', keyring.pub);
if (keepAuthSession) {
console.debug('Configuring Cesium secret key...');
window.sessionStorage.setItem('seckey', keyring.sec);
}
}
// Do Not ask again
else {
console.debug('User not need to connect on local node. Configuring Cesium to remember this choice...');
settings = settings || DEFAULT_CESIUM_SETTINGS;
settings.askLocalNodeKeyring = false;
window.localStorage.setItem('settings', JSON.stringify(settings));
}
}
}
}
{
"name": "cesium",
"main": "cesium/index.html",
"license": "AGPL-3.0",
"window": {
"id": "cesium",
"icon": "cesium/img/logo.png",
"title": "v0.12.7",
"width": 1300,
"height": 800,
"min_width": 750,
"min_height": 400
},
"dependencies": {
"bs58": "^4.0.1",