@hanwha-ss1/plugin 0.5.9 → 0.6.1

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.
@@ -1,5 +1,9 @@
1
1
  package com.plugin.linker;
2
2
 
3
+ import android.os.Handler;
4
+ import android.os.Looper;
5
+ import android.os.Message;
6
+
3
7
  import com.getcapacitor.JSObject;
4
8
  import com.getcapacitor.Plugin;
5
9
  import com.getcapacitor.PluginCall;
@@ -11,7 +15,6 @@ import com.plugin.download.FileDownload;
11
15
  import com.plugin.openbrowser.OpenBrowser;
12
16
  import com.plugin.opencamera.OpenCamera;
13
17
 
14
-
15
18
  @CapacitorPlugin(name = "Plugin")
16
19
  public class LinkerPlugin extends Plugin{
17
20
  private Linker implementation = new Linker();
@@ -157,4 +160,20 @@ public class LinkerPlugin extends Plugin{
157
160
  }
158
161
  });
159
162
  }
163
+
164
+ public void handleDocumentsViewer(String filePath) {
165
+ Handler handler = new Handler(Looper.getMainLooper()) {
166
+ @Override
167
+ public void handleMessage(Message msg) {
168
+ if(hasListeners("DocumentViewer")) {
169
+ JSObject data = new JSObject();
170
+ data.put("file", filePath);
171
+ notifyListeners("DocumentViewer", data);
172
+ } else {
173
+ sendEmptyMessageDelayed(-1, 200);
174
+ }
175
+ }
176
+ };
177
+ handler.sendEmptyMessage(-1);
178
+ }
160
179
  }
@@ -8,7 +8,7 @@ public class CapturePlugin: CAPPlugin {
8
8
  DispatchQueue.main.async {
9
9
  if let topController = UIViewController.topViewController(controller: bridge.viewController) {
10
10
 
11
- topController.view.makeSecure()
11
+ bridge.webView?.makeSecure()
12
12
  if let webView = bridge.webView {
13
13
  self.constraintZero(topController.view, webView)
14
14
  } else {
@@ -17,50 +17,36 @@ public class DownloadPlugin: CAPPlugin {
17
17
  if aData2.count > 1 {
18
18
  let sData = aData2[1]
19
19
 
20
- if let decodedData = Data(base64Encoded: sData, options: .ignoreUnknownCharacters) {
20
+ if let data = Data(base64Encoded: sData, options: .ignoreUnknownCharacters) {
21
21
  let paths = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
22
22
  let documentsDirectory = paths[0]
23
23
  let filePath = documentsDirectory.appendingPathComponent(fileName)
24
24
 
25
- do {
26
- try decodedData.write(to: filePath)
27
- let activityViewController = UIActivityViewController(activityItems: [filePath], applicationActivities: nil)
28
-
29
- // iPad 팝오버 설정
30
- if let popover = activityViewController.popoverPresentationController {
31
- popover.sourceView = _bridge.viewController?.view
32
- popover.sourceRect = CGRect(
33
- x: UIScreen.main.bounds.midX,
34
- y: UIScreen.main.bounds.midY,
35
- width: 0,
36
- height: 0
37
- )
38
- popover.permittedArrowDirections = []
39
- }
40
-
41
- // UIActivityViewController 표시
42
- DispatchQueue.main.async {
43
- if let topController = UIViewController.topViewController(controller: _bridge.viewController) {
44
- topController.present(activityViewController, animated: true, completion: {
45
- call.resolve([
46
- "result": true
47
- ])
48
- })
49
- } else {
25
+ DispatchQueue.global(qos: .userInitiated).async {
26
+ do {
27
+ try data.write(to: filePath)
28
+ DispatchQueue.main.async {
29
+ call.resolve([
30
+ "result": true,
31
+ ])
32
+ }
33
+ } catch {
34
+ DispatchQueue.main.async {
50
35
  call.resolve([
51
36
  "result": false,
52
37
  ])
53
38
  }
54
39
  }
55
- } catch {
56
- call.reject("Failed to save file: \(error.localizedDescription)")
57
40
  }
58
41
  } else {
59
- call.reject("Invalid Base64 data")
42
+ DispatchQueue.main.async {
43
+ call.resolve([
44
+ "result": false,
45
+ ])
46
+ }
60
47
  }
61
48
  }
62
49
  }
63
50
  }
64
-
65
51
  }
66
52
 
@@ -1,3 +1,14 @@
1
+ //
2
+ // UIViewController+Extention.swift
3
+ // Plugin
4
+ //
5
+ // Created by 구정현 on 10/30/24.
6
+ // Copyright © 2024 Max Lynch. All rights reserved.
7
+ //
8
+
9
+ import Foundation
10
+ import UIKit
11
+
1
12
  extension UIViewController {
2
13
  static func topViewController(controller: UIViewController? = UIApplication.shared.keyWindow?.rootViewController) -> UIViewController? {
3
14
  if let navigationController = controller as? UINavigationController {
@@ -8,7 +19,6 @@ extension UIViewController {
8
19
  return topViewController(controller: selected)
9
20
  }
10
21
  }
11
-
12
22
  if let presented = controller?.presentedViewController {
13
23
  return topViewController(controller: presented)
14
24
  }
@@ -5,8 +5,28 @@ import Contacts
5
5
  * Please read the Capacitor iOS Plugin Development Guide
6
6
  * here: https://capacitorjs.com/docs/plugins/ios
7
7
  */
8
+ extension Notification.Name {
9
+ static let documentViewRequest = Notification.Name("documentViewRequest")
10
+ }
11
+
8
12
  @objc(Plugin)
9
13
  public class Plugin: CAPPlugin {
14
+
15
+
16
+ override public func load() {
17
+ // 문서뷰어 요청 이벤트
18
+ NotificationCenter.default.addObserver(self, selector: #selector(handleDocumentViewRequest(_:)), name: .documentViewRequest, object: nil)
19
+ }
20
+
21
+ @objc func handleDocumentViewRequest(_ notification: Notification) {
22
+ if let userInfo = notification.userInfo as? [String: Any] {
23
+ notifyListeners("DocumentViewer", data: userInfo)
24
+ }
25
+ }
26
+
27
+ deinit {
28
+ NotificationCenter.default.removeObserver(self)
29
+ }
10
30
 
11
31
  /**
12
32
  안드로이드에서만 사용
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hanwha-ss1/plugin",
3
- "version": "0.5.9",
3
+ "version": "0.6.1",
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
+ }