1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-08-24 20:19:10 +02:00

Compare commits

...

14 Commits

Author SHA1 Message Date
Laurent Cozic
c6ff42f374 Update shim-init-node.js 2023-08-08 15:48:31 +01:00
Laurent Cozic
a25117c41a Update Note.tsx 2023-08-08 15:47:51 +01:00
Laurent Cozic
6131d1ffd2 Update shim-init-node.js 2023-08-08 15:47:01 +01:00
Laurent Cozic
6dea4b8261 Update Note.tsx 2023-08-08 15:46:04 +01:00
Hubert
94b3de1370 Split message in two lines. 2023-08-04 17:40:54 -03:00
Hubert
cca501d819 Merge remote-tracking branch 'origin/dev' into issue-8566 2023-08-04 17:30:11 -03:00
Hubert
6fe33f3435 Label updated. 2023-08-02 16:09:37 -03:00
Hubert
4d05cc7595 Merge remote-tracking branch 'origin/dev' into issue-8566 2023-08-02 16:08:13 -03:00
Hubert
30471d591a Modifications in the mobile app to support the choice of the user from menu. 2023-07-31 14:37:43 -03:00
Hubert
c997a7e480 Merge remote-tracking branch 'origin/dev' into issue-8566 2023-07-31 13:02:22 -03:00
Hubert
7ed133d960 Changes from review. 2023-07-31 12:03:10 -03:00
Hubert
c252937852 Update packages/lib/models/Setting.ts
Co-authored-by: Henry Heino <46334387+personalizedrefrigerator@users.noreply.github.com>
2023-07-30 10:30:58 -03:00
Hubert
a9c919fe59 Removed the changes in the indentation. The code isn't related to my changes. 2023-07-28 16:51:13 -03:00
Hubert
772baf1e84 Added the option under note's menu that allowed the users to decide what to do when attaching some large image file to some note. 2023-07-28 16:34:14 -03:00
4 changed files with 73 additions and 50 deletions

View File

