Skip to content
This repository has been archived by the owner on Sep 5, 2020. It is now read-only.

Fixes blank screen at startup #1110

Merged
merged 7 commits into from
Aug 24, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 8 additions & 11 deletions interface/client/appStart.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@
if(location.hash)
return;


// set browser as default tab
if(!LocalStore.get('selectedTab'))
LocalStore.set('selectedTab', 'wallet');

/**
The init function of Mist

Expand All @@ -17,7 +12,6 @@ The init function of Mist
mistInit = function(){
console.info('Initialise Mist');


Tabs.onceSynced.then(function() {
if (0 <= location.search.indexOf('reset-tabs')) {
console.info('Resetting UI tabs');
Expand All @@ -35,17 +29,20 @@ mistInit = function(){
});
}


Tabs.upsert({_id: 'wallet'}, {
url: 'https://wallet.ethereum.org',
position: 1,
permissions: {
admin: true
}
});
})
.then(function() {
window.trigger('mist-ready');
});

// Sets browser as default tab if:
// 1) there's no record of selected tab
// 2) data is corrupted (no saved tab matches localstore)
if(!LocalStore.get('selectedTab') || !Tabs.findOne(LocalStore.get('selectedTab'))){
LocalStore.set('selectedTab', 'wallet');
}
});
};

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this was also bugging me and giving an error. @hiddentao do you remember what it was for?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was for future usage. A dapp would be able to listen to the mist-ready event to know when all data was loaded and ready. I'd prefer if this was re-instated.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but trigger isn't even a valid function. Did you meant $(window).trigger ?

Expand Down
8 changes: 2 additions & 6 deletions modules/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@ exports.init = function() {
return Q.try(() => {
// if db file doesn't exist then create it
try {
log.debug(`Check that db exists: ${filePath}`);

fs.accessSync(filePath, fs.R_OK);

log.debug('Check that db exists and it\'s writeable: ${filePath}');
fs.accessSync(filePath, fs.R_OK | fs.W_OK);
return Q.resolve();
} catch (err) {
log.info(`Creating db: ${filePath}`);
Expand All @@ -43,10 +41,8 @@ exports.init = function() {
autoloadCallback: function(err) {
if (err) {
log.error(err);

reject(new Error('Error instantiating db'));
}

resolve();
}
});
Expand Down
48 changes: 18 additions & 30 deletions modules/syncMinimongo.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
/**
@module syncMinimongo
*/


var electron = require('electron');



/**
* Sync IPC calls received from given window into given db table.
* @param {Object} coll Db collection to save to.
*/
exports.backendSync = function() {
var log = require('./utils/logger').create('syncMinimongo');

var db = require('./db');

var ipc = electron.ipcMain;

ipc.on('minimongo-add', function(event, args) {
Expand All @@ -28,7 +22,6 @@ exports.backendSync = function() {

if (!coll.findOne({_id: _id})) {
args.fields._id = _id;

coll.insert(args.fields);
}
});
Expand All @@ -40,7 +33,6 @@ exports.backendSync = function() {
log.trace('minimongo-changed', collName, args._id);

var _id = args._id;

var item = coll.findOne({_id: _id});

if (item) {
Expand All @@ -61,7 +53,6 @@ exports.backendSync = function() {
log.trace('minimongo-removed', collName, args._id);

var _id = args._id;

var item = coll.findOne({_id: _id});

if (item) {
Expand All @@ -74,9 +65,8 @@ exports.backendSync = function() {
// get all data (synchronous)
ipc.on('minimongo-reloadSync', function(event, args) {
var collName = args.collName,
coll = db.getCollection(collName);

var docs = coll.find();
coll = db.getCollection(collName),
docs = coll.find();

log.debug('minimongo-reloadSync, no. of docs:', collName, docs.length);

Expand All @@ -100,34 +90,32 @@ exports.backendSync = function() {


exports.frontendSync = function(coll) {
var ipc = electron.ipcRenderer;

var collName = coll._name;
var ipc = electron.ipcRenderer,
collName = coll._name,
syncDoneResolver;

console.debug('Reload collection from backend: ', collName);

var syncDoneResolver = null;
coll.onceSynced = new Promise(function(resolve, reject) {
syncDoneResolver = resolve;
});


(new Promise(function(resolve, reject) {
var dataStr = ipc.sendSync('minimongo-reloadSync', {
var dataStr, dataJson;

dataStr = ipc.sendSync('minimongo-reloadSync', {
collName: collName
Copy link
Contributor

@hiddentao hiddentao Aug 24, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why has this line been removed? Logging is important.

});

if (!dataStr) {
return resolve();
}

try {
coll.remove({});

var dataJson = JSON.parse(dataStr);
if (!dataStr || (dataJson = JSON.parse(dataStr)).length == 0) {
return resolve();
}

var done = 0;

coll.remove({});

// we do inserts slowly, to avoid race conditions when it comes
// to updating the UI
dataJson.forEach(function(record) {
Expand All @@ -141,9 +129,9 @@ exports.frontendSync = function(coll) {
record.redirect = null;
}

coll.insert(record);
coll.insert(record);
} catch (err) {
console.error(err.toString());
console.error(err.toString());
}

done++;
Expand All @@ -152,7 +140,7 @@ exports.frontendSync = function(coll) {
resolve();
}
});
});
});
} catch (err) {
reject(err);
}
Expand All @@ -163,10 +151,10 @@ exports.frontendSync = function(coll) {
.then(function() {
// start watching for changes
coll.find().observeChanges({
'added': function(id, fields){
'added': function(id, fields){
ipc.send('minimongo-add', {
collName: collName,
_id: id,
_id: id,
fields: fields,
});
},
Expand Down