Skip to content

Commit

Permalink
add web support(beta)
Browse files Browse the repository at this point in the history
  • Loading branch information
crazecoder committed Nov 7, 2019
1 parent df05487 commit 023cd12
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 8 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 2.1.0
* add web support(beta)
* add pc support(beta)
## 2.0.3
* change use FileProvider from Android M to Android N
## 2.0.2
* catch No Activity found to handle Intent exception
* Optimize request REQUEST_INSTALL_PACKAGES permission on Android O
Expand Down
3 changes: 2 additions & 1 deletion lib/open_file.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
library open_file;

export 'src/open_file.dart';
export 'src/plaform/open_file.dart'
if (dart.library.html) 'src/web/open_file.dart';
2 changes: 1 addition & 1 deletion lib/src/linux.dart → lib/src/plaform/linux.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ int system(String command) {

// Invoke the command, and free the pointer.
int result = systemP(cmdP);
cmdP.free();
// cmdP.free();

return result;
}
2 changes: 1 addition & 1 deletion lib/src/macos.dart → lib/src/plaform/macos.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ int system(String command) {

// Invoke the command, and free the pointer.
int result = systemP(cmdP);
cmdP.free();
// cmdP.free();

return result;
}
1 change: 0 additions & 1 deletion lib/src/open_file.dart → lib/src/plaform/open_file.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ class OpenFile {
{String type, String uti, String linuxDesktopName = "xdg"}) async {
if (!Platform.isIOS && !Platform.isAndroid) {
int _result;
//file or url
if (Platform.isMacOS) {
_result = mac.system('open $filePath');
} else if (Platform.isLinux) {
Expand Down
4 changes: 2 additions & 2 deletions lib/src/windows.dart → lib/src/plaform/windows.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ int ShellExecute(String operation, String file) {
// Invoke the command, and free the pointers.
var result = ShellExecuteP(
ffi.nullptr, operationP, fileP, ffi.nullptr, ffi.nullptr, SW_SHOWNORMAL);
operationP.free();
fileP.free();
// operationP.free();
// fileP.free();

return result;
}
9 changes: 9 additions & 0 deletions lib/src/web/open_file.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import 'dart:async';
import 'web.dart' as web;

class OpenFile {
static Future<String> open(String filePath) async {
bool _b = await web.open("file://$filePath");
return _b ? "done" : "there are some errors when open $filePath";
}
}
12 changes: 12 additions & 0 deletions lib/src/web/web.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import 'dart:async';
import 'dart:html';

Future<bool> open(String uri) async {
try{
Entry _e = await window.resolveLocalFileSystemUrl(uri);
return _e != null;
}catch (e){
print(e);
return false;
}
}
5 changes: 3 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
name: open_file
description: A plug-in that can call native APP to open files with string result in flutter,support iOS(UTI) and android(intent)
version: 2.0.2
version: 2.1.0
author: crazecoder <[email protected]>
homepage: https://github.com/crazecoder/open_file


dependencies:
flutter:
sdk: flutter
ffi: ^0.1.3

environment:
sdk: ">=2.0.0-dev.28.0 <3.0.0"
sdk: ">=2.1.0 <3.0.0"
# For information on the generic Dart part of this file, see the
# following page: https://www.dartlang.org/tools/pub/pubspec

Expand Down

0 comments on commit 023cd12

Please sign in to comment.