capacitor-sso-webview 0.0.4 → 0.0.6

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,37 @@ 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
- tvTitle.setLayoutParams(new LinearLayout.LayoutParams(
61
- 0, ViewGroup.LayoutParams.WRAP_CONTENT, 1f));
60
+ tvTitle.setLayoutParams(new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT, 1f));
62
61
 
63
62
  TextView btnClose = new TextView(activity);
64
63
  btnClose.setText("Tutup");
@@ -99,8 +98,8 @@ public class SSOWebView {
99
98
  String path = u.getPath();
100
99
 
101
100
  boolean isRedirect = host != null && host.equalsIgnoreCase(redirectHost) &&
102
- path != null && path.toLowerCase()
103
- .contains(redirectPathContains.toLowerCase());
101
+ path != null && path.toLowerCase()
102
+ .contains(redirectPathContains.toLowerCase());
104
103
 
105
104
  if (isRedirect && !alreadyRedirected) {
106
105
  alreadyRedirected = true;
@@ -119,55 +118,56 @@ public class SSOWebView {
119
118
  String path = u.getPath();
120
119
 
121
120
  boolean isRedirectPage = host != null && host.equalsIgnoreCase(redirectHost) &&
122
- path != null && path.toLowerCase()
123
- .contains(redirectPathContains.toLowerCase());
121
+ path != null && path.toLowerCase()
122
+ .contains(redirectPathContains.toLowerCase());
124
123
 
125
124
  if (!isRedirectPage)
126
125
  return;
127
126
 
128
127
  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
- : "";
128
+ final String finalCode = u.getQueryParameter("code") != null ?
129
+ u.getQueryParameter("code") :
130
+ "";
131
+ final String finalState = u.getQueryParameter("state") != null ?
132
+ u.getQueryParameter("state") :
133
+ "";
135
134
 
136
135
  /* Delay 150ms — beri waktu body JSON ter-render ke DOM */
137
136
  view.postDelayed(new Runnable() {
138
137
  @Override
139
138
  public void run() {
140
- if (webView == null)
141
- return;
139
+ if (webView == null) return;
142
140
  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
- });
141
+ "(function(){" +
142
+ " var t = document.body" +
143
+ " ? (document.body.innerText || document.body.textContent || '')" +
144
+ " : '';" +
145
+ " return t.trim();" +
146
+ "})()",
147
+ value -> {
148
+ String body = value;
149
+ if (body != null) {
150
+ if (body.startsWith("\"") && body.endsWith("\""))
151
+ body = body.substring(1, body.length() - 1);
152
+ body = body.replace("\\\"", "\"")
153
+ .replace("\\n", "\n")
154
+ .replace("\\r", "")
155
+ .replace("\\/", "/");
156
+ }
157
+ final String finalBody = (body != null) ? body : "";
158
+ android.util.Log.d("SSOWebView",
159
+ "body len=" + finalBody.length() +
160
+ " preview=" + finalBody.substring(
161
+ 0, Math.min(120, finalBody.length())));
162
+
163
+ /* FIX: gunakan outer class reference */
164
+ activity.runOnUiThread(() -> SSOWebView.this.dismiss());
165
+
166
+ if (listener != null)
167
+ listener.onRedirectIntercepted(
168
+ finalUrl, finalCode, finalState, finalBody);
169
+ }
170
+ );
171
171
  }
172
172
  }, 150);
173
173
  }
@@ -177,8 +177,7 @@ public class SSOWebView {
177
177
  }
178
178
  });
179
179
 
180
- webView.setLayoutParams(new LinearLayout.LayoutParams(
181
- ViewGroup.LayoutParams.MATCH_PARENT, 0, 1f));
180
+ webView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0, 1f));
182
181
 
183
182
  root.addView(header);
184
183
  root.addView(webView);
@@ -205,7 +204,6 @@ public class SSOWebView {
205
204
  dialog.dismiss();
206
205
  }
207
206
  dialog = null;
208
- } catch (Exception ignored) {
209
- }
207
+ } catch (Exception ignored) {}
210
208
  }
211
209
  }
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.6",
4
4
  "description": "SSO WebView with URL intercept",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",