Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea
.vscode
node_modules/
node_modules/
package-lock.json
3 changes: 2 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.idea
.vscode
references.d.ts
README.md
README.md
*.tgz
25 changes: 12 additions & 13 deletions email.android.js → index.android.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
var application = require("tns-core-modules/application");
var fs = require("tns-core-modules/file-system");
import { Application, File, Folder } from "@nativescript/core";

(function () {
_cleanAttachmentFolder();
Expand All @@ -8,12 +7,12 @@ var fs = require("tns-core-modules/file-system");
var _determineAvailability = function () {
var uri = android.net.Uri.fromParts("mailto", "", null);
var intent = new android.content.Intent(android.content.Intent.ACTION_SENDTO, uri);
var packageManager = application.android.context.getPackageManager();
var packageManager = Application.android.context.getPackageManager();
var nrOfMailApps = packageManager.queryIntentActivities(intent, 0).size();
return nrOfMailApps > 0;
};

exports.available = function () {
export function available() {
return new Promise(function (resolve, reject) {
try {
resolve(_determineAvailability());
Expand All @@ -24,7 +23,7 @@ exports.available = function () {
});
};

exports.compose = function (arg) {
export function compose(arg) {
return new Promise(function (resolve, reject) {
try {

Expand Down Expand Up @@ -63,7 +62,7 @@ exports.compose = function (arg) {
var attachment = arg.attachments[a];
var path = attachment.path;
var fileName = attachment.fileName;
var uri = _getUriForPath(path, fileName, application.android.context);
var uri = _getUriForPath(path, fileName, Application.android.context);

if (!uri) {
reject("File not found for path: " + path);
Expand All @@ -88,7 +87,7 @@ exports.compose = function (arg) {
mail.setFlags(android.content.Intent.FLAG_ACTIVITY_NEW_TASK);

// we can wire up an intent receiver but it's always the same resultCode (0, canceled) anyway
application.android.context.startActivity(mail);
Application.android.context.startActivity(mail);
resolve(true);
} catch (ex) {
console.log("Error in email.compose: " + ex);
Expand Down Expand Up @@ -126,12 +125,12 @@ function _getUriForAbsolutePath(path) {

function _getUriForAssetPath(path, fileName, ctx) {
path = path.replace("file://", "/");
if (!fs.File.exists(path)) {
if (!File.exists(path)) {
console.log("File does not exist: " + path);
return null;
}

var localFile = fs.File.fromPath(path);
var localFile = File.fromPath(path);
var localFileContents = localFile.readSync(function (e) {
error = e;
});
Expand Down Expand Up @@ -168,7 +167,7 @@ function _writeBytesToFile(ctx, fileName, contents) {
var storage = dir.toString() + "/emailcomposer";
var cacheFileName = storage + "/" + fileName;

var toFile = fs.File.fromPath(cacheFileName);
var toFile = File.fromPath(cacheFileName);
toFile.writeSync(contents, function (e) {
error = e;
});
Expand All @@ -181,16 +180,16 @@ function _writeBytesToFile(ctx, fileName, contents) {

function _cleanAttachmentFolder() {

if (application.android.context) {
var dir = application.android.context.getExternalCacheDir();
if (Application.android.context) {
var dir = Application.android.context.getExternalCacheDir();

if (dir === null) {
console.log("Missing external cache dir");
return;
}

var storage = dir.toString() + "/emailcomposer";
var cacheFolder = fs.Folder.fromPath(storage);
var cacheFolder = Folder.fromPath(storage);
cacheFolder.clear();
}
}
Expand Down
9 changes: 4 additions & 5 deletions email.ios.js → index.ios.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
var fs = require("tns-core-modules/file-system");
var frame = require("tns-core-modules/ui/frame");
import { File, Frame } from "@nativescript/core";

var _determineAvailability = function () {
var isSimulator = NSProcessInfo.processInfo.environment.objectForKey("SIMULATOR_DEVICE_NAME") !== null;
Expand All @@ -11,7 +10,7 @@ var _determineAvailability = function () {
return !isSimulator && MFMailComposeViewController.canSendMail();
};

exports.available = function () {
export function available() {
return new Promise(function (resolve, reject) {
try {
resolve(_determineAvailability());
Expand All @@ -22,7 +21,7 @@ exports.available = function () {
});
};

exports.compose = function (arg) {
export function compose(arg) {
return new Promise(function (resolve, reject) {
try {

Expand All @@ -31,7 +30,7 @@ exports.compose = function (arg) {
return;
}

var topMostFrame = frame.topmost();
var topMostFrame = Frame.topmost();
if (topMostFrame) {
var viewController = topMostFrame.currentPage && topMostFrame.currentPage.ios;
if (viewController) {
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "nativescript-email",
"version": "1.6.0",
"name": "@nativescript/email",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧐🤔

"version": "2.0.0",
"description": "Email plugin for your NativeScript app",
"main": "email",
"main": "index",
"typings": "index.d.ts",
"nativescript": {
"platforms": {
Expand Down Expand Up @@ -34,8 +34,8 @@
}
],
"devDependencies": {
"tns-core-modules": "^6.0.4",
"tns-platform-declarations": "~6.0.4"
"@nativescript/core": "rc",
"@nativescript/types": "rc"
},
"license": "MIT",
"bugs": "https://github.com/eddyverbruggen/nativescript-email/issues",
Expand Down
4 changes: 2 additions & 2 deletions references.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
/// <reference path="./node_modules/tns-platform-declarations/ios.d.ts" />
/// <reference path="./node_modules/tns-platform-declarations/android.d.ts" />
/// <reference path="./node_modules/@nativescript/types/ios.d.ts" />
/// <reference path="./node_modules/@nativescript/types/android.d.ts" />