@hanwha-ss1/plugin 0.4.8 → 0.4.9

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.
@@ -57,6 +57,7 @@ dependencies {
57
57
  testImplementation "junit:junit:$junitVersion"
58
58
  androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
59
59
  androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
60
+ implementation 'com.google.code.gson:gson:2.8.9' //
60
61
 
61
62
  implementation 'androidx.biometric:biometric:1.1.0'
62
63
  }
@@ -113,10 +113,11 @@ public class LinkerPlugin extends Plugin{
113
113
  boolean isExternal = Boolean.TRUE.equals(call.getBoolean("ext"));
114
114
  boolean hasClose = Boolean.TRUE.equals(call.getBoolean("isCloseBtn"));
115
115
  boolean clear = Boolean.TRUE.equals(call.getBoolean("clear"));
116
+ String token = call.getString("token");
116
117
  if(openBrowserImplementation == null) {
117
118
  openBrowserImplementation = new OpenBrowser();
118
119
  }
119
- openBrowserImplementation.open(getActivity(), url, isExternal, hasClose, clear);
120
+ openBrowserImplementation.open(getActivity(), url, isExternal, hasClose, clear, token);
120
121
  }
121
122
 
122
123
  @PluginMethod
@@ -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, boolean clear) {
24
+ public void open(AppCompatActivity activity, String url, boolean isExternal, boolean hasClose, boolean clear, String token) {
25
25
  if(activity != null && url != null && !url.isEmpty()) {
26
26
  Intent intent;
27
27
  if(isExternal) {
@@ -31,6 +31,7 @@ public class OpenBrowser {
31
31
  intent.putExtra("url", url);
32
32
  intent.putExtra("hasClose", hasClose);
33
33
  intent.putExtra("clear", clear);
34
+ intent.putExtra("token", token);
34
35
 
35
36
  }
36
37
  activity.startActivity(intent);
@@ -26,9 +26,10 @@ public class OpenBrowserPlugin extends Plugin {
26
26
  boolean isExternal = Boolean.TRUE.equals(call.getBoolean("ext"));
27
27
  boolean hasClose = Boolean.TRUE.equals(call.getBoolean("isCloseBtn"));
28
28
  boolean clear = Boolean.TRUE.equals(call.getBoolean("clear"));
29
+ String token = call.getString("token");
29
30
  if(implementation == null) {
30
31
  implementation = new OpenBrowser();
31
32
  }
32
- implementation.open(getActivity(), url, isExternal, hasClose, clear);
33
+ implementation.open(getActivity(), url, isExternal, hasClose, clear, token);
33
34
  }
34
35
  }
@@ -2,8 +2,11 @@ package com.plugin.openbrowser;
2
2
 
3
3
  import android.app.Activity;
4
4
  import android.content.Intent;
5
+ import android.content.SharedPreferences;
5
6
  import android.net.Uri;
6
7
  import android.os.Bundle;
8
+ import android.preference.PreferenceManager;
9
+ import android.util.Log;
7
10
  import android.view.View;
8
11
  import android.webkit.CookieManager;
9
12
  import android.webkit.ValueCallback;
@@ -19,12 +22,28 @@ import androidx.activity.result.ActivityResultLauncher;
19
22
  import androidx.activity.result.contract.ActivityResultContracts;
20
23
  import androidx.appcompat.app.AppCompatActivity;
21
24
 
25
+ import com.google.gson.Gson;
26
+
27
+ import org.json.JSONObject;
28
+
29
+ import java.io.OutputStream;
30
+ import java.net.HttpURLConnection;
31
+ import java.net.URI;
32
+ import java.net.URISyntaxException;
33
+ import java.net.URL;
34
+ import java.nio.charset.StandardCharsets;
35
+ import java.util.HashMap;
36
+ import java.util.Map;
37
+ import java.util.Scanner;
38
+
22
39
  public class WebViewActivity extends AppCompatActivity {
23
40
 
24
41
  private WebView webView;
25
42
 
26
43
  private ValueCallback mFilePathCallback;;
27
44
 
45
+ private String token;
46
+
28
47
  @Override
29
48
  protected void onCreate(Bundle savedInstanceState) {
30
49
  super.onCreate(savedInstanceState);
@@ -34,6 +53,7 @@ public class WebViewActivity extends AppCompatActivity {
34
53
  String url = getIntent().getStringExtra("url");
35
54
  boolean hasClose = getIntent().getBooleanExtra("hasClose", true);
36
55
  boolean clear = getIntent().getBooleanExtra("clear", false);
56
+ token = getIntent().getStringExtra("token");
37
57
  initLayout(hasClose, clear);
38
58
 
39
59
  openUrl(url);
@@ -114,11 +134,112 @@ public class WebViewActivity extends AppCompatActivity {
114
134
  intent.setData(Uri.parse(url));
115
135
  startActivity(intent);
116
136
  return true;
137
+ } else if(url.startsWith("viewer://")) {
138
+ Map<String, String> param = parseViewerParam(url);
139
+ if(param != null) {
140
+ getViewURL(param, token);
141
+ }
142
+ return true;
117
143
  } else {
118
144
  return super.shouldOverrideUrlLoading(view, url);
119
145
  }
120
146
  }
121
147
  });
148
+
149
+
150
+ }
151
+
152
+ /**
153
+ * OneBill 시스템 파일 뷰어 프로세스
154
+ *
155
+ * @param uriString ex: //viewer://
156
+ * serviceid=onebill&
157
+ * file= https%3A%2F%2Fone-erp.com%3Flang%3Dkor%26manager%3D%EC%86%8C%EB%8B%A4%EB%A7%9B%EC%82%AC%ED%83%95&
158
+ * filetype=uri&
159
+ * extension=pdf
160
+ * @return file 주소
161
+ */
162
+ private Map<String, String> parseViewerParam(String uriString) {
163
+ try {
164
+ URI uri = new URI(uriString);
165
+ String query = uri.getRawSchemeSpecificPart().split("\\?")[1];
166
+ Map<String, String> params = new HashMap<>();
167
+ Map<String, String> parsedParams = new HashMap<>();
168
+
169
+ String[] pairs = query.split("&");
170
+ for (String pair : pairs) {
171
+ String[] keyValue = pair.split("=");
172
+ if (keyValue.length > 1) {
173
+ String key = keyValue[0];
174
+ String value = java.net.URLDecoder.decode(keyValue[1], "UTF-8");
175
+ params.put(key, value);
176
+ }
177
+ }
178
+
179
+ parsedParams.put("serviceId", params.get("serviceid"));
180
+ parsedParams.put("downloadUrl", params.get("file"));
181
+ parsedParams.put("fileExtension", params.get("extension"));
182
+ return parsedParams;
183
+ } catch (URISyntaxException | java.io.UnsupportedEncodingException e) {
184
+ return null;
185
+ }
186
+ }
187
+
188
+ private void getViewURL(Map<String, String> params, String token) {
189
+ String urlString = "https://mhanwha.cleverse.kr/mapi/cofile/ext/getViewerURL";
190
+ JSONObject responseJson;
191
+ HttpURLConnection urlConnection = null;
192
+ Gson gson = new Gson();
193
+
194
+ try {
195
+ URL url = new URL(urlString);
196
+ urlConnection = (HttpURLConnection) url.openConnection();
197
+
198
+ // 요청 설정
199
+ urlConnection.setRequestMethod("POST");
200
+ urlConnection.setRequestProperty("Content-Type", "application/json; utf-8");
201
+ urlConnection.setRequestProperty("Accept", "application/json");
202
+
203
+ if (token != null && !token.isEmpty()) {
204
+ urlConnection.setRequestProperty("Authorization", token);
205
+ }
206
+
207
+ urlConnection.setDoOutput(true);
208
+
209
+ String jsonInputString = gson.toJson(params);
210
+ try (OutputStream os = urlConnection.getOutputStream()) {
211
+ byte[] input = jsonInputString.getBytes(StandardCharsets.UTF_8);
212
+ os.write(input, 0, input.length);
213
+ }
214
+
215
+ // 응답 코드 확인
216
+ int code = urlConnection.getResponseCode();
217
+ if (code == HttpURLConnection.HTTP_OK) {
218
+ // 응답 데이터를 JSON 객체로 변환
219
+ try (Scanner scanner = new Scanner(urlConnection.getInputStream())) {
220
+ scanner.useDelimiter("\\A");
221
+ String response = scanner.hasNext() ? scanner.next() : "";
222
+ responseJson = new JSONObject(response); // 응답을 JSON 객체로 변환
223
+
224
+ if(responseJson.has("iframeURL")) {
225
+ String iframeURL = responseJson.getString("iframeURL");
226
+ openUrl(iframeURL);
227
+ } else {
228
+ String errorMessage = responseJson.getString("errorMessage");
229
+ Log.e("OpenBrowser", "getViewerURL Fail: " + errorMessage);
230
+ }
231
+ }
232
+ } else {
233
+ System.out.println("Error: " + code);
234
+ }
235
+
236
+ } catch (Exception e) {
237
+ Log.e("OpenBrowser", e.getLocalizedMessage());
238
+ } finally {
239
+ if (urlConnection != null) {
240
+ urlConnection.disconnect();
241
+ }
242
+ }
122
243
  }
123
244
 
124
245
  private void openUrl(String url) {
@@ -50,6 +50,7 @@ export interface Plugin {
50
50
  ext: boolean;
51
51
  isCloseBtn?: boolean;
52
52
  clear?: boolean;
53
+ token?: string;
53
54
  }): Promise<{
54
55
  value: string;
55
56
  }>;
@@ -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; isCloseBtn?: boolean; clear?: boolean }): Promise<{ value: string }>;\n\n /**\n * EdgeSwipe 허용\n * @see default false\n */\n edgeSwipe(options: {on: boolean}): Promise<{ value: string }>;\n\n\n /**\n * 카메라앱 열기\n * @see default false\n */\n openCamera(): 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; token?: string;}): Promise<{ value: string }>;\n\n /**\n * EdgeSwipe 허용\n * @see default false\n */\n edgeSwipe(options: {on: boolean}): Promise<{ value: string }>;\n\n\n /**\n * 카메라앱 열기\n * @see default false\n */\n openCamera(): Promise<{ value: string }>;\n}\n\n"]}
package/dist/esm/web.d.ts CHANGED
@@ -11,6 +11,7 @@ export declare class PluginWeb extends WebPlugin implements Plugin {
11
11
  ext: boolean;
12
12
  isCloseBtn?: boolean;
13
13
  clear?: boolean;
14
+ token?: string;
14
15
  }): Promise<any>;
