mirror of
https://github.com/SableClient/Sable.git
synced 2026-11-21 17:41:25 -08:00
fix(tauri): android APK crashing and UnifiedPush not registering (#747)
* (Tauri/fix):Android APK crashing and UnifiedPush not registering * Fixed ESLint errors
This commit is contained in:
1 parent
f616a00da5
commit
bfcb24c00f
10 files changed
+100
-26
No files matched your search
+1
-1
@@ -6,7 +6,7 @@ devAssets
|
||||
|
||||
.DS_Store
|
||||
.idea
|
||||
|
||||
*.code-workspace
|
||||
.env
|
||||
|
||||
.wrangler
|
||||
|
||||
+36
-1
@@ -18,4 +18,39 @@
|
||||
|
||||
# If you keep the line number information, uncomment this to
|
||||
# hide the original source file name.
|
||||
#-renamesourcefileattribute SourceFile
|
||||
#-renamesourcefileattribute SourceFile
|
||||
|
||||
# Keep Android bridge symbols used by Wry/Tauri JNI on release builds.
|
||||
# Without these, R8 can rename/remove methods like WryActivity.getId(),
|
||||
# which tao resolves by method name via JNI.
|
||||
-keep class moe.sable.client.* {
|
||||
native <methods>;
|
||||
}
|
||||
|
||||
-keep class moe.sable.client.WryActivity {
|
||||
public <init>(...);
|
||||
|
||||
void setWebView(moe.sable.client.RustWebView);
|
||||
java.lang.Class getAppClass(...);
|
||||
java.lang.String getVersion();
|
||||
int startActivity(...);
|
||||
int getId();
|
||||
}
|
||||
|
||||
-keep class moe.sable.client.Ipc {
|
||||
public <init>(...);
|
||||
|
||||
@android.webkit.JavascriptInterface public <methods>;
|
||||
}
|
||||
|
||||
-keep class moe.sable.client.RustWebView {
|
||||
public <init>(...);
|
||||
|
||||
void loadUrlMainThread(...);
|
||||
void loadHTMLMainThread(...);
|
||||
void evalScript(...);
|
||||
}
|
||||
|
||||
-keep class moe.sable.client.RustWebChromeClient,moe.sable.client.RustWebViewClient {
|
||||
public <init>(...);
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
|
||||
|
||||
<!-- AndroidTV support -->
|
||||
<uses-feature android:name="android.software.leanback" android:required="false" />
|
||||
@@ -26,6 +27,8 @@
|
||||
<!-- DEEP LINK PLUGIN. AUTO-GENERATED. DO NOT REMOVE. -->
|
||||
<intent-filter >
|
||||
<action android:name="android.intent.action.VIEW" />
|
||||
<!-- ChromeOS ARC++ uses a different action for deep links -->
|
||||
<action android:name="org.chromium.arc.intent.action.VIEW" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<category android:name="android.intent.category.BROWSABLE" />
|
||||
<data android:scheme="sable" />
|
||||
|
||||
+12
-4
@@ -78,7 +78,7 @@ pub fn run() {
|
||||
#[cfg(mobile)]
|
||||
let builder = builder.plugin(tauri_plugin_edge_to_edge::init());
|
||||
|
||||
builder
|
||||
let app = builder
|
||||
.plugin(tauri_plugin_http::init())
|
||||
.plugin(tauri_plugin_opener::init())
|
||||
.plugin(tauri_plugin_deep_link::init())
|
||||
@@ -122,9 +122,17 @@ pub fn run() {
|
||||
#[cfg(windows)]
|
||||
desktop::windows::window_tracking::is_window_tracking_active,
|
||||
])
|
||||
.build(tauri::generate_context!())
|
||||
.expect("error while building tauri application")
|
||||
.run(|app, event| {
|
||||
.build(tauri::generate_context!());
|
||||
|
||||
let Ok(app) = app else {
|
||||
// On Android this function is called through JNI. Panicking here causes
|
||||
// "panic_cannot_unwind" and aborts the whole process without a useful
|
||||
// message in logcat.
|
||||
eprintln!("failed to build tauri application: {app:?}");
|
||||
return;
|
||||
};
|
||||
|
||||
app.run(|app, event| {
|
||||
#[cfg(desktop)]
|
||||
desktop::tray::handle_run_event(app, event);
|
||||
|
||||
|
||||
@@ -592,6 +592,7 @@ function BackgroundPushNotificationSetting() {
|
||||
registration: {
|
||||
endpoint: string;
|
||||
instance: string;
|
||||
gatewayUrl?: string;
|
||||
distributor?: string;
|
||||
pubKeySet?: {
|
||||
pubKey: string;
|
||||
@@ -603,7 +604,8 @@ function BackgroundPushNotificationSetting() {
|
||||
endpoint: registration.endpoint,
|
||||
instance: registration.instance,
|
||||
appId: effectivePushTransport.unifiedPushAppID?.trim() ?? DEFAULT_UNIFIED_PUSH_APP_ID,
|
||||
gatewayUrl: effectivePushTransport.unifiedPushGatewayUrl?.trim() ?? undefined,
|
||||
gatewayUrl:
|
||||
registration.gatewayUrl ?? effectivePushTransport.unifiedPushGatewayUrl?.trim() ?? undefined,
|
||||
status: 'registered',
|
||||
distributor: distributorOverride ?? registration.distributor,
|
||||
permissionState: 'granted',
|
||||
|
||||
@@ -33,13 +33,23 @@ const unifiedPushLog = createDebugLogger('unifiedpush');
|
||||
* Falls back to the configured or public UP gateway.
|
||||
* Note: pushNotifyUrl (Sygnal) is NOT suitable — only a proper UP gateway works.
|
||||
*/
|
||||
async function discoverGateway(upEndpoint: string, unifiedPushGateway?: string): Promise<string> {
|
||||
try {
|
||||
const probeUrl = new URL(upEndpoint);
|
||||
probeUrl.pathname = '/_matrix/push/v1/notify';
|
||||
probeUrl.search = '';
|
||||
const res = await fetch(probeUrl.toString());
|
||||
if (res.ok) {
|
||||
async function discoverGateway(
|
||||
upEndpoint: string,
|
||||
unifiedPushGateway?: string,
|
||||
upInstance?: string
|
||||
): Promise<string> {
|
||||
const probeCandidates = [upInstance, upEndpoint].filter(
|
||||
(candidate): candidate is string => !!candidate?.trim()
|
||||
);
|
||||
|
||||
const probeCandidate = async (candidate: string): Promise<string | undefined> => {
|
||||
try {
|
||||
const probeUrl = new URL(candidate);
|
||||
probeUrl.pathname = '/_matrix/push/v1/notify';
|
||||
probeUrl.search = '';
|
||||
const res = await fetch(probeUrl.toString());
|
||||
if (!res.ok) return undefined;
|
||||
|
||||
const body = await res.json();
|
||||
if (
|
||||
body?.gateway === 'matrix' ||
|
||||
@@ -47,11 +57,24 @@ async function discoverGateway(upEndpoint: string, unifiedPushGateway?: string):
|
||||
) {
|
||||
return probeUrl.toString();
|
||||
}
|
||||
} catch {
|
||||
// Probe failed (network error, invalid URL, etc)
|
||||
}
|
||||
} catch {
|
||||
// probe failed
|
||||
}
|
||||
return unifiedPushGateway ?? UP_PUBLIC_GATEWAY;
|
||||
return undefined;
|
||||
};
|
||||
|
||||
const probeAtIndex = async (index: number): Promise<string | undefined> => {
|
||||
if (index >= probeCandidates.length) return undefined;
|
||||
|
||||
const candidate = probeCandidates[index];
|
||||
const result = await probeCandidate(candidate);
|
||||
if (result) return result;
|
||||
|
||||
return probeAtIndex(index + 1);
|
||||
};
|
||||
|
||||
const discoveredGateway = await probeAtIndex(0);
|
||||
return discoveredGateway ?? unifiedPushGateway ?? UP_PUBLIC_GATEWAY;
|
||||
}
|
||||
|
||||
const UP_REGISTER_TIMEOUT_MS = 30_000;
|
||||
@@ -85,6 +108,7 @@ export type EnableUnifiedPushResult =
|
||||
status: 'registered';
|
||||
endpoint: string;
|
||||
instance: string;
|
||||
gatewayUrl: string;
|
||||
distributor: string;
|
||||
pubKeySet?: {
|
||||
pubKey: string;
|
||||
@@ -132,7 +156,7 @@ export async function tryEnableUnifiedPush(
|
||||
|
||||
const { endpoint, instance, pubKeySet } = registration;
|
||||
const resolvedConfig = resolveUnifiedPushPusherConfig(config);
|
||||
const gatewayUrl = await discoverGateway(endpoint, resolvedConfig.gatewayUrl);
|
||||
const gatewayUrl = await discoverGateway(endpoint, resolvedConfig.gatewayUrl, instance);
|
||||
|
||||
const pusherData: Record<string, string> = {
|
||||
url: gatewayUrl,
|
||||
@@ -160,6 +184,7 @@ export async function tryEnableUnifiedPush(
|
||||
status: 'registered',
|
||||
endpoint,
|
||||
instance,
|
||||
gatewayUrl,
|
||||
distributor: registration.distributor,
|
||||
pubKeySet,
|
||||
};
|
||||
@@ -168,7 +193,7 @@ export async function tryEnableUnifiedPush(
|
||||
export async function enableUnifiedPush(
|
||||
mx: MatrixClient,
|
||||
config?: UnifiedPushTransportConfigInput
|
||||
): Promise<{ endpoint: string; instance: string }> {
|
||||
): Promise<{ endpoint: string; instance: string; gatewayUrl: string }> {
|
||||
const result = await tryEnableUnifiedPush(mx, config);
|
||||
if (result.status !== 'registered') {
|
||||
throw new Error(result.error ?? 'UnifiedPush registration failed');
|
||||
@@ -177,6 +202,7 @@ export async function enableUnifiedPush(
|
||||
return {
|
||||
endpoint: result.endpoint,
|
||||
instance: result.instance,
|
||||
gatewayUrl: result.gatewayUrl,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
{
|
||||
"version": 2,
|
||||
"commands_hash": "fc2eef5fe637d84",
|
||||
"structs_hash": "558120cf32bcd332",
|
||||
"commands_hash": "eb32eda4bc83b382",
|
||||
"structs_hash": "a284d88145e0b10b",
|
||||
"events_hash": "7904dd65836c8ff4",
|
||||
"config_hash": "c72a07caa5bc6ed4",
|
||||
"combined_hash": "6c5e9d69794c83ae"
|
||||
"combined_hash": "9a335f76f3f4c201"
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Auto-generated TypeScript bindings for Tauri commands
|
||||
* Generated by tauri-typegen v0.5.0
|
||||
* Generated at: 2026-04-12T10:38:31.125771300+00:00
|
||||
* Generated at: 2026-05-04T20:53:05.987838956+00:00
|
||||
* Generator: none
|
||||
*
|
||||
* Do not edit manually - regenerate using: cargo tauri-typegen generate
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Auto-generated TypeScript bindings for Tauri commands
|
||||
* Generated by tauri-typegen v0.5.0
|
||||
* Generated at: 2026-04-12T10:38:31.126453100+00:00
|
||||
* Generated at: 2026-05-04T20:53:05.988109318+00:00
|
||||
* Generator: none
|
||||
*
|
||||
* Do not edit manually - regenerate using: cargo tauri-typegen generate
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Auto-generated TypeScript bindings for Tauri commands
|
||||
* Generated by tauri-typegen v0.5.0
|
||||
* Generated at: 2026-04-12T10:38:31.125008800+00:00
|
||||
* Generated at: 2026-05-04T20:53:05.987256613+00:00
|
||||
* Generator: none
|
||||
*
|
||||
* Do not edit manually - regenerate using: cargo tauri-typegen generate
|
||||
|
||||
Reference in new issue
Block a user