1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-11-27 08:21:03 +02:00

Electron: fixed loading of resources, and disable drag and dropping of links in app

This commit is contained in:
Laurent Cozic 2017-11-21 19:31:21 +00:00
parent f5feb595f6
commit 367a18db93
4 changed files with 23 additions and 2 deletions

View File

@ -59,7 +59,10 @@ class NoteTextComponent extends React.Component {
mdToHtml() {
if (this.mdToHtml_) return this.mdToHtml_;
this.mdToHtml_ = new MdToHtml({ supportsResourceLinks: true });
this.mdToHtml_ = new MdToHtml({
supportsResourceLinks: true,
resourceBaseUrl: 'file://' + Setting.value('resourceDir') + '/',
});
return this.mdToHtml_;
}

View File

@ -9,5 +9,12 @@
<body>
<div id="react-root"></div>
<script src="main-html.js"></script>
<style>
/* Disable dragging of links (which are often buttons) */
a:not([draggable=true]), img:not([draggable=true]) {
-webkit-user-drag: none;
user-drag: none;
}
</style>
</body>
</html>

View File

@ -31,6 +31,13 @@ BaseItem.loadClass('NoteTag', NoteTag);
Setting.setConstant('appId', 'net.cozic.joplin-desktop');
Setting.setConstant('appType', 'desktop');
// Disable drag and drop of links inside application (which would
// open it as if the whole app was a browser)
document.addEventListener('dragover', event => event.preventDefault());
document.addEventListener('drop', event => event.preventDefault());
// Disable middle-click (which would open a new browser window, but we don't want this)
document.addEventListener('auxclick', event => event.preventDefault());
shimInit();
app().start(bridge().processArgv()).then(() => {

View File

@ -14,6 +14,9 @@ class MdToHtml {
this.loadedResources_ = {};
this.cachedContent_ = null;
this.cachedContentKey_ = null;
// Must include last "/"
this.resourceBaseUrl_ = ('resourceBaseUrl' in options) ? options.resourceBaseUrl : null;
}
makeContentKey(resources, body, style, options) {
@ -100,7 +103,8 @@ class MdToHtml {
const mime = resource.mime ? resource.mime.toLowerCase() : '';
if (mime == 'image/png' || mime == 'image/jpg' || mime == 'image/jpeg' || mime == 'image/gif') {
const src = './' + Resource.filename(resource);
let src = './' + Resource.filename(resource);
if (this.resourceBaseUrl_ !== null) src = this.resourceBaseUrl_ + src;
let output = '<img title="' + htmlentities(title) + '" src="' + src + '"/>';
return output;
}