Skip to content

Commit

Permalink
add option to disable auto-download of images for offline storage, #2859
Browse files Browse the repository at this point in the history
  • Loading branch information
zadam committed May 21, 2022
1 parent 2085dc5 commit 819cf09
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 8 deletions.
24 changes: 21 additions & 3 deletions src/public/app/dialogs/options/other.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,13 @@ const TPL = `
</div>
<div>
<h4>Image compression</h4>
<h4>Images</h4>
<div class="form-group">
<input id="download-images-automatically" type="checkbox" name="download-images-automatically">
<label for="download-images-automatically">Download images automatically for offline use.</label>
<p>(pasted HTML can contain references to online images, Trilium will find those references and download the images so that they are available offline)</p>
</div>
<div class="form-group">
<input id="image-compresion-enabled" type="checkbox" name="image-compression-enabled">
Expand Down Expand Up @@ -216,6 +222,15 @@ export default class ProtectedSessionOptions {
return false;
});

this.$downloadImagesAutomatically = $("#download-images-automatically");

this.$downloadImagesAutomatically.on("change", () => {
const isChecked = this.$downloadImagesAutomatically.prop("checked");
const opts = { 'downloadImagesAutomatically': isChecked ? 'true' : 'false' };

server.put('options', opts).then(() => toastService.showMessage("Options changed have been saved."));
});

this.$enableImageCompression = $("#image-compresion-enabled");
this.$imageCompressionWrapper = $("#image-compression-enabled-wraper");

Expand All @@ -225,7 +240,7 @@ export default class ProtectedSessionOptions {
} else {
this.$imageCompressionWrapper.addClass("disabled-field");
}
}
};

this.$enableImageCompression.on("change", () => {
const isChecked = this.$enableImageCompression.prop("checked");
Expand All @@ -234,7 +249,7 @@ export default class ProtectedSessionOptions {
server.put('options', opts).then(() => toastService.showMessage("Options changed have been saved."));

this.setImageCompression(isChecked);
})
});
}

optionsLoaded(options) {
Expand All @@ -251,6 +266,9 @@ export default class ProtectedSessionOptions {
this.$autoReadonlySizeText.val(options['autoReadonlySizeText']);
this.$autoReadonlySizeCode.val(options['autoReadonlySizeCode']);

const downloadImagesAutomatically = options['downloadImagesAutomatically'] === 'true';
this.$downloadImagesAutomatically.prop('checked', downloadImagesAutomatically);

const compressImages = options['compressImages'] === 'true';
this.$enableImageCompression.prop('checked', compressImages);
this.setImageCompression(compressImages);
Expand Down
3 changes: 2 additions & 1 deletion src/routes/api/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ const ALLOWED_OPTIONS = new Set([
'weeklyBackupEnabled',
'monthlyBackupEnabled',
'maxContentWidth',
'compressImages'
'compressImages',
'downloadImagesAutomatically'
]);

function getOptions() {
Expand Down
4 changes: 4 additions & 0 deletions src/services/notes.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,10 @@ function replaceUrl(content, url, imageNote) {
}

function downloadImages(noteId, content) {
if (!optionService.getOptionBool("downloadImagesAutomatically")) {
return content;
}

const imageRe = /<img[^>]*?\ssrc=['"]([^'">]+)['"]/ig;
let imageMatch;

Expand Down
9 changes: 5 additions & 4 deletions src/services/options_init.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ function initNotSyncedOptions(initialized, opts = {}) {
optionService.createOption('lastSyncedPush', '0', false);

let theme = 'dark'; // default based on the poll in https://github.com/zadam/trilium/issues/2516

if (utils.isElectron()) {
const {nativeTheme} = require('electron');

theme = nativeTheme.shouldUseDarkColors ? 'dark' : 'light';
}

optionService.createOption('theme', theme, false);

optionService.createOption('syncServerHost', opts.syncServerHost || '', false);
Expand Down Expand Up @@ -83,7 +83,8 @@ const defaultOptions = [
{ name: 'weeklyBackupEnabled', value: 'true', isSynced: false },
{ name: 'monthlyBackupEnabled', value: 'true', isSynced: false },
{ name: 'maxContentWidth', value: '1200', isSynced: false },
{ name: 'compressImages', value: 'true', isSynced: true }
{ name: 'compressImages', value: 'true', isSynced: true },
{ name: 'downloadImagesAutomatically', value: 'true', isSynced: true }
];

function initStartupOptions() {
Expand Down

0 comments on commit 819cf09

Please sign in to comment.