mirror of
https://github.com/zadam/trilium.git
synced 2025-11-06 05:15:59 +01:00
attachment download now works also in electron, added option to open the attachment
This commit is contained in:
@@ -18,6 +18,7 @@ const noteEditor = (function() {
|
||||
const $attachmentFileType = $("#attachment-filetype");
|
||||
const $attachmentFileSize = $("#attachment-filesize");
|
||||
const $attachmentDownload = $("#attachment-download");
|
||||
const $attachmentOpen = $("#attachment-open");
|
||||
|
||||
let editor = null;
|
||||
let codeEditor = null;
|
||||
@@ -271,9 +272,37 @@ const noteEditor = (function() {
|
||||
}
|
||||
|
||||
$attachmentDownload.click(() => {
|
||||
window.location.href = "/api/attachments/download/" + getCurrentNoteId();
|
||||
if (isElectron()) {
|
||||
const remote = require('electron').remote;
|
||||
|
||||
remote.getCurrentWebContents().downloadURL(getAttachmentUrl());
|
||||
}
|
||||
else {
|
||||
window.location.href = getAttachmentUrl();
|
||||
}
|
||||
});
|
||||
|
||||
$attachmentOpen.click(() => {
|
||||
if (isElectron()) {
|
||||
const open = require("open");
|
||||
|
||||
open(getAttachmentUrl());
|
||||
}
|
||||
else {
|
||||
window.location.href = getAttachmentUrl();
|
||||
}
|
||||
});
|
||||
|
||||
function getAttachmentUrl() {
|
||||
// electron needs absolute URL so we extract current host, port, protocol
|
||||
const url = new URL(window.location.href);
|
||||
const host = url.protocol + "//" + url.hostname + ":" + url.port;
|
||||
|
||||
const downloadUrl = "/api/attachments/download/" + getCurrentNoteId();
|
||||
|
||||
return host + downloadUrl;
|
||||
}
|
||||
|
||||
$(document).ready(() => {
|
||||
$noteTitle.on('input', () => {
|
||||
noteChanged();
|
||||
|
||||
Reference in New Issue
Block a user