Skip to content

Commit 2ec0814

Browse files
committed
Update SmartWebView.java
1 parent 5f9a773 commit 2ec0814

File tree

1 file changed

+71
-53
lines changed

1 file changed

+71
-53
lines changed

app/src/main/java/mgks/os/swv/SmartWebView.java

Lines changed: 71 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@
2929
import android.widget.TextView;
3030

3131
import java.util.ArrayList;
32+
import java.util.HashMap;
3233
import java.util.List;
34+
import java.util.Map;
3335

3436
/**
3537
* Configuration and utility class for Smart WebView
@@ -40,35 +42,35 @@ public class SmartWebView {
4042
// ===============================================================================================
4143
// CORE CONFIGURATION
4244
// ===============================================================================================
43-
45+
4446
// Debug options
4547
public static boolean SWV_DEBUGMODE = true; // Enable for detailed logs and toast alerts
46-
48+
4749
// Version information
4850
public static String ASWV_VERSION = "7.1";
49-
51+
5052
// ===============================================================================================
5153
// URL CONFIGURATION
5254
// ===============================================================================================
53-
55+
5456
// URL configurations
5557
public static String ASWV_APP_URL = "https://mgks.github.io/Android-SmartWebView/";
5658
public static String ASWV_OFFLINE_URL = "file:///android_asset/offline.html";
5759
public static String ASWV_SEARCH = "https://www.google.com/search?q=";
58-
60+
5961
// Determine app URL based on offline status
6062
public static String ASWV_URL;
6163
public static String ASWV_SHARE_URL;
6264
public static String ASWV_HOST;
6365
public static String CURR_URL;
64-
66+
6567
// External URL handling
6668
public static String ASWV_EXC_LIST = "mgks.dev,mgks.github.io,github.com"; // Comma-separated domains
67-
69+
6870
// ===============================================================================================
6971
// FEATURE FLAGS
7072
// ===============================================================================================
71-
73+
7274
// Core features
7375
public static boolean ASWP_OFFLINE; // True if app loads from local file or no internet
7476
public static boolean ASWP_FUPLOAD = true; // Upload file from webview
@@ -84,38 +86,57 @@ public class SmartWebView {
8486
public static boolean ASWP_EXTURL = true; // Open external url with default browser
8587
public static boolean ASWP_TAB = true; // Use Chrome tabs for external URLs
8688
public static boolean ASWP_EXITDIAL = true; // Confirm exit on back press
87-
89+
8890
// Security options
8991
public static boolean ASWP_CERT_VERI = true; // Verify SSL certificate (recommended)
90-
92+
9193
// Layout and display
9294
public static int ASWV_ORIENTATION = 0; // 0: unspecified, 1: portrait, 2: landscape
9395
public static int ASWV_LAYOUT = 0; // 0: fullscreen, 1: drawer layout
94-
96+
9597
// User agent configuration
9698
public static boolean POSTFIX_USER_AGENT = true;
9799
public static boolean OVERRIDE_USER_AGENT = false;
98100
public static String USER_AGENT_POSTFIX = "SWVAndroid";
99101
public static String CUSTOM_USER_AGENT = "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Mobile Safari/537.36";
100-
102+
101103
// File upload configuration
102104
public static String ASWV_F_TYPE = "*/*"; // Upload file type (use "*/*" for any file)
103-
105+
104106
// Analytics
105107
public static String ASWV_GTAG = "G-7XXC1C7CRQ"; // Analytics ID
106-
108+
109+
// ===============================================================================================
110+
// PLUGIN CONFIGURATION
111+
// ===============================================================================================
112+
113+
// Master switch for all plugins
114+
public static boolean ASWP_PLUGINS = true; // Globally enable or disable all plugins
115+
116+
// Individual plugin switches
117+
public static Map<String, Boolean> ASWP_PLUGIN_SETTINGS = new HashMap<String, Boolean>() {{
118+
put("AdMobPlugin", true);
119+
put("JSInterfacePlugin", true);
120+
put("ToastPlugin", true);
121+
put("QRScannerPlugin", true);
122+
put("BiometricPlugin", true);
123+
put("ImageCompressionPlugin", true);
124+
// To disable a plugin, just set it to false, e.g., put("AdMobPlugin", false);
125+
// New plugins can be added here.
126+
}};
127+
107128
// ===============================================================================================
108129
// RATING CONFIGURATION
109130
// ===============================================================================================
110-
131+
111132
static int ASWR_DAYS = 3; // Days before showing the dialog
112133
static int ASWR_TIMES = 10; // Launch times before showing
113134
static int ASWR_INTERVAL = 2; // Days interval for reminders
114-
135+
115136
// ===============================================================================================
116137
// INTERNAL STATE VARIABLES
117138
// ===============================================================================================
118-
139+
119140
// Shared UI components
120141
static WebView asw_view;
121142
static WebView print_view;
@@ -125,13 +146,13 @@ public class SmartWebView {
125146
static NotificationManager asw_notification;
126147
static Notification asw_notification_new;
127148
static ValueCallback<Uri[]> asw_file_path;
128-
149+
129150
// Permission request codes
130151
static int loc_perm = 1;
131152
static int file_perm = 2;
132153
static int cam_perm = 3;
133154
static int noti_perm = 4;
134-
155+
135156
// State tracking
136157
static String fcm_token;
137158
static String asw_pcam_message;
@@ -140,46 +161,46 @@ public class SmartWebView {
140161
static int ASWV_FCM_ID = (int) System.currentTimeMillis();
141162
static int asw_error_counter = 0;
142163
static boolean true_online = !ASWP_OFFLINE;
143-
164+
144165
// ===============================================================================================
145166
// INITIALIZATION MANAGEMENT
146167
// ===============================================================================================
147-
168+
148169
private static Context appContext;
149170
private static PluginManager pluginManagerInstance;
150-
private static boolean isInitialized = false;
151-
private static List<Runnable> initCallbacks = new ArrayList<>();
152-
171+
private static boolean arePluginsInitialized = false; // Flag to track initialization
172+
private static final List<Runnable> onInitCallbacks = new ArrayList<>(); // List of tasks to run after init
173+
153174
/**
154175
* Default constructor
155176
*/
156177
public SmartWebView() {
157178
// Empty constructor
158179
}
159-
180+
160181
/**
161182
* Set the application context
162183
* @param context Application context
163184
*/
164185
public static void setAppContext(Context context) {
165186
appContext = context.getApplicationContext();
166-
187+
167188
// Initialize URL configuration after context is set
168-
ASWP_OFFLINE = ASWV_APP_URL.matches("^(file)://.*$") && Functions.isInternetAvailable(appContext);
189+
ASWP_OFFLINE = ASWV_APP_URL.matches("^(file)://.*$") && !Functions.isInternetAvailable(appContext);
169190
ASWV_URL = ASWP_OFFLINE ? ASWV_OFFLINE_URL : ASWV_APP_URL;
170-
ASWV_SHARE_URL = ASWV_URL + "?share=";
191+
ASWV_SHARE_URL = ASWV_URL + "/?share="; // A more standard share URL
171192
ASWV_HOST = Functions.aswm_host(ASWV_URL);
172193
CURR_URL = ASWV_URL;
173194
}
174-
195+
175196
/**
176197
* Get the application context
177198
* @return Application context
178199
*/
179200
public static Context getAppContext() {
180201
return appContext;
181202
}
182-
203+
183204
/**
184205
* Get the plugin manager instance (singleton)
185206
* @return PluginManager instance
@@ -190,40 +211,37 @@ public static synchronized PluginManager getPluginManager() {
190211
}
191212
return pluginManagerInstance;
192213
}
193-
214+
194215
/**
195-
* Initialize Smart WebView with required components
196-
* @param activity Activity instance
197-
* @param webView WebView instance
198-
* @param functions Functions instance
216+
* Initializes the core components of SmartWebView and signals that plugins can be initialized.
217+
* @param activity The main activity.
218+
* @param webView The main WebView.
219+
* @param functions The utility functions instance.
199220
*/
200221
public static void init(Activity activity, WebView webView, Functions functions) {
201222
getPluginManager().setContext(activity, webView, functions);
202-
initializePlugins();
203-
}
204-
205-
/**
206-
* Initialize plugins and trigger callbacks
207-
*/
208-
public static void initializePlugins() {
209-
if (!isInitialized) {
210-
isInitialized = true;
211-
for (Runnable callback : initCallbacks) {
223+
224+
// Now that the context is set, we can consider plugins initialized.
225+
// Run all pending callbacks.
226+
if (!arePluginsInitialized) {
227+
arePluginsInitialized = true;
228+
for (Runnable callback : onInitCallbacks) {
212229
callback.run();
213230
}
214-
initCallbacks.clear();
231+
onInitCallbacks.clear();
215232
}
216233
}
217-
234+
218235
/**
219-
* Register callback for plugin initialization
220-
* @param callback Callback to run after initialization
236+
* Registers a task to be executed once the plugin system is fully initialized.
237+
* If the system is already initialized, the task runs immediately.
238+
* @param callback The task (Runnable) to execute.
221239
*/
222240
public static void onPluginsInitialized(Runnable callback) {
223-
if (isInitialized) {
224-
callback.run();
241+
if (arePluginsInitialized) {
242+
callback.run(); // Already initialized, run immediately.
225243
} else {
226-
initCallbacks.add(callback);
244+
onInitCallbacks.add(callback); // Not yet initialized, queue the callback.
227245
}
228246
}
229-
}
247+
}

0 commit comments

Comments
 (0)