Merge pull request #24 from Gillardo/master

Added support for WP8
This commit is contained in:
pwlin 2015-04-28 23:43:26 +02:00
commit 19ea102579
2 changed files with 55 additions and 0 deletions

View File

@ -37,4 +37,13 @@
<header-file src="src/ios/FileOpener2.h" />
</platform>
<!-- WP8 -->
<platform name="wp8">
<config-file target="config.xml" parent="/*">
<feature name="FileOpener2">
<param name="wp-package" value="FileOpener2" />
</feature>
</config-file>
<source-file src="src/wp8/FileOpener2.cs" />
</platform>
</plugin>

46
src/wp8/FileOpener2.cs Normal file
View File

@ -0,0 +1,46 @@
using System;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using Microsoft.Phone.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Media;
using Windows.Storage;
using System.Diagnostics;
using System.IO;
namespace WPCordovaClassLib.Cordova.Commands
{
public class FileOpener2 : BaseCommand
{
public async void open(string options)
{
string[] args = JSON.JsonHelper.Deserialize<string[]>(options);
var fileName = System.IO.Path.GetFileName(args[0]);
string aliasCurrentCommandCallbackId = args[2];
try
{
// Access isolated storage.
StorageFolder local = Windows.Storage.ApplicationData.Current.LocalFolder;
// Access the file.
StorageFile file = await local.GetFileAsync(fileName);
// Launch the bug query file.
await Windows.System.Launcher.LaunchFileAsync(file);
DispatchCommandResult(new PluginResult(PluginResult.Status.OK), aliasCurrentCommandCallbackId);
}
catch (FileNotFoundException)
{
DispatchCommandResult(new PluginResult(PluginResult.Status.IO_EXCEPTION), aliasCurrentCommandCallbackId);
}
catch (Exception)
{
DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR), aliasCurrentCommandCallbackId);
}
}
}
}