Apply the auto-fixable lint rules and the formatter, and drop the Vite build artifacts.
This commit is contained in:
@@ -62,15 +62,15 @@ interface MatrixBackgroundSyncPlugin {
|
||||
resolveUnifiedPushGateway(options: { endpoint: string }): Promise<{ gatewayUrl: string }>;
|
||||
addListener(
|
||||
eventName: 'unifiedPushNewEndpoint',
|
||||
listenerFunc: (event: UnifiedPushEndpointEvent) => void
|
||||
listenerFunc: (event: UnifiedPushEndpointEvent) => void,
|
||||
): Promise<PluginListenerHandle>;
|
||||
addListener(
|
||||
eventName: 'unifiedPushUnregistered',
|
||||
listenerFunc: (event: UnifiedPushUnregisteredEvent) => void
|
||||
listenerFunc: (event: UnifiedPushUnregisteredEvent) => void,
|
||||
): Promise<PluginListenerHandle>;
|
||||
addListener(
|
||||
eventName: 'unifiedPushRegistrationFailed',
|
||||
listenerFunc: (event: UnifiedPushRegistrationFailedEvent) => void
|
||||
listenerFunc: (event: UnifiedPushRegistrationFailedEvent) => void,
|
||||
): Promise<PluginListenerHandle>;
|
||||
}
|
||||
|
||||
@@ -79,13 +79,15 @@ type StoredPusherState = {
|
||||
appId: string;
|
||||
};
|
||||
|
||||
const DEFAULT_UNIFIED_PUSH_GATEWAY = 'https://matrix.gateway.unifiedpush.org/_matrix/push/v1/notify';
|
||||
const DEFAULT_UNIFIED_PUSH_GATEWAY =
|
||||
'https://matrix.gateway.unifiedpush.org/_matrix/push/v1/notify';
|
||||
const PUSHER_APP_ID_BASE = 'com.paarrot.app.android';
|
||||
const PUSHER_STORAGE_PREFIX = 'paarrot.unifiedpush';
|
||||
|
||||
/** Returns true when the current platform is Android Capacitor. */
|
||||
export const isBackgroundSyncSupported = (): boolean => {
|
||||
const capacitor = (window as typeof window & { Capacitor?: CapacitorCoreModule['Capacitor'] }).Capacitor;
|
||||
const capacitor = (window as typeof window & { Capacitor?: CapacitorCoreModule['Capacitor'] })
|
||||
.Capacitor;
|
||||
return Boolean(capacitor?.isNativePlatform?.() && capacitor.getPlatform() === 'android');
|
||||
};
|
||||
|
||||
@@ -99,7 +101,7 @@ const buildPusherAppId = (deviceId: string | null): string => {
|
||||
|
||||
const loadStoredPusherState = (
|
||||
userId: string | null,
|
||||
deviceId: string | null
|
||||
deviceId: string | null,
|
||||
): StoredPusherState | undefined => {
|
||||
if (typeof window === 'undefined' || !window.localStorage) return undefined;
|
||||
|
||||
@@ -116,7 +118,7 @@ const loadStoredPusherState = (
|
||||
const saveStoredPusherState = (
|
||||
userId: string | null,
|
||||
deviceId: string | null,
|
||||
state: StoredPusherState
|
||||
state: StoredPusherState,
|
||||
): void => {
|
||||
if (typeof window === 'undefined' || !window.localStorage) return;
|
||||
window.localStorage.setItem(getStoredPusherKey(userId, deviceId), JSON.stringify(state));
|
||||
@@ -196,8 +198,13 @@ class AndroidUnifiedPushManager {
|
||||
const { Capacitor, registerPlugin } = await loadCapacitorCore();
|
||||
const MatrixBackgroundSync = registerPlugin<MatrixBackgroundSyncPlugin>('MatrixBackgroundSync');
|
||||
|
||||
console.log('[BackgroundSync] start() called, platform:', Capacitor.getPlatform(), 'isNative:', Capacitor.isNativePlatform());
|
||||
|
||||
console.log(
|
||||
'[BackgroundSync] start() called, platform:',
|
||||
Capacitor.getPlatform(),
|
||||
'isNative:',
|
||||
Capacitor.isNativePlatform(),
|
||||
);
|
||||
|
||||
if (!isBackgroundSyncSupported()) {
|
||||
console.log('[BackgroundSync] Background sync not supported on this platform');
|
||||
return;
|
||||
@@ -208,7 +215,12 @@ class AndroidUnifiedPushManager {
|
||||
const userId = mx.getUserId();
|
||||
const deviceId = mx.getDeviceId();
|
||||
|
||||
console.log('[BackgroundSync] Credentials check:', { userId, deviceId, hasToken: !!accessToken, hasUrl: !!homeserverUrl });
|
||||
console.log('[BackgroundSync] Credentials check:', {
|
||||
userId,
|
||||
deviceId,
|
||||
hasToken: !!accessToken,
|
||||
hasUrl: !!homeserverUrl,
|
||||
});
|
||||
|
||||
if (!homeserverUrl || !accessToken || !userId) {
|
||||
console.warn('[BackgroundSync] Missing credentials, not starting');
|
||||
@@ -246,7 +258,7 @@ class AndroidUnifiedPushManager {
|
||||
const { registerPlugin } = await loadCapacitorCore();
|
||||
const MatrixBackgroundSync = registerPlugin<MatrixBackgroundSyncPlugin>('MatrixBackgroundSync');
|
||||
|
||||
const client = this.client;
|
||||
const { client } = this;
|
||||
if (client) {
|
||||
const deviceId = client.getDeviceId();
|
||||
const userId = client.getUserId();
|
||||
@@ -269,7 +281,7 @@ class AndroidUnifiedPushManager {
|
||||
|
||||
/** Update the Matrix pusher when a new native endpoint is published. */
|
||||
private async handleNewEndpoint(event: UnifiedPushEndpointEvent): Promise<void> {
|
||||
const client = this.client;
|
||||
const { client } = this;
|
||||
if (!client) return;
|
||||
|
||||
if (event.previousEndpoint) {
|
||||
@@ -281,7 +293,7 @@ class AndroidUnifiedPushManager {
|
||||
|
||||
/** Remove the Matrix pusher when UnifiedPush unregisters this instance. */
|
||||
private async handleUnregistered(event: UnifiedPushUnregisteredEvent): Promise<void> {
|
||||
const client = this.client;
|
||||
const { client } = this;
|
||||
if (!client) return;
|
||||
|
||||
const stored = loadStoredPusherState(client.getUserId(), client.getDeviceId());
|
||||
@@ -311,7 +323,8 @@ class AndroidUnifiedPushManager {
|
||||
private async tryRequestDistributorSetup(): Promise<void> {
|
||||
try {
|
||||
const { registerPlugin } = await loadCapacitorCore();
|
||||
const MatrixBackgroundSync = registerPlugin<MatrixBackgroundSyncPlugin>('MatrixBackgroundSync');
|
||||
const MatrixBackgroundSync =
|
||||
registerPlugin<MatrixBackgroundSyncPlugin>('MatrixBackgroundSync');
|
||||
const setupResult = await MatrixBackgroundSync.requestDistributorSetup();
|
||||
console.warn('[BackgroundSync] requestDistributorSetup result:', setupResult);
|
||||
const status = await this.safeGetStatus();
|
||||
@@ -319,7 +332,7 @@ class AndroidUnifiedPushManager {
|
||||
const distributors = normalizeDistributors(status?.distributors ?? []);
|
||||
if (distributors.length === 0) {
|
||||
console.error(
|
||||
'[BackgroundSync] No UnifiedPush distributor installed. Install one (for example ntfy) to enable Android background notifications.'
|
||||
'[BackgroundSync] No UnifiedPush distributor installed. Install one (for example ntfy) to enable Android background notifications.',
|
||||
);
|
||||
this.showNoDistributorPrompt();
|
||||
}
|
||||
@@ -336,7 +349,7 @@ class AndroidUnifiedPushManager {
|
||||
const distributors = normalizeDistributors(status.distributors);
|
||||
if (!status.registered && distributors.length === 0) {
|
||||
console.error(
|
||||
'[BackgroundSync] No UnifiedPush distributor installed. Install one (for example ntfy) to enable Android background notifications.'
|
||||
'[BackgroundSync] No UnifiedPush distributor installed. Install one (for example ntfy) to enable Android background notifications.',
|
||||
);
|
||||
this.showNoDistributorPrompt();
|
||||
}
|
||||
@@ -395,7 +408,7 @@ class AndroidUnifiedPushManager {
|
||||
|
||||
/** Reconcile an already-persisted native endpoint after app startup. */
|
||||
private async syncExistingEndpoint(): Promise<void> {
|
||||
const client = this.client;
|
||||
const { client } = this;
|
||||
if (!client) return;
|
||||
|
||||
const { registerPlugin } = await loadCapacitorCore();
|
||||
@@ -457,7 +470,7 @@ class AndroidUnifiedPushManager {
|
||||
private async removePusher(
|
||||
mx: MatrixClient,
|
||||
endpoint: string,
|
||||
appId = buildPusherAppId(mx.getDeviceId())
|
||||
appId = buildPusherAppId(mx.getDeviceId()),
|
||||
): Promise<void> {
|
||||
try {
|
||||
await mx.setPusher({
|
||||
@@ -474,7 +487,8 @@ class AndroidUnifiedPushManager {
|
||||
private async safeGetStatus(): Promise<UnifiedPushStatus | undefined> {
|
||||
try {
|
||||
const { registerPlugin } = await loadCapacitorCore();
|
||||
const MatrixBackgroundSync = registerPlugin<MatrixBackgroundSyncPlugin>('MatrixBackgroundSync');
|
||||
const MatrixBackgroundSync =
|
||||
registerPlugin<MatrixBackgroundSyncPlugin>('MatrixBackgroundSync');
|
||||
return await MatrixBackgroundSync.getStatus();
|
||||
} catch (err) {
|
||||
console.warn('[BackgroundSync] Failed to read UnifiedPush status:', err);
|
||||
|
||||
Reference in New Issue
Block a user