Skip to content

Commit 54b06e7

Browse files
authored
fix: compatibility for old android versions (Acode-Foundation#1656)
1 parent 6d221c2 commit 54b06e7

File tree

4 files changed

+47
-16
lines changed

4 files changed

+47
-16
lines changed

src/pages/fileBrowser/fileBrowser.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1333,14 +1333,16 @@ function FileBrowserInclude(mode, info, doesOpenLast = true) {
13331333
* @param {String} url
13341334
*/
13351335
function pushToNavbar(name, url, action) {
1336+
if (!url) return;
1337+
const displayName = name || Url.basename(url) || url;
13361338
$navigation.append(
13371339
<span
13381340
id={getNavId(url)}
13391341
className="nav"
13401342
data-url={url}
1341-
data-name={name}
1343+
data-name={displayName}
13421344
attr-action="navigation"
1343-
attr-text={name}
1345+
attr-text={displayName}
13441346
tabIndex={-1}
13451347
></span>,
13461348
);
@@ -1359,14 +1361,20 @@ function FileBrowserInclude(mode, info, doesOpenLast = true) {
13591361
* @param {Array<Location>} states
13601362
*/
13611363
function loadStates(states) {
1362-
if (!Array.isArray(states)) return;
1364+
if (!Array.isArray(states) || !states.length) return;
13631365

13641366
const backNavigation = [];
1365-
const { url, name } = states.pop();
1367+
const lastState = states.pop();
1368+
if (!lastState || !lastState.url) return;
1369+
const { url } = lastState;
1370+
const name = lastState.name || Url.basename(url) || url;
13661371
let { url: lastUrl, name: lastName } = currentDir;
13671372

13681373
while (states.length) {
13691374
const location = states.splice(0, 1)[0];
1375+
if (!location || !location.url) {
1376+
continue;
1377+
}
13701378
const { url, name } = location;
13711379
let action;
13721380

src/plugins/system/android/com/foxdebug/system/System.java

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -691,14 +691,29 @@ private void hasPermission(String permission, CallbackContext callback) {
691691
}
692692

693693
public boolean fileExists(String path, String countSymlinks) {
694-
Path p = new File(path).toPath();
694+
boolean followSymlinks = !Boolean.parseBoolean(countSymlinks);
695+
File file = new File(path);
696+
697+
// Android < O does not implement File#toPath(), fall back to legacy checks
698+
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
699+
if (!file.exists()) return false;
700+
if (followSymlinks) {
701+
try {
702+
// If canonical and absolute paths differ, it's a symlink
703+
return file.getCanonicalPath().equals(file.getAbsolutePath());
704+
} catch (IOException ignored) {
705+
return false;
706+
}
707+
}
708+
return true;
709+
}
710+
711+
Path p = file.toPath();
695712
try {
696-
if (Boolean.parseBoolean(countSymlinks)) {
697-
// This will return true even for broken symlinks
698-
return Files.exists(p, LinkOption.NOFOLLOW_LINKS);
699-
} else {
700-
// Check target file, not symlink itself
713+
if (followSymlinks) {
701714
return Files.exists(p) && !Files.isSymbolicLink(p);
715+
} else {
716+
return Files.exists(p, LinkOption.NOFOLLOW_LINKS);
702717
}
703718
} catch (Exception e) {
704719
return false;
@@ -1301,4 +1316,4 @@ private void setInputType(String type) {
13011316
}
13021317
webView.setInputType(mode);
13031318
}
1304-
}
1319+
}

src/plugins/websocket/www/websocket.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,21 @@ class WebSocketInstance extends EventTarget {
5858

5959
if (event.type === 'close') {
6060
this.readyState = WebSocketInstance.CLOSED;
61-
const closeEvent = new CloseEvent('close', { code: event.data?.code, reason: event.data?.reason });
61+
const closeData = event && event.data ? event.data : {};
62+
const closeEvent = new CloseEvent('close', {
63+
code: closeData.code,
64+
reason: closeData.reason,
65+
});
6266
if (this.onclose) this.onclose(closeEvent);
6367
this.dispatchEvent(closeEvent);
6468
}
6569

6670
if (event.type === 'error') {
67-
const errorEvent = new Event('error', { message: event?.data });
71+
const errorMessage = event && event.data ? event.data : undefined;
72+
const errorEvent = new Event('error');
73+
if (errorMessage !== undefined) {
74+
errorEvent.message = errorMessage;
75+
}
6876
if (this.onerror) this.onerror(errorEvent);
6977
this.dispatchEvent(errorEvent);
7078
}

www/index.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
type,
4848
listener,
4949
useCapture,
50-
allowed,
50+
allowed
5151
) {
5252
if (typeof useCapture === "boolean") {
5353
allowed = useCapture;
@@ -76,7 +76,7 @@
7676
}
7777
this.eventListeners[type].push({
7878
listener: listener,
79-
useCapture: useCapture,
79+
useCapture: useCapture
8080
});
8181

8282
return;
@@ -159,4 +159,4 @@
159159
<wc-page id="root" class="primary"></wc-page>
160160
</body>
161161

162-
</html>
162+
</html>

0 commit comments

Comments
 (0)