electron fixes

This commit is contained in:
azivner 2018-04-05 23:17:19 -04:00
parent 98f80998b9
commit e827ddffb9
7 changed files with 37 additions and 31 deletions

View File

@ -1,20 +1,19 @@
import server from './services/server.js'; import server from './services/server.js';
$(document).ready(() => { $(document).ready(async () => {
server.get('migration').then(result => { const {appDbVersion, dbVersion} = await server.get('migration');
const appDbVersion = result.app_dbVersion;
const dbVersion = result.dbVersion;
if (appDbVersion === dbVersion) { console.log("HI", {appDbVersion, dbVersion});
$("#up-to-date").show();
}
else {
$("#need-to-migrate").show();
$("#app-db-version").html(appDbVersion); if (appDbVersion === dbVersion) {
$("#db-version").html(dbVersion); $("#up-to-date").show();
} }
}); else {
$("#need-to-migrate").show();
$("#app-db-version").html(appDbVersion);
$("#db-version").html(dbVersion);
}
}); });
$("#run-migration").click(async () => { $("#run-migration").click(async () => {
@ -37,4 +36,11 @@ $("#run-migration").click(async () => {
$("#migration-table").append(row); $("#migration-table").append(row);
} }
});
// copy of this shortcut to be able to debug migration problems
$(document).bind('keydown', 'ctrl+shift+i', () => {
require('electron').remote.getCurrentWindow().toggleDevTools();
return false;
}); });

View File

@ -100,7 +100,7 @@ setTimeout(() => {
lastSyncId: lastSyncId lastSyncId: lastSyncId
})); }));
}, 1000); }, 1000);
}, 1000); }, 0);
export default { export default {
logError, logError,

View File

@ -85,19 +85,17 @@ async function ajax(url, method, data) {
}); });
} }
setTimeout(() => { if (utils.isElectron()) {
if (utils.isElectron()) { const ipc = require('electron').ipcRenderer;
const ipc = require('electron').ipcRenderer;
ipc.on('server-response', (event, arg) => { ipc.on('server-response', (event, arg) => {
console.log(utils.now(), "Response #" + arg.requestId + ": " + arg.statusCode); console.log(utils.now(), "Response #" + arg.requestId + ": " + arg.statusCode);
reqResolves[arg.requestId](arg.body); reqResolves[arg.requestId](arg.body);
delete reqResolves[arg.requestId]; delete reqResolves[arg.requestId];
}); });
} }
}, 100);
export default { export default {
get, get,

View File

@ -7,7 +7,7 @@ const appInfo = require('../../services/app_info');
async function getMigrationInfo() { async function getMigrationInfo() {
return { return {
dbVersion: parseInt(await optionService.getOption('dbVersion')), dbVersion: parseInt(await optionService.getOption('dbVersion')),
app_dbVersion: appInfo.dbVersion appDbVersion: appInfo.dbVersion
}; };
} }

View File

@ -19,6 +19,7 @@ function init(app) {
res.status = function(statusCode) { res.status = function(statusCode) {
res.statusCode = statusCode; res.statusCode = statusCode;
return res;
}; };
res.send = function(obj) { res.send = function(obj) {

View File

@ -1,6 +1,7 @@
const scriptService = require('./script'); const scriptService = require('./script');
const repository = require('./repository'); const repository = require('./repository');
const cls = require('./cls'); const cls = require('./cls');
const sqlInit = require('./sql_init');
async function runNotesWithLabel(runAttrValue) { async function runNotesWithLabel(runAttrValue) {
const notes = await repository.getEntities(` const notes = await repository.getEntities(`
@ -19,8 +20,10 @@ async function runNotesWithLabel(runAttrValue) {
} }
} }
setTimeout(cls.wrap(() => runNotesWithLabel('backendStartup')), 10 * 1000); sqlInit.dbReady.then(() => {
setTimeout(cls.wrap(() => runNotesWithLabel('backendStartup')), 10 * 1000);
setInterval(cls.wrap(() => runNotesWithLabel('hourly')), 3600 * 1000); setInterval(cls.wrap(() => runNotesWithLabel('hourly')), 3600 * 1000);
setInterval(cls.wrap(() => runNotesWithLabel('daily')), 24 * 3600 * 1000); setInterval(cls.wrap(() => runNotesWithLabel('daily')), 24 * 3600 * 1000);
});

View File

@ -18,8 +18,6 @@ const log = require('./services/log');
const appInfo = require('./services/app_info'); const appInfo = require('./services/app_info');
const messagingService = require('./services/messaging'); const messagingService = require('./services/messaging');
const utils = require('./services/utils'); const utils = require('./services/utils');
const sql = require('./services/sql');
const sqlInit = require('./services/sql_init');
const port = normalizePort(config['Network']['port'] || '3000'); const port = normalizePort(config['Network']['port'] || '3000');
app.set('port', port); app.set('port', port);
@ -56,7 +54,7 @@ httpServer.listen(port);
httpServer.on('error', onError); httpServer.on('error', onError);
httpServer.on('listening', onListening); httpServer.on('listening', onListening);
sqlInit.dbReady.then(() => messagingService.init(httpServer, sessionParser)); messagingService.init(httpServer, sessionParser);
if (utils.isElectron()) { if (utils.isElectron()) {
const electronRouting = require('./routes/electron'); const electronRouting = require('./routes/electron');