@@ -78,7 +78,7 @@ export async function commandAttachFileToBody(body: string, filePaths: string[]
logger.info(`Attaching ${filePath}`);
const newBody = await shim.attachFileToNoteBody(body, filePath, options.position, {
createFileURL: options.createFileURL,
resizeLargeImages: 'ask',
resizeLargeImages: Setting.value('imageResizing'),
});
if (!newBody) {

View File

@@ -572,29 +572,16 @@ class NoteScreenComponent extends BaseScreenComponent {
public async resizeImage(localFilePath: string, targetPath: string, mimeType: string) {
const maxSize = Resource.IMAGE_MAX_DIMENSION;
const dimensions: any = await this.imageDimensions(localFilePath);
reg.logger().info('Original dimensions ', dimensions);
let mustResize = dimensions.width > maxSize || dimensions.height > maxSize;
if (mustResize) {
const buttonId = await dialogs.pop(this, _('You are about to attach a large image (%dx%d pixels). Would you like to resize it down to %d pixels before attaching it?', dimensions.width, dimensions.height, maxSize), [
{ text: _('Yes'), id: 'yes' },
{ text: _('No'), id: 'no' },
{ text: _('Cancel'), id: 'cancel' },
]);
if (buttonId === 'cancel') return false;
mustResize = buttonId === 'yes';
}
if (mustResize) {
const saveOriginalImage = async () => {
await shim.fsDriver().copy(localFilePath, targetPath);
return true;
};
const saveResizedImage = async () => {
dimensions.width = maxSize;
dimensions.height = maxSize;
reg.logger().info('New dimensions ', dimensions);
const format = mimeType === 'image/png' ? 'PNG' : 'JPEG';
@@ -612,11 +599,27 @@ class NoteScreenComponent extends BaseScreenComponent {
} catch (error) {
reg.logger().warn('Error when unlinking cached file: ', error);
}
} else {
await shim.fsDriver().copy(localFilePath, targetPath);
return true;
};
const canResize = dimensions.width > maxSize || dimensions.height > maxSize;
if (canResize) {
const resizeLargeImages = Setting.value('imageResizing');
if (resizeLargeImages === 'alwaysAsk') {
const userAnswer = await dialogs.pop(this, `${_('You are about to attach a large image (%dx%d pixels). Would you like to resize it down to %d pixels before attaching it?', dimensions.width, dimensions.height, maxSize)}\n\n${_('(You may disable this prompt in the options)')}`, [
{ text: _('Yes'), id: 'yes' },
{ text: _('No'), id: 'no' },
{ text: _('Cancel'), id: 'cancel' },
]);
if (userAnswer === 'yes') return await saveResizedImage();
if (userAnswer === 'no') return await saveOriginalImage();
if (userAnswer === 'cancel') return false;
} else if (resizeLargeImages === 'alwaysResize') {
return await saveResizedImage();
}
}
return true;
return await saveOriginalImage();
}
public async attachFile(pickerResponse: any, fileType: string) {

View File

@@ -1121,7 +1121,25 @@ class Setting extends BaseModel {
storage: SettingStorage.File,
isGlobal: true,
},
imageResizing: {
value: 'alwaysAsk',
type: SettingItemType.String,
section: 'note',
isEnum: true,
public: true,
appTypes: [AppType.Mobile, AppType.Desktop],
label: () => _('Resize large images:'),
description: () => _('Shrink large images before adding them to notes to save storage space.'),
options: () => {
return {
alwaysAsk: _('Always ask'),
alwaysResize: _('Always resize'),
neverResize: _('Never resize'),
};
},
storage: SettingStorage.File,
isGlobal: true,
},
'plugins.states': {
value: '',
type: SettingItemType.Object,

View File

@@ -184,38 +184,42 @@ function shimInit(options = null) {
if (shim.isElectron()) {
// For Electron
const nativeImage = require('electron').nativeImage;
let image = nativeImage.createFromPath(filePath);
const image = nativeImage.createFromPath(filePath);
if (image.isEmpty()) throw new Error(`Image is invalid or does not exist: ${filePath}`);
const size = image.getSize();
let mustResize = size.width > maxDim || size.height > maxDim;
if (mustResize && resizeLargeImages === 'ask') {
const answer = shim.showMessageBox(_('You are about to attach a large image (%dx%d pixels). Would you like to resize it down to %d pixels before attaching it?', size.width, size.height, maxDim), {
buttons: [_('Yes'), _('No'), _('Cancel')],
});
if (answer === 2) return false;
mustResize = answer === 0;
}
if (!mustResize) {
const saveOriginalImage = async () => {
await shim.fsDriver().copy(filePath, targetPath);
return true;
};
const saveResizedImage = async () => {
const options = {};
if (size.width > size.height) {
options.width = maxDim;
} else {
options.height = maxDim;
}
const resizedImage = image.resize(options);
await shim.writeImageToFile(resizedImage, mime, targetPath);
return true;
};
const canResize = size.width > maxDim || size.height > maxDim;
if (canResize) {
if (resizeLargeImages === 'alwaysAsk') {
const Yes = 0, No = 1, Cancel = 2;
const userAnswer = shim.showMessageBox(`${_('You are about to attach a large image (%dx%d pixels). Would you like to resize it down to %d pixels before attaching it?', size.width, size.height, maxDim)}\n\n${_('(You may disable this prompt in the options)')}`, {
buttons: [_('Yes'), _('No'), _('Cancel')],
});
if (userAnswer === Yes) return await saveResizedImage();
if (userAnswer === No) return await saveOriginalImage();
if (userAnswer === Cancel) return false;
} else if (resizeLargeImages === 'alwaysResize') {
return await saveResizedImage();
}
}
const options = {};
if (size.width > size.height) {
options.width = maxDim;
} else {
options.height = maxDim;
}
image = image.resize(options);
await shim.writeImageToFile(image, mime, targetPath);
return await saveOriginalImage();
} else {
// For the CLI tool
const image = sharp(filePath);
@@ -241,8 +245,6 @@ function shimInit(options = null) {
});
});
}
return true;
};
// This is a bit of an ugly method that's used to both create a new resource