capacitor-sso-webview 0.0.4 → 0.0.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.
@@ -27,38 +27,38 @@ public class SSOWebView {
27
27
  private boolean alreadyRedirected = false;
28
28
 
29
29
  public void open(
30
- final Activity activity,
31
- final String url,
32
- final String redirectHost,
33
- final String redirectPathContains,
34
- final String title,
35
- final Listener listener) {
30
+ final Activity activity,
31
+ final String url,
32
+ final String redirectHost,
33
+ final String redirectPathContains,
34
+ final String title,
35
+ final Listener listener) {
36
36
  alreadyRedirected = false;
37
37
 
38
38
  dialog = new Dialog(activity, android.R.style.Theme_Light_NoTitleBar_Fullscreen);
39
39
 
40
40
  LinearLayout root = new LinearLayout(activity);
41
- root.setOrientation(LinearLayout.VERTICAL);
41
+ root.setOrientation(LinearLayout.VERTICAL);
42
42
  root.setLayoutParams(new LinearLayout.LayoutParams(
43
- ViewGroup.LayoutParams.MATCH_PARENT,
44
- ViewGroup.LayoutParams.MATCH_PARENT));
43
+ ViewGroup.LayoutParams.MATCH_PARENT,
44
+ ViewGroup.LayoutParams.MATCH_PARENT));
45
45
 
46
46
  /* ── Header bar ── */
47
- LinearLayout header = new LinearLayout(activity);
47
+ LinearLayout header = new LinearLayout(activity);
48
48
  header.setOrientation(LinearLayout.HORIZONTAL);
49
49
  header.setBackgroundColor(Color.parseColor("#1A2B4A"));
50
50
  header.setPadding(48, 72, 48, 48);
51
51
  header.setGravity(Gravity.CENTER_VERTICAL);
52
52
  header.setLayoutParams(new LinearLayout.LayoutParams(
53
- ViewGroup.LayoutParams.MATCH_PARENT,
54
- ViewGroup.LayoutParams.WRAP_CONTENT));
53
+ ViewGroup.LayoutParams.MATCH_PARENT,
54
+ ViewGroup.LayoutParams.WRAP_CONTENT));
55
55
 
56
56
  TextView tvTitle = new TextView(activity);
57
57
  tvTitle.setText(title != null ? title : "Login");
58
58
  tvTitle.setTextColor(Color.WHITE);
59
59
  tvTitle.setTextSize(16);
60
60
  tvTitle.setLayoutParams(new LinearLayout.LayoutParams(
61
- 0, ViewGroup.LayoutParams.WRAP_CONTENT, 1f));
61
+ 0, ViewGroup.LayoutParams.WRAP_CONTENT, 1 f));
62
62
 
63
63
  TextView btnClose = new TextView(activity);
64
64
  btnClose.setText("Tutup");
