mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-09-22 00:06:06 +08:00
fix(auto-updater): Make updates check happen every 5 minutes, fix critical crash
Summary: Additional references to the windowmanager Improve some log messages to make them more clear Make shipLogs the throttled version. Calling shipLogs over and over leads to crash Test Plan: Run tests Reviewers: evan Reviewed By: evan Differential Revision: https://phab.nylas.com/D1538
This commit is contained in:
parent
9d18b1e1d5
commit
23bf42c227
|
@ -567,7 +567,6 @@ class Atom extends Model
|
|||
startRootWindow: ->
|
||||
{resourcePath, safeMode} = @getLoadSettings()
|
||||
|
||||
console.log ('startRootWindow')
|
||||
CommandInstaller = require './command-installer'
|
||||
CommandInstaller.installAtomCommand resourcePath, false, (error) ->
|
||||
console.warn error.message if error?
|
||||
|
|
|
@ -126,7 +126,7 @@ class ApplicationMenu
|
|||
]
|
||||
|
||||
focusedWindow: ->
|
||||
_.find global.application.windows, (atomWindow) -> atomWindow.isFocused()
|
||||
global.application.windowManager.focusedWindow()
|
||||
|
||||
# Combines a menu template with the appropriate keystroke.
|
||||
#
|
||||
|
|
|
@ -34,10 +34,10 @@ class AutoUpdateManager
|
|||
autoUpdater = require 'auto-updater'
|
||||
|
||||
autoUpdater.on 'error', (event, message) =>
|
||||
@setState(ErrorState)
|
||||
console.error "Error Downloading Update: #{message}"
|
||||
@setState(ErrorState)
|
||||
|
||||
autoUpdater.setFeedUrl @feedUrl
|
||||
autoUpdater.setFeedUrl(@feedUrl)
|
||||
|
||||
autoUpdater.on 'checking-for-update', =>
|
||||
@setState(CheckingState)
|
||||
|
@ -53,6 +53,9 @@ class AutoUpdateManager
|
|||
@emitUpdateAvailableEvent(@getWindows()...)
|
||||
|
||||
@check(hidePopups: true)
|
||||
setInterval =>
|
||||
@check(hidePopups: true)
|
||||
, (1000 * 60 * 5)
|
||||
|
||||
switch process.platform
|
||||
when 'win32'
|
||||
|
@ -74,10 +77,10 @@ class AutoUpdateManager
|
|||
@state
|
||||
|
||||
check: ({hidePopups}={}) ->
|
||||
console.log "Checking for updates..."
|
||||
unless hidePopups
|
||||
autoUpdater.once 'update-not-available', @onUpdateNotAvailable
|
||||
autoUpdater.once 'error', @onUpdateError
|
||||
|
||||
autoUpdater.checkForUpdates()
|
||||
|
||||
install: ->
|
||||
|
@ -97,7 +100,7 @@ class AutoUpdateManager
|
|||
icon: @iconURL()
|
||||
message: 'No update available.'
|
||||
title: 'No Update Available'
|
||||
detail: "Version #{@version} is the latest version."
|
||||
detail: "You're running the latest version of Nylas Mail (#{@version})."
|
||||
|
||||
onUpdateError: (event, message) =>
|
||||
autoUpdater.removeListener 'update-not-available', @onUpdateNotAvailable
|
||||
|
@ -111,4 +114,4 @@ class AutoUpdateManager
|
|||
detail: message
|
||||
|
||||
getWindows: ->
|
||||
global.application.windows
|
||||
global.application.windowManager.windows()
|
||||
|
|
|
@ -165,19 +165,6 @@ class WindowManager
|
|||
# Returns a new AtomWindow
|
||||
#
|
||||
newWindow: (options={}) ->
|
||||
supportedHotWindowKeys = [
|
||||
"title"
|
||||
"width"
|
||||
"height"
|
||||
"windowType"
|
||||
"windowProps"
|
||||
]
|
||||
|
||||
unsupported = _.difference(Object.keys(options), supportedHotWindowKeys)
|
||||
if unsupported.length > 0
|
||||
console.log "WARNING! You are passing in options that can't be hotLoaded into a new window. Please either change the options or pass the `coldStart:true` option to suppress this warning. If it's just data for the window, please put them in the `windowProps` param."
|
||||
console.log unsupported
|
||||
|
||||
if options.coldStart or not @_hotWindows[options.windowType]?
|
||||
return @newColdWindow(options)
|
||||
else
|
||||
|
@ -202,7 +189,7 @@ class WindowManager
|
|||
#
|
||||
registerHotWindow: ({windowType, replenishNum, windowPackages}={}) ->
|
||||
if not windowType
|
||||
throw new Error("please provide a windowType when registering a hot window")
|
||||
throw new Error("registerHotWindow: please provide a windowType")
|
||||
|
||||
@_hotWindows ?= {}
|
||||
@_hotWindows[windowType] ?= {}
|
||||
|
@ -244,9 +231,27 @@ class WindowManager
|
|||
win = null
|
||||
|
||||
if not hotWindowParams?
|
||||
console.log "WARNING! The requested windowType '#{options.windowType}' has not been registered. Be sure to call `registerWindowType` first in your packages setup."
|
||||
console.log "WindowManager: Warning! The requested windowType '#{options.windowType}'
|
||||
has not been registered. Be sure to call `registerWindowType` first
|
||||
in your packages setup."
|
||||
return @newColdWindow(options)
|
||||
|
||||
supportedHotWindowKeys = [
|
||||
"title"
|
||||
"width"
|
||||
"height"
|
||||
"windowType"
|
||||
"windowProps"
|
||||
]
|
||||
|
||||
unsupported = _.difference(Object.keys(options), supportedHotWindowKeys)
|
||||
if unsupported.length > 0
|
||||
console.log "WindowManager: Nylas will open a new hot window of type #{options.windowType},
|
||||
but you are passing options that can't be applied to the preloaded window
|
||||
(#{JSON.stringify(unsupported)}). Please change the options or pass the
|
||||
`coldStart:true` option to use a new window instead of a hot window. If
|
||||
it's just data for the window, please put them in the `windowProps` param."
|
||||
|
||||
if hotWindowParams.loadedWindows.length is 0
|
||||
# No windows ready
|
||||
options.windowPackages = hotWindowParams.windowPackages
|
||||
|
@ -304,7 +309,7 @@ class WindowManager
|
|||
@_processingQueue = true
|
||||
if @_replenishQueue.length > 0
|
||||
options = @_replenishQueue.shift()
|
||||
console.log "---> Launching new '#{options.windowType}' window"
|
||||
console.log "WindowManager: Preparing a new '#{options.windowType}' window"
|
||||
newWindow = new AtomWindow(options)
|
||||
@_hotWindows[options.windowType].loadedWindows.push(newWindow)
|
||||
newWindow.once 'window:loaded', =>
|
||||
|
|
|
@ -163,6 +163,22 @@ module.exports = ErrorReporter = (function() {
|
|||
};
|
||||
|
||||
ErrorReporter.prototype.shipLogs = function(reason) {
|
||||
if (!this.shipLogsQueued) {
|
||||
var timeSinceLogShip = Date.now() - this.shipLogsTime;
|
||||
if (timeSinceLogShip > 20000) {
|
||||
this.runShipLogsTask(reason);
|
||||
} else {
|
||||
this.shipLogsQueued = true;
|
||||
var self = this;
|
||||
setTimeout(function() {
|
||||
self.runShipLogsTask(reason);
|
||||
self.shipLogsQueued = false;
|
||||
}, 20000 - timeSinceLogShip);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
ErrorReporter.prototype.runShipLogsTask = function(reason) {
|
||||
var self = this;
|
||||
|
||||
this.shipLogsTime = Date.now();
|
||||
|
@ -179,27 +195,12 @@ module.exports = ErrorReporter = (function() {
|
|||
|
||||
console.log("ErrorReporter: Shipping Logs. " + reason);
|
||||
|
||||
Task = require('./task')
|
||||
Task = require('./task');
|
||||
ship = Task.once(fs.absolute('./tasks/ship-logs-task'), tmpPath, logPattern, function() {
|
||||
self.appendLog("ErrorReporter: Shipped Logs.");
|
||||
});
|
||||
};
|
||||
|
||||
ErrorReporter.prototype.shipLogsThrottled = function(reason) {
|
||||
if (!this.shipLogsQueued) {
|
||||
var timeSinceLogShip = Date.now() - this.shipLogsTime;
|
||||
if (timeSinceLogShip > 5000) {
|
||||
this.shipLogs(reason);
|
||||
} else {
|
||||
this.shipLogsQueued = true;
|
||||
var self = this;
|
||||
setTimeout(function() {
|
||||
self.shipLogs(reason);
|
||||
self.shipLogsQueued = false;
|
||||
}, 5000 - timeSinceLogShip);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
ErrorReporter.prototype.getVersion = function() {
|
||||
var _ref;
|
||||
|
@ -224,7 +225,7 @@ module.exports = ErrorReporter = (function() {
|
|||
});
|
||||
|
||||
this.appendLog(err, metadata);
|
||||
this.shipLogsThrottled('Exception occurred');
|
||||
this.shipLogs('Exception occurred');
|
||||
};
|
||||
|
||||
return ErrorReporter;
|
||||
|
|
|
@ -223,7 +223,10 @@ class DatabaseView extends ModelView
|
|||
delete page.metadata[id]
|
||||
dirtied = true
|
||||
if dirtied
|
||||
@log('Invalidated metadata for items with ids: '+JSON.stringify(ids))
|
||||
if ids.length < 5
|
||||
@log("Invalidated metadata for items with ids: #{JSON.stringify(ids)}")
|
||||
else
|
||||
@log("Invalidated metadata for #{ids.length} items")
|
||||
@retrievePageMetadata(idx, page.items)
|
||||
|
||||
invalidateCount: ->
|
||||
|
|
Loading…
Reference in a new issue