REF: remove GroundControl server URI saving from notifications module
Some checks are pending
Build Release and Upload to TestFlight (iOS) / build (push) Waiting to run
Build Release and Upload to TestFlight (iOS) / testflight-upload (push) Blocked by required conditions
BuildReleaseApk / buildReleaseApk (push) Waiting to run
BuildReleaseApk / browserstack (push) Blocked by required conditions

Co-authored-by: Overtorment <Overtorment@users.noreply.github.com>
This commit is contained in:
Cursor Agent 2026-06-09 20:24:56 +00:00 committed by Overtorment
parent bfeda40284
commit f334b985e8
2 changed files with 1 additions and 76 deletions

View File

@ -13,11 +13,10 @@ import { groundControlUri } from './constants';
import { fetch } from '../util/fetch';
const PUSH_TOKEN = 'PUSH_TOKEN';
const GROUNDCONTROL_BASE_URI = 'GROUNDCONTROL_BASE_URI';
const NOTIFICATIONS_STORAGE = 'NOTIFICATIONS_STORAGE';
const ANDROID_NOTIFICATION_CHANNEL_ID = 'channel_01';
export const NOTIFICATIONS_NO_AND_DONT_ASK_FLAG = 'NOTIFICATIONS_NO_AND_DONT_ASK_FLAG';
let baseURI = groundControlUri;
const baseURI = groundControlUri;
let notificationSubscriptions: EmitterSubscription[] = [];
let onProcessNotificationsHandler: undefined | (() => void | Promise<void>);
const handledNotificationKeys = new Set<string>();
@ -529,22 +528,6 @@ const configureNotifications = async (onProcessNotifications?: () => void): Prom
}
};
/**
* Validates whether the provided GroundControl URI is valid by pinging it.
*
* @param uri {string}
* @returns {Promise<boolean>} TRUE if valid, FALSE otherwise
*/
export const isGroundControlUriValid = async (uri: string) => {
try {
const response = await fetch(`${uri}/ping`, { headers: _getHeaders() });
const json = await response.json();
return !!json.description;
} catch (_) {
return false;
}
};
export const isNotificationsCapable = hasGmsSync() || hasHmsSync() || Platform.OS !== 'android';
export const getPushToken = async (): Promise<TPushToken> => {
@ -676,38 +659,6 @@ export const removeAllDeliveredNotifications = () => {
Notifications.removeAllDeliveredNotifications();
};
export const getDefaultUri = () => {
return groundControlUri;
};
export const saveUri = async (uri: string) => {
try {
baseURI = uri || groundControlUri;
await AsyncStorage.setItem(GROUNDCONTROL_BASE_URI, baseURI);
} catch (error) {
console.error('Error saving URI:', error);
throw error;
}
};
export const getSavedUri = async () => {
try {
const baseUriStored = await AsyncStorage.getItem(GROUNDCONTROL_BASE_URI);
if (baseUriStored) {
baseURI = baseUriStored;
}
return baseUriStored;
} catch (e) {
console.error(e);
try {
await AsyncStorage.setItem(GROUNDCONTROL_BASE_URI, groundControlUri);
} catch (storageError) {
console.error('Failed to reset URI:', storageError);
}
throw e;
}
};
export const isNotificationsEnabled = async () => {
try {
const levels = await getLevels();
@ -757,10 +708,6 @@ export const initializeNotifications = async (onProcessNotifications?: () => voi
return;
}
const baseUriStored = await AsyncStorage.getItem(GROUNDCONTROL_BASE_URI);
baseURI = baseUriStored || groundControlUri;
console.log('Base URI set to:', baseURI);
setApplicationIconBadgeNumber(0);
// Only check permissions, never request
@ -781,7 +728,5 @@ export const initializeNotifications = async (onProcessNotifications?: () => voi
}
} catch (error) {
console.error('Failed to initialize notifications:', error);
baseURI = groundControlUri;
await AsyncStorage.setItem(GROUNDCONTROL_BASE_URI, groundControlUri).catch(err => console.error('Failed to reset URI:', err));
}
};

View File

@ -1,20 +0,0 @@
import assert from 'assert';
import { isGroundControlUriValid } from '../../blue_modules/notifications';
// Notifications.default = new Notifications();
describe('notifications', () => {
// yeah, lets rely less on external services...
// eslint-disable-next-line jest/no-disabled-tests
it.skip('can check groundcontrol server uri validity', async () => {
assert.ok(await isGroundControlUriValid('https://groundcontrol.bluewallet.io/'));
assert.ok(!(await isGroundControlUriValid('https://www.google.com')));
await new Promise(resolve => setTimeout(resolve, 2000));
});
// muted because it causes jest to hang waiting indefinitely
// eslint-disable-next-line jest/no-disabled-tests
it.skip('can check non-responding url', async () => {
assert.ok(!(await isGroundControlUriValid('https://localhost.com')));
});
});