15
16
  edgeSwipe(_options: {
16
17
  on: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,sDAAsD;AACtD,OAAO,EAAC,SAAS,EAAE,SAAS,EAAC,MAAM,iBAAiB,CAAC;AAGrD,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;IAED,KAAK,CAAC,SAAS,CAAC,QAAyB;QACvC,IAAI,SAAS,CAAC,WAAW,EAAE,KAAK,KAAK,EAAE;YACrC,OAAO,OAAO,CAAC,MAAM,CAAC,qCAAqC,CAAC,CAAC;SAC9D;QACD,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;IACzB,CAAC;IAED,KAAK,CAAC,UAAU;QACd,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;IACzB,CAAC;CACF","sourcesContent":["/* eslint-disable @typescript-eslint/no-unused-vars */\nimport {Capacitor, 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 async edgeSwipe(_options: { on: boolean }): Promise<any> {\n if (Capacitor.getPlatform() !== 'ios') {\n return Promise.reject('edgeSwipe is only supported on iOS.');\n }\n return { results: {} };\n }\n\n async openCamera(): 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,EAAE,SAAS,EAAC,MAAM,iBAAiB,CAAC;AAGrD,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,QAA6F;QACtG,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;IACzB,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,QAAyB;QACvC,IAAI,SAAS,CAAC,WAAW,EAAE,KAAK,KAAK,EAAE;YACrC,OAAO,OAAO,CAAC,MAAM,CAAC,qCAAqC,CAAC,CAAC;SAC9D;QACD,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;IACzB,CAAC;IAED,KAAK,CAAC,UAAU;QACd,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;IACzB,CAAC;CACF","sourcesContent":["/* eslint-disable @typescript-eslint/no-unused-vars */\nimport {Capacitor, 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; token?: string}): Promise<any> {\n return { results: {} };\n }\n\n async edgeSwipe(_options: { on: boolean }): Promise<any> {\n if (Capacitor.getPlatform() !== 'ios') {\n return Promise.reject('edgeSwipe is only supported on iOS.');\n }\n return { results: {} };\n }\n\n async openCamera(): Promise<any> {\n return { results: {} };\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hanwha-ss1/plugin",
3
- "version": "0.4.8",
3
+ "version": "0.4.9",
4
4
  "description": "Plugin",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",