Skip to content

Commit

Permalink
Refactory updating lists, now they get 5 seconds to finish
Browse files Browse the repository at this point in the history
  • Loading branch information
gokr committed Jun 13, 2016
1 parent b45738a commit ab18417
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions app/hyper/ui/main-window-func.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,14 @@ exports.defineUIFunctions = function(hyper)
initAppLists()
}

function updateListsSilently() {
function updateLists(silent) {
if (!mUpdatingLists) {
mUpdatingLists = true
hyper.UI.updateExampleList(true) // Silent
hyper.UI.updateLibraryList(true) // Silent
setTimeout(function() {mUpdatingLists = false}, 5000)
hyper.UI.updateExampleList(silent)
hyper.UI.updateLibraryList(silent)
} else {
console.log("Already updating lists, ignore EVENTS.LOGIN")
console.log("Already updating lists, ignoring")
}
}

Expand All @@ -89,21 +90,20 @@ exports.defineUIFunctions = function(hyper)
readProjectList()
hyper.UI.displayProjectList()

// If we have verified basic internet access - we load the lists.
// If we have verified basic internet access - we load the lists but not silently.
UTIL.checkInternet().then(hasInternet => {
if (hasInternet) {
hyper.UI.updateExampleList(false)
hyper.UI.updateLibraryList(false)
updateLists(false)
}
})

// Register a timer so that we update the lists every 30 min, but silently.
setInterval(function() {
updateListsSilently()
updateLists(true)
}, 30 * 60 * 1000);

// When user logs in we update
EVENTS.subscribe(EVENTS.LOGIN, updateListsSilently)
// When user logs in we update silently
EVENTS.subscribe(EVENTS.LOGIN, function() {updateLists(true)})

hyper.UI.setServerMessageFun()
}
Expand Down Expand Up @@ -1074,8 +1074,7 @@ exports.defineUIFunctions = function(hyper)
var oldUrls = SETTINGS.getRepositoryURLs()
if (newUrls != oldUrls) {
SETTINGS.setRepositoryURLs(newUrls)
hyper.UI.updateExampleList(false)
hyper.UI.updateLibraryList(false)
updateLists(false)
}

// Check if server address has been changed.
Expand Down

0 comments on commit ab18417

Please sign in to comment.