Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@nativescript-community/ui-share-file

Package Overview
Dependencies
Maintainers
12
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nativescript-community/ui-share-file - npm Package Compare versions

Comparing version 1.2.2 to 1.2.3

8

CHANGELOG.md

@@ -6,2 +6,10 @@ # Change Log

## [1.2.3](https://github.com/nativescript-community/ui-share-file/compare/v1.2.2...v1.2.3) (2021-06-03)
**Note:** Version bump only for package @nativescript-community/ui-share-file
## [1.2.2](https://github.com/nativescript-community/ui-share-file/compare/v1.2.1...v1.2.2) (2021-03-09)

@@ -8,0 +16,0 @@

2

index.d.ts

@@ -13,2 +13,4 @@ export interface ShareOptions {

type?: string;
// android only
dontGrantReadUri?: boolean;
}

@@ -15,0 +17,0 @@ export declare class ShareFile {

4

package.json
{
"name": "@nativescript-community/ui-share-file",
"version": "1.2.2",
"version": "1.2.3",
"description": "Send/share file to other apps.",

@@ -34,3 +34,3 @@ "main": "share-file",

"bootstrapper": "nativescript-plugin-seed",
"gitHead": "a4b376cdb1e5f427f2847aa1528623f8cc7e62e2"
"gitHead": "bf09f9c18a4f6001c8e41e811431c9dfefe738ff"
}

@@ -5,6 +5,6 @@ export declare class ShareFile {

fileName(filename: any): any;
_getUriForPath(path: any, fileName: any, ctx: any): globalAndroid.net.Uri;
_getUriForAbsolutePath(path: any): globalAndroid.net.Uri;
_getUriForAssetPath(path: any, fileName: any, ctx: any): globalAndroid.net.Uri;
_getUriForBase64Content(path: any, fileName: any, ctx: any): globalAndroid.net.Uri;
_getUriForPath(filePath: any, fileName: any, ctx: any): globalAndroid.net.Uri;
_getUriForAbsolutePath(filePath: any): globalAndroid.net.Uri;
_getUriForAssetPath(filePath: any, fileName: any, ctx: any): globalAndroid.net.Uri;
_getUriForBase64Content(filePath: any, fileName: any, ctx: any): globalAndroid.net.Uri;
_writeBytesToFile(ctx: any, fileName: any, contents: any): string;

@@ -11,0 +11,0 @@ _cleanAttachmentFolder(): void;

import { AndroidApplication, android as androidApp } from '@nativescript/core/application';
import { File, Folder } from '@nativescript/core/file-system';
import { File, Folder, path } from '@nativescript/core/file-system';
const REQUEST_CODE = 2343;

@@ -9,18 +9,23 @@ export class ShareFile {

try {
const path = args.path;
const intent = new android.content.Intent();
const map = android.webkit.MimeTypeMap.getSingleton();
const mimeType = map.getMimeTypeFromExtension(this.fileExtension(path));
intent.addFlags(android.content.Intent.FLAG_GRANT_READ_URI_PERMISSION);
const uri = this._getUriForPath(path, '/' + this.fileName(path), androidApp.context);
// uris.add(uri);
// const map = android.webkit.MimeTypeMap.getSingleton();
// const mimeType = map.getMimeTypeFromExtension(this.fileExtension(path));
if (args.dontGrantReadUri !== true) {
intent.addFlags(android.content.Intent.FLAG_GRANT_READ_URI_PERMISSION);
}
if (Array.isArray(args.path)) {
const uris = new java.util.ArrayList();
args.path.forEach((p) => uris.add(this._getUriForPath(p, this.fileName(p), androidApp.context)));
intent.putParcelableArrayListExtra(android.content.Intent.EXTRA_STREAM, uris);
intent.setAction(android.content.Intent.ACTION_SEND_MULTIPLE);
}
else {
const path = args.path;
const uri = this._getUriForPath(path, this.fileName(path), androidApp.context);
intent.putExtra(android.content.Intent.EXTRA_STREAM, uri);
intent.setAction(android.content.Intent.ACTION_SEND);
}
const builder = new android.os.StrictMode.VmPolicy.Builder();
android.os.StrictMode.setVmPolicy(builder.build());
intent.setAction(android.content.Intent.ACTION_SEND);
intent.setType((args === null || args === void 0 ? void 0 : args.type) || '*/*');
intent.putExtra(android.content.Intent.EXTRA_STREAM, uri);
// intent.putParcelableArrayListExtra(
// android.content.Intent.EXTRA_STREAM,
// uris
// );
const activity = androidApp.foregroundActivity || androidApp.startActivity;

@@ -34,8 +39,2 @@ const onActivityResultHandler = (data) => {

androidApp.on(AndroidApplication.activityResultEvent, onActivityResultHandler);
// activity.startActivityForResult(
// new android.content.Intent(
// android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS
// ),
// 0
// );
activity.startActivityForResult(android.content.Intent.createChooser(intent, args.title || 'Open file:'), REQUEST_CODE);

@@ -59,23 +58,30 @@ }

}
_getUriForPath(path, fileName, ctx) {
if (path.indexOf('file:///') === 0) {
return this._getUriForAbsolutePath(path);
_getUriForPath(filePath, fileName, ctx) {
try {
const file = new java.io.File(filePath);
return androidx.core.content.FileProvider.getUriForFile(androidApp.foregroundActivity || androidApp.startActivity, androidApp.packageName + '.provider', file);
}
else if (path.indexOf('file://') === 0) {
return this._getUriForAssetPath(path, fileName, ctx);
catch (err) {
console.error(err);
}
else if (path.indexOf('base64:') === 0) {
return this._getUriForBase64Content(path, fileName, ctx);
if (filePath.indexOf('file:///') === 0) {
return this._getUriForAbsolutePath(filePath);
}
else if (filePath.indexOf('file://') === 0) {
return this._getUriForAssetPath(filePath, fileName, ctx);
}
else if (filePath.indexOf('base64:') === 0) {
return this._getUriForBase64Content(filePath, fileName, ctx);
}
else {
if (path.indexOf(ctx.getPackageName()) > -1) {
return this._getUriForAssetPath(path, fileName, ctx);
if (filePath.startsWith('/data') && filePath.indexOf(ctx.getPackageName()) > -1) {
return this._getUriForAssetPath(filePath, fileName, ctx);
}
else {
return this._getUriForAbsolutePath(path);
return this._getUriForAbsolutePath(filePath);
}
}
}
_getUriForAbsolutePath(path) {
const absPath = path.replace('file://', '');
_getUriForAbsolutePath(filePath) {
const absPath = filePath.replace('file://', '');
const file = new java.io.File(absPath);

@@ -90,9 +96,9 @@ if (!file.exists()) {

}
_getUriForAssetPath(path, fileName, ctx) {
path = path.replace('file://', '/');
if (!File.exists(path)) {
console.log('File does not exist: ' + path);
_getUriForAssetPath(filePath, fileName, ctx) {
filePath = filePath.replace('file://', '/');
if (!File.exists(filePath)) {
console.log('File does not exist: ' + filePath);
return null;
}
const localFile = File.fromPath(path);
const localFile = File.fromPath(filePath);
const localFileContents = localFile.readSync(function (e) {

@@ -107,4 +113,4 @@ console.log(e);

}
_getUriForBase64Content(path, fileName, ctx) {
const resData = path.substring(path.indexOf('://') + 3);
_getUriForBase64Content(filePath, fileName, ctx) {
const resData = filePath.substring(filePath.indexOf('://') + 3);
let bytes;

@@ -127,4 +133,3 @@ try {

}
const storage = dir.toString() + '/filecomposer';
let cacheFileName = storage + '/' + fileName;
let cacheFileName = path.join(dir.toString(), 'filecomposer', fileName);
const toFile = File.fromPath(cacheFileName);

@@ -142,3 +147,3 @@ toFile.writeSync(contents, function (e) {

const dir = androidApp.context.getExternalCacheDir();
const storage = dir.toString() + '/filecomposer';
const storage = path.join(dir.toString(), 'filecomposer');
const cacheFolder = Folder.fromPath(storage);

@@ -145,0 +150,0 @@ cacheFolder.clear();

@@ -16,2 +16,18 @@ import { Application } from '@nativescript/core';

try {
if (Array.isArray(args.path)) {
// we only support one shared file for now
args.path = args.path[0];
// const activityController = UIActivityViewController.alloc().initWithActivityItemsApplicationActivities(thingsToShare, null);
// const presentViewController = activityController.popoverPresentationController;
// if (presentViewController) {
// const page = Frame.topmost().currentPage;
// if (page && page.ios.navigationItem.rightBarButtonItems && page.ios.navigationItem.rightBarButtonItems.count > 0) {
// presentViewController.barButtonItem = page.ios.navigationItem.rightBarButtonItems[0];
// } else {
// presentViewController.sourceView = page.ios.view;
// }
// }
// Utils.ios.getVisibleViewController(getRootViewController()).presentViewControllerAnimatedCompletion(activityController, true, null);
}
// else {
const appPath = this.getCurrentAppPath();

@@ -49,2 +65,3 @@ const path = args.path.replace('~', appPath);

this.resolve = resolve;
// }
}

@@ -51,0 +68,0 @@ catch (e) {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc