This repository has been archived by the owner on Sep 5, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Fixes blank screen at startup #1110
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ef93be9
Removing unneeded code
evertonfraga b40c81b
Checking if DB is writable
evertonfraga d3fa3c8
Resolving DB sync when database is empty
evertonfraga 6803d88
Enhancing selected tab defaults at startup
evertonfraga a64d772
Checking for R/W permissions
evertonfraga 095c61b
Restoring log entry
evertonfraga cda3348
Improving error handling
evertonfraga File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { | ||
|
@@ -28,7 +22,6 @@ exports.backendSync = function() { | |
|
||
if (!coll.findOne({_id: _id})) { | ||
args.fields._id = _id; | ||
|
||
coll.insert(args.fields); | ||
} | ||
}); | ||
|
@@ -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) { | ||
|
@@ -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) { | ||
|
@@ -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); | ||
|
||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) { | ||
|
@@ -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++; | ||
|
@@ -152,7 +140,7 @@ exports.frontendSync = function(coll) { | |
resolve(); | ||
} | ||
}); | ||
}); | ||
}); | ||
} catch (err) { | ||
reject(err); | ||
} | ||
|
@@ -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, | ||
}); | ||
}, | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.There was a problem hiding this comment.
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
?