mirror of
https://github.com/laurent22/joplin.git
synced 2025-01-08 13:06:15 +02:00
Android: Fixed sharing items from Joplin (#4718)
Ref: https://discourse.joplinapp.org/t/android-lost-access-to-resources/15716/4
This commit is contained in:
parent
015aec503e
commit
e3efe70bab
@ -748,6 +748,9 @@ packages/app-mobile/setUpQuickActions.js.map
|
|||||||
packages/app-mobile/utils/ShareExtension.d.ts
|
packages/app-mobile/utils/ShareExtension.d.ts
|
||||||
packages/app-mobile/utils/ShareExtension.js
|
packages/app-mobile/utils/ShareExtension.js
|
||||||
packages/app-mobile/utils/ShareExtension.js.map
|
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.d.ts
|
||||||
packages/app-mobile/utils/checkPermissions.js
|
packages/app-mobile/utils/checkPermissions.js
|
||||||
packages/app-mobile/utils/checkPermissions.js.map
|
packages/app-mobile/utils/checkPermissions.js.map
|
||||||
|
3
.gitignore
vendored
3
.gitignore
vendored
@ -735,6 +735,9 @@ packages/app-mobile/setUpQuickActions.js.map
|
|||||||
packages/app-mobile/utils/ShareExtension.d.ts
|
packages/app-mobile/utils/ShareExtension.d.ts
|
||||||
packages/app-mobile/utils/ShareExtension.js
|
packages/app-mobile/utils/ShareExtension.js
|
||||||
packages/app-mobile/utils/ShareExtension.js.map
|
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.d.ts
|
||||||
packages/app-mobile/utils/checkPermissions.js
|
packages/app-mobile/utils/checkPermissions.js
|
||||||
packages/app-mobile/utils/checkPermissions.js.map
|
packages/app-mobile/utils/checkPermissions.js.map
|
||||||
|
@ -1,12 +1,11 @@
|
|||||||
import { useCallback } from 'react';
|
import { useCallback } from 'react';
|
||||||
import Setting from '@joplin/lib/models/Setting';
|
|
||||||
import shim from '@joplin/lib/shim';
|
|
||||||
|
|
||||||
const { ToastAndroid } = require('react-native');
|
const { ToastAndroid } = require('react-native');
|
||||||
const { _ } = require('@joplin/lib/locale.js');
|
const { _ } = require('@joplin/lib/locale.js');
|
||||||
import { reg } from '@joplin/lib/registry';
|
import { reg } from '@joplin/lib/registry';
|
||||||
const { dialogs } = require('../../../utils/dialogs.js');
|
const { dialogs } = require('../../../utils/dialogs.js');
|
||||||
import Resource from '@joplin/lib/models/Resource';
|
import Resource from '@joplin/lib/models/Resource';
|
||||||
|
import { copyToCache } from '../../../utils/ShareUtils';
|
||||||
const Share = require('react-native-share').default;
|
const Share = require('react-native-share').default;
|
||||||
|
|
||||||
export default function useOnResourceLongPress(onJoplinLinkClick: Function, dialogBoxRef: any) {
|
export default function useOnResourceLongPress(onJoplinLinkClick: Function, dialogBoxRef: any) {
|
||||||
@ -24,21 +23,14 @@ export default function useOnResourceLongPress(onJoplinLinkClick: Function, dial
|
|||||||
if (action === 'open') {
|
if (action === 'open') {
|
||||||
onJoplinLinkClick(`joplin://${resourceId}`);
|
onJoplinLinkClick(`joplin://${resourceId}`);
|
||||||
} else if (action === 'share') {
|
} else if (action === 'share') {
|
||||||
const filename = resource.file_name ?
|
const fileToShare = await copyToCache(resource);
|
||||||
`${resource.file_name}.${resource.file_extension}` :
|
|
||||||
resource.title;
|
|
||||||
const targetPath = `${Setting.value('resourceDir')}/${filename}`;
|
|
||||||
|
|
||||||
await shim.fsDriver().copy(Resource.fullPath(resource), targetPath);
|
|
||||||
|
|
||||||
await Share.open({
|
await Share.open({
|
||||||
type: resource.mime,
|
type: resource.mime,
|
||||||
filename: resource.title,
|
filename: resource.title,
|
||||||
url: `file://${targetPath}`,
|
url: `file://${fileToShare}`,
|
||||||
failOnCancel: false,
|
failOnCancel: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
await shim.fsDriver().remove(targetPath);
|
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
reg.logger().error('Could not handle link long press', e);
|
reg.logger().error('Could not handle link long press', e);
|
||||||
|
3622
packages/app-mobile/package-lock.json
generated
3622
packages/app-mobile/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -44,7 +44,7 @@
|
|||||||
"react-native-popup-menu": "^0.10.0",
|
"react-native-popup-menu": "^0.10.0",
|
||||||
"react-native-quick-actions": "^0.3.13",
|
"react-native-quick-actions": "^0.3.13",
|
||||||
"react-native-securerandom": "^1.0.0-rc.0",
|
"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-side-menu": "^1.1.3",
|
||||||
"react-native-sqlite-storage": "^5.0.0",
|
"react-native-sqlite-storage": "^5.0.0",
|
||||||
"react-native-vector-icons": "^7.1.0",
|
"react-native-vector-icons": "^7.1.0",
|
||||||
|
@ -95,6 +95,7 @@ import FsDriverRN from './utils/fs-driver-rn';
|
|||||||
import DecryptionWorker from '@joplin/lib/services/DecryptionWorker';
|
import DecryptionWorker from '@joplin/lib/services/DecryptionWorker';
|
||||||
import EncryptionService from '@joplin/lib/services/EncryptionService';
|
import EncryptionService from '@joplin/lib/services/EncryptionService';
|
||||||
import MigrationService from '@joplin/lib/services/MigrationService';
|
import MigrationService from '@joplin/lib/services/MigrationService';
|
||||||
|
import { clearSharedFilesCache } from './utils/ShareUtils';
|
||||||
|
|
||||||
let storeDispatch = function(_action: any) {};
|
let storeDispatch = function(_action: any) {};
|
||||||
|
|
||||||
@ -564,6 +565,8 @@ async function initialize(dispatch: Function) {
|
|||||||
folderId: folder.id,
|
folderId: folder.id,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await clearSharedFilesCache();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
alert(`Initialization error: ${error.message}`);
|
alert(`Initialization error: ${error.message}`);
|
||||||
reg.logger().error('Initialization error:', error);
|
reg.logger().error('Initialization error:', error);
|
||||||
|
29
packages/app-mobile/utils/ShareUtils.ts
Normal file
29
packages/app-mobile/utils/ShareUtils.ts
Normal 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`);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user