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

Desktop: Fixes #1425: Improved handling of images when using external editor, so that it works in Atom, VSCode and Typora

This commit is contained in:
Laurent Cozic 2019-05-11 11:46:13 +01:00
parent 91ecab51c5
commit b702b0b40c
7 changed files with 36 additions and 16 deletions

View File

@ -511,11 +511,13 @@ class BaseApplication {
Setting.setConstant('appName', appName);
const profileDir = this.determineProfileDir(initArgs);
const resourceDir = profileDir + '/resources';
const resourceDirName = 'resources';
const resourceDir = profileDir + '/' + resourceDirName;
const tempDir = profileDir + '/tmp';
Setting.setConstant('env', initArgs.env);
Setting.setConstant('profileDir', profileDir);
Setting.setConstant('resourceDirName', resourceDirName);
Setting.setConstant('resourceDir', resourceDir);
Setting.setConstant('tempDir', tempDir);
@ -525,6 +527,9 @@ class BaseApplication {
await fs.mkdirp(resourceDir, 0o755);
await fs.mkdirp(tempDir, 0o755);
// Clean up any remaining watched files (they start with "edit-")
await shim.fsDriver().removeAllThatStartWith(profileDir, 'edit-');
const extraFlags = await this.readFlagsFromFile(profileDir + '/flags.txt');
initArgs = Object.assign(initArgs, extraFlags);

View File

@ -38,6 +38,18 @@ class FsDriverBase {
}
}
async removeAllThatStartWith(dirPath, filenameStart) {
if (!filenameStart || !dirPath) throw new Error('dirPath and filenameStart cannot be empty');
const stats = await this.readDirStats(dirPath);
for (const stat of stats) {
if (stat.path.indexOf(filenameStart) === 0) {
await this.remove(dirPath + '/' + stat.path);
}
}
}
}
module.exports = FsDriverBase;

View File

@ -177,14 +177,15 @@ class Note extends BaseItem {
const id = resourceIds[i];
const resource = await Resource.load(id);
if (!resource) continue;
body = body.replace(new RegExp(':/' + id, 'gi'), toFileProtocolPath(Resource.fullPath(resource)));
const resourcePath = Resource.relativePath(resource)
body = body.replace(new RegExp(':/' + id, 'gi'), resourcePath); //toFileProtocolPath(Resource.fullPath(resource)));
}
return body;
}
static async replaceResourceExternalToInternalLinks(body) {
const reString = pregQuote(toFileProtocolPath(Resource.baseDirectoryPath() + '/')) + '[a-zA-Z0-9\.]+';
const reString = pregQuote(toFileProtocolPath(Resource.baseRelativeDirectoryPath() + '/')) + '[a-zA-Z0-9\.]+';
const re = new RegExp(reString, 'gi');
body = body.replace(re, (match) => {
const id = Resource.pathToId(match);

View File

@ -71,6 +71,14 @@ class Resource extends BaseItem {
return Setting.value('resourceDir');
}
static baseRelativeDirectoryPath() {
return Setting.value('resourceDirName');
}
static relativePath(resource, encryptedBlob = false) {
return Setting.value('resourceDirName') + '/' + this.filename(resource, encryptedBlob);
}
static fullPath(resource, encryptedBlob = false) {
return Setting.value('resourceDir') + '/' + this.filename(resource, encryptedBlob);
}

View File

@ -633,6 +633,7 @@ Setting.constants_ = {
appName: 'joplin',
appId: 'SET_ME', // Each app should set this identifier
appType: 'SET_ME', // 'cli' or 'mobile'
resourceDirName: '',
resourceDir: '',
profileDir: '',
tempDir: '',

View File

@ -26,6 +26,10 @@ class ExternalEditWatcher {
return this.instance_;
}
tempDir() {
return Setting.value('profileDir');
}
on(eventName, callback) {
return this.eventEmitter_.on(eventName, callback);
}
@ -109,7 +113,7 @@ class ExternalEditWatcher {
}
noteFilePath(noteId) {
return Setting.value('tempDir') + '/' + noteId + '.md';
return this.tempDir() + '/edit-' + noteId + '.md';
}
watchedFiles() {
@ -123,7 +127,7 @@ class ExternalEditWatcher {
for (let i = 0; i < watchedPaths[dirName].length; i++) {
const f = watchedPaths[dirName][i];
output.push(Setting.value('tempDir') + '/' + f);
output.push(this.tempDir() + '/' + f);
}
}

View File

@ -332,23 +332,12 @@ const appReducer = (state = appDefaultState, action) => {
let store = createStore(appReducer, applyMiddleware(generalMiddleware));
storeDispatch = store.dispatch;
// function blobTest() {
// const contentType = 'text/plain';
// var blob = new Blob(['aaaaaaaaaaa'], { type: contentType });
// const fileTest = new File([blob], '/storage/emulated/0/Download/test.txt', { type: contentType, lastModified: Date.now() });
// console.info('FFFFFFFFFFFFFFFFFFFFF', fileTest);
// }
async function initialize(dispatch) {
shimInit();
// blobTest();
Setting.setConstant('env', __DEV__ ? 'dev' : 'prod');
Setting.setConstant('appId', 'net.cozic.joplin-mobile');
Setting.setConstant('appType', 'mobile');
//Setting.setConstant('resourceDir', () => { return RNFetchBlob.fs.dirs.DocumentDir; });
Setting.setConstant('resourceDir', RNFetchBlob.fs.dirs.DocumentDir);
const logDatabase = new Database(new DatabaseDriverReactNative());