@hanwha-ss1/plugin 0.4.0 → 0.4.2

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.
package/README.md CHANGED
@@ -25,6 +25,9 @@ await HanwhaPlugin.addContact({
25
25
  ext: "내선"
26
26
  })
27
27
 
28
+ // 모달
29
+ HanwhaPlugin.open({url: "{{url}}", isCloseBtn:true, clear: true, ext: false})
30
+
28
31
  // 생체인증
29
32
  await HanwhaPlugin.auth()
30
33
  ```
@@ -21,7 +21,7 @@ public class OpenBrowser {
21
21
  * @param url
22
22
  * @param isExternal
23
23
  */
24
- public void open(AppCompatActivity activity, String url, boolean isExternal, boolean hasClose) {
24
+ public void open(AppCompatActivity activity, String url, boolean isExternal, boolean hasClose, boolean clear) {
25
25
  if(activity != null && url != null && !url.isEmpty()) {
26
26
  Intent intent;
27
27
  if(isExternal) {
@@ -30,6 +30,8 @@ public class OpenBrowser {
30
30
  intent = new Intent(activity, WebViewActivity.class);
31
31
  intent.putExtra("url", url);
32
32
  intent.putExtra("hasClose", hasClose);
33
+ intent.putExtra("clear", clear);
34
+
33
35
  }
34
36
  activity.startActivity(intent);
35
37
  }
@@ -25,9 +25,10 @@ public class OpenBrowserPlugin extends Plugin {
25
25
  String url = call.getString("url");
26
26
  boolean isExternal = Boolean.TRUE.equals(call.getBoolean("ext"));
27
27
  boolean hasClose = Boolean.TRUE.equals(call.getBoolean("isCloseBtn"));
28
+ boolean clear = Boolean.TRUE.equals(call.getBoolean("clear"));
28
29
  if(implementation == null) {
29
30
  implementation = new OpenBrowser();
30
31
  }
31
- implementation.open(getActivity(), url, isExternal, hasClose);
32
+ implementation.open(getActivity(), url, isExternal, hasClose, clear);
32
33
  }
33
34
  }
@@ -1,18 +1,30 @@
1
1
  package com.plugin.openbrowser;
2
2
 
3
3
  import android.app.Activity;
4
+ import android.content.Intent;
5
+ import android.net.Uri;
4
6
  import android.os.Bundle;
5
7
  import android.view.View;
8
+ import android.webkit.CookieManager;
9
+ import android.webkit.ValueCallback;
10
+ import android.webkit.WebChromeClient;
11
+ import android.webkit.WebStorage;
6
12
  import android.webkit.WebView;
7
13
  import android.webkit.WebViewClient;
8
14
  import android.widget.ImageView;
9
15
 
16
+ import androidx.activity.result.ActivityResult;
17
+ import androidx.activity.result.ActivityResultCallback;
18
+ import androidx.activity.result.ActivityResultLauncher;
19
+ import androidx.activity.result.contract.ActivityResultContracts;
10
20
  import androidx.appcompat.app.AppCompatActivity;
11
21
 
12
22
  public class WebViewActivity extends AppCompatActivity {
13
23
 
14
24
  private WebView webView;
15
25
 
26
+ private ValueCallback mFilePathCallback;;
27
+
16
28
  @Override
17
29
  protected void onCreate(Bundle savedInstanceState) {
18
30
  super.onCreate(savedInstanceState);
@@ -21,15 +33,39 @@ public class WebViewActivity extends AppCompatActivity {
21
33
 
22
34
  String url = getIntent().getStringExtra("url");
23
35
  boolean hasClose = getIntent().getBooleanExtra("hasClose", true);
24
-
25
- initLayout(hasClose);
36
+ boolean clear = getIntent().getBooleanExtra("clear", false);
37
+ initLayout(hasClose, clear);
26
38
 
27
39
  openUrl(url);
28
40
  }
29
41
 
30
- private void initLayout(boolean hasClose) {
42
+ private final ActivityResultLauncher<Intent> startActivityResult = registerForActivityResult(
43
+ new ActivityResultContracts.StartActivityForResult(),
44
+ new ActivityResultCallback<ActivityResult>() {
45
+ @Override
46
+ public void onActivityResult(ActivityResult result) {
47
+ if (result.getResultCode() == Activity.RESULT_OK) {
48
+ mFilePathCallback.onReceiveValue(WebChromeClient.FileChooserParams.parseResult(result.getResultCode(), result.getData()));
49
+ mFilePathCallback = null;
50
+ } else {
51
+ mFilePathCallback.onReceiveValue(null);
52
+ }
53
+ }
54
+ });
55
+
56
+ private void initLayout(boolean hasClose, boolean clear) {
31
57
  webView = findViewById(R.id.webView);
32
58
 
59
+ if(clear) {
60
+ webView.clearCache(true);
61
+ webView.clearHistory();
62
+ webView.clearFormData();
63
+ CookieManager cookieManager = CookieManager.getInstance();
64
+ cookieManager.removeAllCookies(null);
65
+ cookieManager.flush();
66
+ WebStorage.getInstance().deleteAllData();
67
+ }
68
+
33
69
  if(hasClose) {
34
70
  findViewById(R.id.ivClose).setOnClickListener(new View.OnClickListener() {
35
71
  @Override
@@ -48,7 +84,41 @@ public class WebViewActivity extends AppCompatActivity {
48
84
  webView.getSettings().setDisplayZoomControls(false);
49
85
  webView.getSettings().setLoadWithOverviewMode(true);
50
86
  webView.getSettings().setUseWideViewPort(true);
51
- webView.setWebChromeClient(new ChromeClient((Activity)this));
87
+ // webView.setWebChromeClient(new ChromeClient((Activity)this));
88
+ webView.setWebChromeClient(new ChromeClient(this) {
89
+ @Override
90
+ public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback, FileChooserParams fileChooserParams) {
91
+ mFilePathCallback = filePathCallback;
92
+
93
+ Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
94
+ intent.addCategory(Intent.CATEGORY_OPENABLE);
95
+ intent.setType("image/*");
96
+
97
+ // startActivityForResult(intent, 0);
98
+ startActivityResult.launch(intent);
99
+ return true;
100
+ }
101
+ });
102
+
103
+ webView.setWebViewClient(new WebViewClient(){
104
+ @Override
105
+ public boolean shouldOverrideUrlLoading(WebView view, String url) {
106
+ if(url.startsWith("close://")){
107
+ WebViewActivity.this.finish();
108
+ } else if(url.startsWith("tel:")){
109
+ Intent intent = new Intent(Intent.ACTION_DIAL);
110
+ intent.setData(Uri.parse(url));
111
+ startActivity(intent);
112
+ } else if(url.startsWith("sms:")){
113
+ Intent intent = new Intent(Intent.ACTION_SENDTO);
114
+ intent.setData(Uri.parse(url));
115
+ startActivity(intent);
116
+ }
117
+ return super.shouldOverrideUrlLoading(view, url);
118
+ }
119
+ });
120
+
121
+
52
122
  webView.setWebViewClient(new WebViewClient(){
53
123
  @Override
54
124
  public boolean shouldOverrideUrlLoading(WebView view, String url) {
@@ -72,4 +142,4 @@ public class WebViewActivity extends AppCompatActivity {
72
142
  super.onBackPressed();
73
143
  }
74
144
  }
75
- }
145
+ }
@@ -48,6 +48,8 @@ export interface Plugin {
48
48
  open(options: {
49
49
  url: string;
50
50
  ext: boolean;
51
+ isCloseBtn?: boolean;
52
+ clear?: boolean;
51
53
  }): Promise<{
52
54
  value: string;
53
55
  }>;
@@ -1 +1 @@
1
- {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["export interface Plugin {\n /**\n * 앱 실행\n * @param options package : 패키지명\n */\n executeApp(options: {\n package: string;\n }): Promise<{ value: string }>;\n\n /**\n * 연락처 저장\n * @param options name : 성명\n * @param options phone : 전화번호\n * @param options email : 이메일\n * @param options dept : 소속\n * @param options ext : 내선번호\n */\n addContact(options: {\n name: string;\n phone: string;\n email: string;\n dept: string;\n ext: string;\n }): Promise<{ value: string }>;\n\n /**\n * TouchID, FaceID\n */\n auth(): Promise<{ value: string }>;\n\n /**\n * 시스템에 설정된 지역이 서울인지 확인\n */\n checkSeoulTimeZone(): Promise<{ value: string }>;\n\n timezone(): Promise<{ value: string }>;\n\n /**\n *\n * @param options url : \"웹 페이지 주소\"\n * @param options ext : false(내부 웹뷰), true(외부 브라우저)\n */\n open(options: { url: string; ext: boolean; }): Promise<{ value: string }>;\n}\n\n"]}
1
+ {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["export interface Plugin {\n /**\n * 앱 실행\n * @param options package : 패키지명\n */\n executeApp(options: {\n package: string;\n }): Promise<{ value: string }>;\n\n /**\n * 연락처 저장\n * @param options name : 성명\n * @param options phone : 전화번호\n * @param options email : 이메일\n * @param options dept : 소속\n * @param options ext : 내선번호\n */\n addContact(options: {\n name: string;\n phone: string;\n email: string;\n dept: string;\n ext: string;\n }): Promise<{ value: string }>;\n\n /**\n * TouchID, FaceID\n */\n auth(): Promise<{ value: string }>;\n\n /**\n * 시스템에 설정된 지역이 서울인지 확인\n */\n checkSeoulTimeZone(): Promise<{ value: string }>;\n\n timezone(): Promise<{ value: string }>;\n\n /**\n *\n * @param options url : \"웹 페이지 주소\"\n * @param options ext : false(내부 웹뷰), true(외부 브라우저)\n */\n open(options: { url: string; ext: boolean; isCloseBtn?: boolean; clear?: boolean }): Promise<{ value: string }>;\n}\n\n"]}
package/dist/esm/web.d.ts CHANGED
@@ -9,5 +9,7 @@ export declare class PluginWeb extends WebPlugin implements Plugin {
9
9
  open(_options: {
10
10
  url: string;
11
11
  ext: boolean;
12
+ isCloseBtn?: boolean;
13
+ clear?: boolean;
12
14
  }): Promise<any>;
13
15
  }
@@ -1 +1 @@
1
- {"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,sDAAsD;AACtD,OAAO,EAAC,SAAS,EAAC,MAAM,iBAAiB,CAAC;AAG1C,MAAM,OAAO,SAAU,SAAQ,SAAS;IAEtC,KAAK,CAAC,UAAU;QACd,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;IACzB,CAAC;IAED,KAAK,CAAC,UAAU;QACd,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;IACzB,CAAC;IAED,KAAK,CAAC,IAAI;QACR,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;IACzB,CAAC;IAED,KAAK,CAAC,kBAAkB;QACtB,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;IACzB,CAAC;IAED,KAAK,CAAC,QAAQ;QACZ,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;IACzB,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,QAAuC;QAChD,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;IACzB,CAAC;CACF","sourcesContent":["/* eslint-disable @typescript-eslint/no-unused-vars */\nimport {WebPlugin} from '@capacitor/core';\nimport type {Plugin} from './definitions';\n\nexport class PluginWeb extends WebPlugin implements Plugin {\n\n async executeApp(): Promise<any> {\n return { results: {} };\n }\n\n async addContact(): Promise<any> {\n return { results: {} };\n }\n\n async auth(): Promise<any> {\n return { results: {} };\n }\n\n async checkSeoulTimeZone(): Promise<any> {\n return { results: {} };\n }\n\n async timezone(): Promise<any> {\n return { results: {} };\n }\n\n async open(_options: { url: string, ext: boolean }): Promise<any> {\n return { results: {} };\n }\n}\n"]}
1
+ {"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,sDAAsD;AACtD,OAAO,EAAC,SAAS,EAAC,MAAM,iBAAiB,CAAC;AAG1C,MAAM,OAAO,SAAU,SAAQ,SAAS;IAEtC,KAAK,CAAC,UAAU;QACd,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;IACzB,CAAC;IAED,KAAK,CAAC,UAAU;QACd,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;IACzB,CAAC;IAED,KAAK,CAAC,IAAI;QACR,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;IACzB,CAAC;IAED,KAAK,CAAC,kBAAkB;QACtB,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;IACzB,CAAC;IAED,KAAK,CAAC,QAAQ;QACZ,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;IACzB,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,QAA8E;QACvF,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;IACzB,CAAC;CACF","sourcesContent":["/* eslint-disable @typescript-eslint/no-unused-vars */\nimport {WebPlugin} from '@capacitor/core';\nimport type {Plugin} from './definitions';\n\nexport class PluginWeb extends WebPlugin implements Plugin {\n\n async executeApp(): Promise<any> {\n return { results: {} };\n }\n\n async addContact(): Promise<any> {\n return { results: {} };\n }\n\n async auth(): Promise<any> {\n return { results: {} };\n }\n\n async checkSeoulTimeZone(): Promise<any> {\n return { results: {} };\n }\n\n async timezone(): Promise<any> {\n return { results: {} };\n }\n\n async open(_options: { url: string, ext: boolean, isCloseBtn?: boolean; clear?: boolean }): Promise<any> {\n return { results: {} };\n }\n}\n"]}
@@ -11,10 +11,11 @@ public class OpenBrowserPlugin: CAPPlugin {
11
11
 
12
12
  @objc func openBrowser(_ call: CAPPluginCall, _bridge: CAPBridgeProtocol) {
13
13
  let url = call.getString("url") ?? ""
14
-
14
+ let isCloseBtn = call.getBool("isCloseBtn") ?? true
15
+ let clear = call.getBool("clear") ?? false
15
16
 
16
17
  DispatchQueue.main.async {
17
- let controller = self.implementation.builder(url: url)
18
+ let controller = self.implementation.builder(url: url, isCloseBtn: isCloseBtn, clear: clear)
18
19
  controller.modalPresentationStyle = .fullScreen
19
20
 
20
21
  _bridge.viewController?.present(controller, animated: true)
@@ -6,10 +6,12 @@ import Capacitor
6
6
 
7
7
 
8
8
  public class OpenBrowserService: NSObject {
9
- @objc public func builder(url: String) -> UIViewController {
9
+ @objc public func builder(url: String, isCloseBtn: Bool, clear: Bool) -> UIViewController {
10
10
  let bundle = Bundle(for: self.classForCoder)
11
11
  let controller = ViewController(nibName: "ViewController", bundle: bundle)
12
+ controller.isCloseBtn = isCloseBtn
12
13
  controller.url = url
14
+ controller.clear = clear
13
15
  return controller
14
16
  }
15
17
 
@@ -13,16 +13,33 @@ import WebKit
13
13
 
14
14
  class ViewController: UIViewController {
15
15
  @IBOutlet var wkWebview: WKWebView!
16
+ @IBOutlet var btnPanel: UIView!
17
+ @IBOutlet var constraintPanelHeight: NSLayoutConstraint!
16
18
  @IBOutlet var btnClose: UIButton!
17
19
  @IBOutlet var indicator: UIActivityIndicatorView!
18
-
20
+
19
21
 
20
22
  var url: String = ""
23
+ var isCloseBtn: Bool = false
24
+ var clear: Bool = false
21
25
  var naviTitle: String = ""
26
+
22
27
 
23
28
  override func viewDidLoad() {
24
29
  super.viewDidLoad()
30
+ if isCloseBtn {
31
+ btnPanel.isHidden = false
32
+ constraintPanelHeight.constant = 48
33
+ } else {
34
+ btnPanel.isHidden = true
35
+ constraintPanelHeight.constant = 0
36
+ }
37
+
25
38
  indicator.startAnimating()
39
+ if clear {
40
+ clearCache()
41
+ }
42
+ wkWebview.uiDelegate = self
26
43
  wkWebview.navigationDelegate = self
27
44
  wkWebview.load(URLRequest.init(url: URL(string: url)!))
28
45
  }
@@ -41,15 +58,53 @@ class ViewController: UIViewController {
41
58
  @IBAction func doClose() {
42
59
  self.dismiss(animated: true)
43
60
  }
61
+
62
+ func clearCache() {
63
+ let websiteDataTypes = Set([WKWebsiteDataTypeMemoryCache, WKWebsiteDataTypeDiskCache, WKWebsiteDataTypeCookies, WKWebsiteDataTypeSessionStorage, WKWebsiteDataTypeLocalStorage, WKWebsiteDataTypeIndexedDBDatabases, WKWebsiteDataTypeWebSQLDatabases])
64
+ let dateFrom = Date(timeIntervalSince1970: 0)
65
+
66
+ WKWebsiteDataStore.default().removeData(ofTypes: websiteDataTypes, modifiedSince: dateFrom) {
67
+ print("Cache cleared")
68
+ }
69
+ }
44
70
  }
45
71
 
46
72
 
47
- extension ViewController: WKNavigationDelegate {
73
+ extension ViewController: WKNavigationDelegate, WKUIDelegate {
48
74
  func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
49
75
  indicator.stopAnimating()
50
76
  webView.isHidden = false
51
77
  }
52
78
 
79
+ func webView(_ webView: WKWebView, runJavaScriptAlertPanelWithMessage message: String, initiatedByFrame frame: WKFrameInfo, completionHandler: @escaping () -> Swift.Void) {
80
+
81
+ let alertController = UIAlertController(title: message, message: nil, preferredStyle: .alert);
82
+
83
+ let cancelAction = UIAlertAction(title: "확인", style: .cancel) {
84
+ _ in completionHandler()
85
+ }
86
+
87
+ alertController.addAction(cancelAction)
88
+ DispatchQueue.main.async {
89
+ self.present(alertController, animated: true, completion: nil)
90
+ }
91
+ }
92
+
93
+ func webView(_ webView: WKWebView, runJavaScriptConfirmPanelWithMessage message: String, initiatedByFrame frame: WKFrameInfo, completionHandler: @escaping (Bool) -> Void) {
94
+ let alertController = UIAlertController(title: "", message: message, preferredStyle: .alert)
95
+ let cancelAction = UIAlertAction(title: "취소", style: .cancel) { _ in
96
+ completionHandler(false)
97
+ }
98
+ let okAction = UIAlertAction(title: "확인", style: .default) { _ in
99
+ completionHandler(true)
100
+ }
101
+ alertController.addAction(cancelAction)
102
+ alertController.addAction(okAction)
103
+ DispatchQueue.main.async {
104
+ self.present(alertController, animated: true, completion: nil)
105
+ }
106
+ }
107
+
53
108
  func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
54
109
 
55
110
  let url = navigationAction.request.url?.absoluteString
@@ -3,14 +3,16 @@
3
3
  <device id="retina6_0" orientation="portrait" appearance="light"/>
4
4
  <dependencies>
5
5
  <deployment identifier="iOS"/>
6
- <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="22684"/>
6
+ <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="22685"/>
7
7
  <capability name="Safe area layout guides" minToolsVersion="9.0"/>
8
8
  <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
9
9
  </dependencies>
10
10
  <objects>
11
- <placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="ViewController" customModule="HanwhaSs1Plugin" customModuleProvider="target">
11
+ <placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="ViewController" customModule="Plugin" customModuleProvider="target">
12
12
  <connections>
13
13
  <outlet property="btnClose" destination="1PV-Mj-hAT" id="mlS-cq-Qaz"/>
14
+ <outlet property="btnPanel" destination="Uoe-RW-I9y" id="iTQ-0F-k59"/>
15
+ <outlet property="constraintPanelHeight" destination="G6Y-b0-xtz" id="QkE-B3-I13"/>
14
16
  <outlet property="indicator" destination="Vt7-sZ-fvc" id="LWz-jE-fvu"/>
15
17
  <outlet property="view" destination="i5M-Pr-FkT" id="sfx-zR-JGt"/>
16
18
  <outlet property="wkWebview" destination="gNx-5x-FOs" id="rA7-7h-TvS"/>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hanwha-ss1/plugin",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "description": "Plugin",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",