@@ -99,8 +99,8 @@ public class SSOWebView {
99
99
  String path = u.getPath();
100
100
 
101
101
  boolean isRedirect = host != null && host.equalsIgnoreCase(redirectHost) &&
102
- path != null && path.toLowerCase()
103
- .contains(redirectPathContains.toLowerCase());
102
+ path != null && path.toLowerCase()
103
+ .contains(redirectPathContains.toLowerCase());
104
104
 
105
105
  if (isRedirect && !alreadyRedirected) {
106
106
  alreadyRedirected = true;
@@ -119,55 +119,56 @@ public class SSOWebView {
119
119
  String path = u.getPath();
120
120
 
121
121
  boolean isRedirectPage = host != null && host.equalsIgnoreCase(redirectHost) &&
122
- path != null && path.toLowerCase()
123
- .contains(redirectPathContains.toLowerCase());
122
+ path != null && path.toLowerCase()
123
+ .contains(redirectPathContains.toLowerCase());
124
124
 
125
125
  if (!isRedirectPage)
126
126
  return;
127
127
 
128
128
  final String finalUrl = pageUrl;
129
- final String finalCode = u.getQueryParameter("code") != null
130
- ? u.getQueryParameter("code")
131
- : "";
132
- final String finalState = u.getQueryParameter("state") != null
133
- ? u.getQueryParameter("state")
134
- : "";
129
+ final String finalCode = u.getQueryParameter("code") != null ?
130
+ u.getQueryParameter("code") :
131
+ "";
132
+ final String finalState = u.getQueryParameter("state") != null ?
133
+ u.getQueryParameter("state") :
134
+ "";
135
135
 
136
136
  /* Delay 150ms — beri waktu body JSON ter-render ke DOM */
137
137
  view.postDelayed(new Runnable() {
138
138
  @Override
139
139
  public void run() {
140
- if (webView == null)
141
- return;
140
+ if (webView == null) return;
142
141
  webView.evaluateJavascript(
143
- "(function(){" +
144
- " var t = document.body" +
145
- " ? (document.body.innerText || document.body.textContent || '')" +
146
- " : '';" +
147
- " return t.trim();" +
148
- "})()",
149
- value -> {
150
- String body = value;
151
- if (body != null) {
152
- if (body.startsWith("\"") && body.endsWith("\""))
153
- body = body.substring(1, body.length() - 1);
154
- body = body.replace("\\\"", "\"")
155
- .replace("\\n", "\n")
156
- .replace("\\r", "")
157
- .replace("\\/", "/");
158
- }
159
- final String finalBody = (body != null) ? body : "";
160
- android.util.Log.d("SSOWebView",
161
- "body len=" + finalBody.length() +
162
- " preview=" + finalBody.substring(
163
- 0, Math.min(120, finalBody.length())));
164
-
165
- activity.runOnUiThread(this::dismiss);
166
-
167
- if (listener != null)
168
- listener.onRedirectIntercepted(
169
- finalUrl, finalCode, finalState, finalBody);
170
- });
142
+ "(function(){" +
143
+ " var t = document.body" +
144
+ " ? (document.body.innerText || document.body.textContent || '')" +
145
+ " : '';" +
146
+ " return t.trim();" +
147
+ "})()",
148
+ value -> {
149
+ String body = value;
150
+ if (body != null) {
151
+ if (body.startsWith("\"") && body.endsWith("\""))
152
+ body = body.substring(1, body.length() - 1);
153
+ body = body.replace("\\\"", "\"")
154
+ .replace("\\n", "\n")
155
+ .replace("\\r", "")
156
+ .replace("\\/", "/");
157
+ }
158
+ final String finalBody = (body != null) ? body : "";
159
+ android.util.Log.d("SSOWebView",
160
+ "body len=" + finalBody.length() +
161
+ " preview=" + finalBody.substring(
162
+ 0, Math.min(120, finalBody.length())));
163
+
164
+ /* FIX: gunakan outer class reference */
165
+ activity.runOnUiThread(() -> SSOWebView.this.dismiss());
166
+
167
+ if (listener != null)
168
+ listener.onRedirectIntercepted(
169
+ finalUrl, finalCode, finalState, finalBody);
170
+ }
171
+ );
171
172
  }
172
173
  }, 150);
173
174
  }
@@ -178,7 +179,7 @@ public class SSOWebView {
178
179
  });
179
180
 
180
181
  webView.setLayoutParams(new LinearLayout.LayoutParams(
181
- ViewGroup.LayoutParams.MATCH_PARENT, 0, 1f));
182
+ ViewGroup.LayoutParams.MATCH_PARENT, 0, 1 f));
182
183
 
183
184
  root.addView(header);
184
185
  root.addView(webView);
@@ -205,7 +206,6 @@ public class SSOWebView {
205
206
  dialog.dismiss();
206
207
  }
207
208
  dialog = null;
208
- } catch (Exception ignored) {
209
- }
209
+ } catch (Exception ignored) {}
210
210
  }
211
211
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "capacitor-sso-webview",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "description": "SSO WebView with URL intercept",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",