1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-01-08 13:06:15 +02:00

Android: Fixed sharing items from Joplin ()

Ref: https://discourse.joplinapp.org/t/android-lost-access-to-resources/15716/4
This commit is contained in:
Roman Musin 2021-04-07 18:41:54 +01:00 committed by GitHub
parent 015aec503e
commit e3efe70bab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 3646 additions and 30 deletions

View File

@ -748,6 +748,9 @@ packages/app-mobile/setUpQuickActions.js.map
packages/app-mobile/utils/ShareExtension.d.ts
packages/app-mobile/utils/ShareExtension.js
packages/app-mobile/utils/ShareExtension.js.map
packages/app-mobile/utils/ShareUtils.d.ts
packages/app-mobile/utils/ShareUtils.js
packages/app-mobile/utils/ShareUtils.js.map
packages/app-mobile/utils/checkPermissions.d.ts
packages/app-mobile/utils/checkPermissions.js
packages/app-mobile/utils/checkPermissions.js.map

3
.gitignore vendored
View File

@ -735,6 +735,9 @@ packages/app-mobile/setUpQuickActions.js.map
packages/app-mobile/utils/ShareExtension.d.ts
packages/app-mobile/utils/ShareExtension.js
packages/app-mobile/utils/ShareExtension.js.map
packages/app-mobile/utils/ShareUtils.d.ts
packages/app-mobile/utils/ShareUtils.js
packages/app-mobile/utils/ShareUtils.js.map
packages/app-mobile/utils/checkPermissions.d.ts
packages/app-mobile/utils/checkPermissions.js
packages/app-mobile/utils/checkPermissions.js.map

View File

@ -1,12 +1,11 @@
import { useCallback } from 'react';
import Setting from '@joplin/lib/models/Setting';
import shim from '@joplin/lib/shim';
const { ToastAndroid } = require('react-native');
const { _ } = require('@joplin/lib/locale.js');
import { reg } from '@joplin/lib/registry';
const { dialogs } = require('../../../utils/dialogs.js');
import Resource from '@joplin/lib/models/Resource';
import { copyToCache } from '../../../utils/ShareUtils';
const Share = require('react-native-share').default;
export default function useOnResourceLongPress(onJoplinLinkClick: Function, dialogBoxRef: any) {
@ -24,21 +23,14 @@ export default function useOnResourceLongPress(onJoplinLinkClick: Function, dial
if (action === 'open') {
onJoplinLinkClick(`joplin://${resourceId}`);
} else if (action === 'share') {
const filename = resource.file_name ?
`${resource.file_name}.${resource.file_extension}` :
resource.title;
const targetPath = `${Setting.value('resourceDir')}/${filename}`;
await shim.fsDriver().copy(Resource.fullPath(resource), targetPath);
const fileToShare = await copyToCache(resource);
await Share.open({
type: resource.mime,
filename: resource.title,
url: `file://${targetPath}`,
url: `file://${fileToShare}`,
failOnCancel: false,
});
await shim.fsDriver().remove(targetPath);
}
} catch (e) {
reg.logger().error('Could not handle link long press', e);

File diff suppressed because it is too large Load Diff

View File

@ -44,7 +44,7 @@
"react-native-popup-menu": "^0.10.0",
"react-native-quick-actions": "^0.3.13",
"react-native-securerandom": "^1.0.0-rc.0",
"react-native-share": "^5.1.3",
"react-native-share": "^5.1.5",
"react-native-side-menu": "^1.1.3",
"react-native-sqlite-storage": "^5.0.0",
"react-native-vector-icons": "^7.1.0",

View File

@ -95,6 +95,7 @@ import FsDriverRN from './utils/fs-driver-rn';
import DecryptionWorker from '@joplin/lib/services/DecryptionWorker';
import EncryptionService from '@joplin/lib/services/EncryptionService';
import MigrationService from '@joplin/lib/services/MigrationService';
import { clearSharedFilesCache } from './utils/ShareUtils';
let storeDispatch = function(_action: any) {};
@ -564,6 +565,8 @@ async function initialize(dispatch: Function) {
folderId: folder.id,
});
}
await clearSharedFilesCache();
} catch (error) {
alert(`Initialization error: ${error.message}`);
reg.logger().error('Initialization error:', error);

View File

@ -0,0 +1,29 @@
import Resource from '@joplin/lib/models/Resource';
import { ResourceEntity } from '@joplin/lib/services/database/types';
import shim from '@joplin/lib/shim';
import { CachesDirectoryPath } from 'react-native-fs';
const DIR_NAME = 'sharedFiles';
/**
* Copy a file to be shared to cache, renaming it to its orignal name
*/
export async function copyToCache(resource: ResourceEntity): Promise<string> {
const filename = Resource.friendlySafeFilename(resource);
const targetDir = `${CachesDirectoryPath}/${DIR_NAME}`;
await shim.fsDriver().mkdir(targetDir);
const targetFile = `${targetDir}/${filename}`;
await shim.fsDriver().copy(Resource.fullPath(resource), targetFile);
return targetFile;
}
/**
* Clear previously shared files from cache
*/
export async function clearSharedFilesCache(): Promise<void> {
return shim.fsDriver().remove(`${CachesDirectoryPath}/sharedFiles`);
}