2014-06-29 23:40:40 +00:00
|
|
|
define([
|
|
|
|
"command",
|
|
|
|
"storage/settingsProvider",
|
|
|
|
"ui/statusbar",
|
2014-07-07 18:49:13 +00:00
|
|
|
"sessions/state",
|
|
|
|
"util/i18n"
|
|
|
|
], function(command, Settings, status, state, i18n) {
|
2014-06-29 23:40:40 +00:00
|
|
|
|
|
|
|
var autosaveTimeout = null;
|
|
|
|
var scheduleAutosave = function() {
|
|
|
|
if (autosaveTimeout) clearTimeout(autosaveTimeout);
|
|
|
|
Settings.pull("user").then(function(settings) {
|
|
|
|
if(settings.user.autosaveInterval) {
|
|
|
|
//schedule next save in minutes
|
|
|
|
autosaveTimeout = setTimeout(autosave, settings.user.autosaveInterval * 60 * 1000);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
var autosave = function() {
|
2014-07-07 18:49:13 +00:00
|
|
|
status.toast(i18n.get("fileAutosaving"));
|
2014-06-29 23:40:40 +00:00
|
|
|
state.tabs.forEach(function(tab) {
|
2015-03-31 14:06:32 +00:00
|
|
|
if (tab.file && !tab.file.virtual && tab.modified) {
|
2014-06-29 23:40:40 +00:00
|
|
|
tab.save();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
scheduleAutosave();
|
|
|
|
};
|
|
|
|
|
|
|
|
scheduleAutosave();
|
|
|
|
command.on("init:restart", scheduleAutosave);
|
|
|
|
|
|
|
|
window.on("blur", function() {
|
|
|
|
Settings.pull("user").then(function(settings) {
|
|
|
|
if (settings.user.autosaveOnBlur) {
|
|
|
|
autosave();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|