Gekidou Android share extension (#6803)

* Refactor app database queries to not require the app database as argument

* Android Share Extension and fix notifications prompt

* feedback review
This commit is contained in:
Elias Nahum
2022-11-30 23:18:56 +02:00
committed by GitHub
parent c1f480de31
commit 6eadc527bb
86 changed files with 4116 additions and 383 deletions

View File

@@ -9,12 +9,11 @@ import {autoUpdateTimezone} from '@actions/remote/user';
import LocalConfig from '@assets/config.json';
import {Events, Sso} from '@constants';
import {MIN_REQUIRED_VERSION} from '@constants/supported_server';
import DatabaseManager from '@database/manager';
import {DEFAULT_LOCALE, getTranslations, t} from '@i18n';
import {getServerCredentials} from '@init/credentials';
import {getLaunchPropsFromDeepLink, relaunchApp} from '@init/launch';
import * as analytics from '@managers/analytics';
import {queryAllServers} from '@queries/app/servers';
import {getAllServers} from '@queries/app/servers';
import {logError} from '@utils/log';
import type {jsAndNativeErrorHandler} from '@typings/global/error_handling';
@@ -29,8 +28,7 @@ class GlobalEventHandler {
DeviceEventEmitter.addListener(Events.CONFIG_CHANGED, this.onServerConfigChanged);
RNLocalize.addEventListener('change', async () => {
try {
const {database} = DatabaseManager.getAppDatabaseAndOperator();
const servers = await queryAllServers(database);
const servers = await getAllServers();
for (const server of servers) {
if (server.url && server.lastActiveAt > 0) {
autoUpdateTimezone(server.url);

View File

@@ -16,11 +16,12 @@ import PushNotifications from '@init/push_notifications';
import * as analytics from '@managers/analytics';
import NetworkManager from '@managers/network_manager';
import WebsocketManager from '@managers/websocket_manager';
import {queryAllServers, queryServerName} from '@queries/app/servers';
import {getAllServers, getServerDisplayName} from '@queries/app/servers';
import {getCurrentUser} from '@queries/servers/user';
import {getThemeFromState} from '@screens/navigation';
import EphemeralStore from '@store/ephemeral_store';
import {deleteFileCache, deleteFileCacheByDir} from '@utils/file';
import {isMainActivity} from '@utils/helpers';
import {addNewServer} from '@utils/server';
import type {LaunchType} from '@typings/launch';
@@ -54,10 +55,10 @@ class SessionManager {
}
init() {
this.cancelAll();
this.cancelAllSessionNotifications();
}
private cancelAll = async () => {
private cancelAllSessionNotifications = async () => {
const serverCredentials = await getAllServerCredentials();
for (const {serverUrl} of serverCredentials) {
cancelSessionNotification(serverUrl);
@@ -86,7 +87,7 @@ class SessionManager {
}
};
private scheduleAll = async () => {
private scheduleAllSessionNotifications = async () => {
if (!this.scheduling) {
this.scheduling = true;
const serverCredentials = await getAllServerCredentials();
@@ -142,17 +143,17 @@ class SessionManager {
};
private onAppStateChange = async (appState: AppStateStatus) => {
if (appState === this.previousAppState) {
if (appState === this.previousAppState || !isMainActivity()) {
return;
}
this.previousAppState = appState;
switch (appState) {
case 'active':
setTimeout(this.cancelAll, 750);
setTimeout(this.cancelAllSessionNotifications, 750);
break;
case 'inactive':
this.scheduleAll();
this.scheduleAllSessionNotifications();
break;
}
};
@@ -179,11 +180,9 @@ class SessionManager {
}
// set the onboardingViewed value to false so the launch will show the onboarding screen after all servers were removed
if (DatabaseManager.appDatabase) {
const servers = await queryAllServers(DatabaseManager.appDatabase.database);
if (!servers.length) {
await storeOnboardingViewedValue(false);
}
const servers = await getAllServers();
if (!servers.length) {
await storeOnboardingViewedValue(false);
}
relaunchApp({launchType, serverUrl, displayName}, true);
@@ -196,8 +195,7 @@ class SessionManager {
await this.terminateSession(serverUrl, false);
const activeServerUrl = await DatabaseManager.getActiveServerUrl();
const appDatabase = DatabaseManager.appDatabase?.database;
const serverDisplayName = appDatabase ? await queryServerName(appDatabase, serverUrl) : undefined;
const serverDisplayName = await getServerDisplayName(serverUrl);
await relaunchApp({launchType: Launch.Normal, serverUrl, displayName: serverDisplayName}, true);
if (activeServerUrl) {

View File

@@ -15,6 +15,7 @@ import DatabaseManager from '@database/manager';
import {getCurrentUserId} from '@queries/servers/system';
import {queryAllUsers} from '@queries/servers/user';
import {toMilliseconds} from '@utils/datetime';
import {isMainActivity} from '@utils/helpers';
import {logError} from '@utils/log';
const WAIT_TO_CLOSE = toMilliseconds({seconds: 15});
@@ -181,6 +182,8 @@ class WebsocketManager {
return;
}
const isMain = isMainActivity();
this.cancelAllConnections();
if (appState !== 'active' && !this.isBackgroundTimerRunning) {
this.isBackgroundTimerRunning = true;
@@ -195,7 +198,7 @@ class WebsocketManager {
return;
}
if (appState === 'active' && this.netConnected) { // Reopen the websockets only if there is connection
if (appState === 'active' && this.netConnected && isMain) { // Reopen the websockets only if there is connection
if (this.backgroundIntervalId) {
BackgroundTimer.clearInterval(this.backgroundIntervalId);
}
@@ -205,7 +208,9 @@ class WebsocketManager {
return;
}
this.previousAppState = appState;
if (isMain) {
this.previousAppState = appState;
}
};
private onNetStateChange = async (netState: NetInfoState) => {