@hanwha-ss1/plugin 0.5.4 → 0.5.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,50 @@
1
+
2
+ import Foundation
3
+ import Capacitor
4
+
5
+ public class DownloadPlugin: CAPPlugin {
6
+
7
+ @objc public func doDownload(_ call: CAPPluginCall, _bridge: CAPBridgeProtocol) {
8
+ let body = call.getString("body") ?? ""
9
+
10
+ let aSplit = body.components(separatedBy: ";")
11
+
12
+ if aSplit.count > 2 {
13
+ let fileName = aSplit[0]
14
+ let sData1 = "\(aSplit[1])\(aSplit[2])"
15
+ let aData2 = sData1.components(separatedBy: ",")
16
+
17
+ if aData2.count > 1, let sData = aData2[1] {
18
+ if let data = Data(base64Encoded: sData, options: .ignoreUnknownCharacters) {
19
+ let paths = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
20
+ let documentsDirectory = paths[0]
21
+ let filePath = documentsDirectory.appendingPathComponent(fileName)
22
+
23
+ DispatchQueue.global(qos: .userInitiated).async {
24
+ do {
25
+ try data.write(to: filePath)
26
+ DispatchQueue.main.async {
27
+ call.resolve([
28
+ "result": true,
29
+ ])
30
+ }
31
+ } catch {
32
+ DispatchQueue.main.async {
33
+ call.resolve([
34
+ "result": false,
35
+ ])
36
+ }
37
+ }
38
+ }
39
+ } else {
40
+ DispatchQueue.main.async {
41
+ call.resolve([
42
+ "result": false,
43
+ ])
44
+ }
45
+ }
46
+ }
47
+ }
48
+ }
49
+ }
50
+
@@ -2,8 +2,6 @@ import Foundation
2
2
  import Capacitor
3
3
 
4
4
  public class EdgeSwipePlugin: CAPPlugin {
5
- private let implementation = EdgeSwipeService()
6
-
7
5
  @objc public func onEdgeSwipe(_ call: CAPPluginCall, _bridge: CAPBridgeProtocol) {
8
6
  let isOn = call.getBool("on") ?? false
9
7
 
@@ -11,4 +11,5 @@ CAP_PLUGIN(Plugin, "Plugin",
11
11
  CAP_PLUGIN_METHOD(timezone, CAPPluginReturnPromise);
12
12
  CAP_PLUGIN_METHOD(open, CAPPluginReturnPromise);
13
13
  CAP_PLUGIN_METHOD(edgeSwipe, CAPPluginReturnPromise);
14
+ CAP_PLUGIN_METHOD(fileDownload, CAPPluginReturnPromise);
14
15
  )
@@ -42,6 +42,10 @@ public class Plugin: CAPPlugin {
42
42
  EdgeSwipePlugin().onEdgeSwipe(call, _bridge: self.bridge!)
43
43
 
44
44
  }
45
+
46
+ @objc func fileDownload(_ call: CAPPluginCall) {
47
+ DownloadPlugin().doDownload(call, _bridge: self.bridge!)
48
+ }
45
49
 
46
50
 
47
51
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hanwha-ss1/plugin",
3
- "version": "0.5.4",
3
+ "version": "0.5.5",
4
4
  "description": "Plugin",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",
@@ -76,4 +76,4 @@
76
76
  }
77
77
  },
78
78
  "gitHead": "dbc41811fcd3e5956cc77c6df41d831c9370c1b3"
79
- }
79
+ }
@@ -1,10 +0,0 @@
1
- import Foundation
2
- import UIKit
3
-
4
-
5
- @objc public class EdgeSwipeService: NSObject {
6
- @objc public func echo(_ value: String) -> String {
7
- print(value)
8
- return value
9
- }
10
- }