Implemented an auto save feature that periodically saves all files

Changed the label for the old "auto save feature" to make it more distinct from the new feature
Removed the setting from view for non-desktop users, because it wasn't supported there anyway
Fixes #745
This commit is contained in:
Dennis Ploeger 2019-01-02 15:19:19 +01:00
parent 72c912d57f
commit 425389051a
6 changed files with 48 additions and 2 deletions

View File

@ -354,7 +354,10 @@
"setGenTableView": "Entries list table view",
"setGenColorfulIcons": "Colorful custom icons in list",
"setGenFunction": "Function",
"setGenAutoSync": "Automatically save and sync",
"setGenAutoSyncOnClose": "Automatically save and sync on close",
"setGenAutoSyncTimer": "Automatically save and sync periodically",
"setGenAutoSyncTimerOff": "Disabled",
"setGenAutoSyncTimerInterval": "Every {} minute(s)",
"setGenRememberKeyFiles": "Remember key files",
"setGenNoRememberKeyFiles": "Don't remember",
"setGenRememberKeyFilesData": "Store in the internal app storage",

View File

@ -12,6 +12,7 @@ const AppSettingsModel = Backbone.Model.extend({
autoUpdate: 'install',
clipboardSeconds: 0,
autoSave: true,
autoSaveInterval: 0,
rememberKeyFiles: false,
idleMinutes: 15,
minimizeOnClose: false,

View File

@ -360,6 +360,7 @@ const FileModel = Backbone.Model.extend({
setModified: function() {
if (!this.get('demo')) {
this.set({ modified: true, dirty: true });
Backbone.trigger('file-modified');
}
},

View File

@ -84,6 +84,7 @@ const AppView = Backbone.View.extend({
this.listenTo(Backbone, 'app-minimized', this.appMinimized);
this.listenTo(Backbone, 'show-context-menu', this.showContextMenu);
this.listenTo(Backbone, 'second-instance', this.showSingleInstanceAlert);
this.listenTo(Backbone, 'file-modified', this.handleAutoSaveTimer);
this.listenTo(UpdateModel.instance, 'change:updateReady', this.updateApp);
@ -476,6 +477,19 @@ const AppView = Backbone.View.extend({
}
},
handleAutoSaveTimer: function () {
if (this.model.settings.get('autoSaveInterval') !== 0) {
// trigger periodical auto save
if (this.autoSaveTimeoutId) {
clearTimeout(this.autoSaveTimeoutId);
}
this.autoSaveTimeoutId = setTimeout(
this.saveAll.bind(this),
this.model.settings.get('autoSaveInterval') * 1000 * 60
);
}
},
saveAndLock: function(complete) {
let pendingCallbacks = 0;
const errorFiles = [];

View File

@ -28,6 +28,7 @@ const SettingsGeneralView = Backbone.View.extend({
'change .settings__general-idle-minutes': 'changeIdleMinutes',
'change .settings__general-clipboard': 'changeClipboard',
'change .settings__general-auto-save': 'changeAutoSave',
'change .settings__general-auto-save-interval': 'changeAutoSaveInterval',
'change .settings__general-remember-key-files': 'changeRememberKeyFiles',
'change .settings__general-minimize': 'changeMinimize',
'change .settings__general-lock-on-minimize': 'changeLockOnMinimize',
@ -74,10 +75,12 @@ const SettingsGeneralView = Backbone.View.extend({
rememberKeyFiles: AppSettingsModel.instance.get('rememberKeyFiles'),
supportFiles: !!Launcher,
autoSave: AppSettingsModel.instance.get('autoSave'),
autoSaveInterval: AppSettingsModel.instance.get('autoSaveInterval'),
idleMinutes: AppSettingsModel.instance.get('idleMinutes'),
minimizeOnClose: AppSettingsModel.instance.get('minimizeOnClose'),
devTools: Launcher && Launcher.devTools,
canAutoUpdate: Updater.enabled,
canAutoSaveOnClose: Launcher,
canMinimize: Launcher && Launcher.canMinimize(),
canDetectMinimize: !!Launcher,
canDetectOsSleep: Launcher && Launcher.canDetectOsSleep(),
@ -224,6 +227,11 @@ const SettingsGeneralView = Backbone.View.extend({
AppSettingsModel.instance.set('autoSave', autoSave);
},
changeAutoSaveInterval: function(e) {
const autoSaveInterval = Number(e.target.value) || 0;
AppSettingsModel.instance.set('autoSaveInterval', autoSaveInterval);
},
changeRememberKeyFiles: function(e) {
const rememberKeyFiles = e.target.value || false;
AppSettingsModel.instance.set('rememberKeyFiles', rememberKeyFiles);

View File

@ -90,10 +90,29 @@
</div>
<h2>{{res 'setGenFunction'}}</h2>
{{#if canAutoSaveOnClose}}
<div>
<input type="checkbox" class="settings__input input-base settings__general-auto-save" id="settings__general-auto-save"
{{#if autoSave}}checked{{/if}} />
<label for="settings__general-auto-save">{{res 'setGenAutoSync'}}</label>
<label for="settings__general-auto-save">{{res 'setGenAutoSyncOnClose'}}</label>
</div>
{{/if}}
<div>
<label for="settings__general-auto-save-interval">{{res 'setGenAutoSyncTimer'}}</label>
<select class="settings__select input-base settings__general-auto-save-interval"
id="settings__general-auto-save-interval">
<option value="0" {{#ifeq autoSaveInterval 0}}selected{{/ifeq}}>{{res 'setGenAutoSyncTimerOff'}}</option>
<option value="1" {{#ifeq autoSaveInterval 1}}selected{{/ifeq}}>{{#res 'setGenAutoSyncTimerInterval'}}
1{{/res}}</option>
<option value="5" {{#ifeq autoSaveInterval 5}}selected{{/ifeq}}>{{#res 'setGenAutoSyncTimerInterval'}}
5{{/res}}</option>
<option value="15" {{#ifeq autoSaveInterval 15}}selected{{/ifeq}}>{{#res 'setGenAutoSyncTimerInterval'}}
15{{/res}}</option>
<option value="30" {{#ifeq autoSaveInterval 30}}selected{{/ifeq}}>{{#res 'setGenAutoSyncTimerInterval'}}
30{{/res}}</option>
<option value="60" {{#ifeq autoSaveInterval 60}}selected{{/ifeq}}>{{#res 'setGenAutoSyncTimerInterval'}}
60{{/res}}</option>
</select>
</div>
<div>
<label for="settings__general-remember-key-files">{{res 'setGenRememberKeyFiles'}}:</label>