1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/keeweb_ynh.git synced 2024-09-03 19:26:33 +02:00
keeweb_ynh/sources/main.js
2016-03-01 10:47:41 +01:00

43 lines
1.3 KiB
JavaScript

// KeeWeb launcher script
// This script is distributed with the app and is its entry point
// It checks whether the app is available in userData folder and if its version is higher than local, launches it
// This script is the only part which will be updated only with the app itself, auto-update will not change it
// (C) Antelle 2015, MIT license https://github.com/antelle/keeweb
'use strict';
/* jshint node:true */
/* jshint browser:false */
var app = require('app'),
path = require('path'),
fs = require('fs');
var userDataDir = app.getPath('userData'),
appPathUserData = path.join(userDataDir, 'app.js'),
appPath = path.join(__dirname, 'app.js');
if (fs.existsSync(appPathUserData)) {
var versionLocal = require('./package.json').version;
try {
var versionUserData = require(path.join(userDataDir, 'package.json')).version;
versionLocal = versionLocal.split('.');
versionUserData = versionUserData.split('.');
for (var i = 0; i < versionLocal.length; i++) {
if (+versionUserData[i] > +versionLocal[i]) {
appPath = appPathUserData;
break;
}
if (+versionUserData[i] < +versionLocal[i]) {
break;
}
}
}
catch (e) {
console.error('Error reading user file version', e);
}
}
require(appPath);