mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-22 09:32:41 +00:00
Resolve "Error: Database not created"
This commit is contained in:
@@ -18,10 +18,10 @@ import {App, URLOpenListenerEvent} from '@capacitor/app';
|
|||||||
import {Platform, ToastController} from '@ionic/angular';
|
import {Platform, ToastController} from '@ionic/angular';
|
||||||
import {SettingsProvider} from './modules/settings/settings.provider';
|
import {SettingsProvider} from './modules/settings/settings.provider';
|
||||||
import {AuthHelperService} from './modules/auth/auth-helper.service';
|
import {AuthHelperService} from './modules/auth/auth-helper.service';
|
||||||
import {ScheduleSyncService} from './modules/background/schedule/schedule-sync.service';
|
|
||||||
import {environment} from '../environments/environment';
|
import {environment} from '../environments/environment';
|
||||||
import {StatusBar, Style} from '@capacitor/status-bar';
|
import {StatusBar, Style} from '@capacitor/status-bar';
|
||||||
import {Capacitor} from '@capacitor/core';
|
import {Capacitor} from '@capacitor/core';
|
||||||
|
import {ScheduleSyncService} from './modules/background/schedule/schedule-sync.service';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO
|
* TODO
|
||||||
@@ -53,7 +53,6 @@ export class AppComponent implements AfterContentInit {
|
|||||||
* @param zone The angular zone
|
* @param zone The angular zone
|
||||||
* @param authHelper Helper service for OAuth providers
|
* @param authHelper Helper service for OAuth providers
|
||||||
* @param toastController Toast controller
|
* @param toastController Toast controller
|
||||||
* @param scheduleSync TODO
|
|
||||||
*/
|
*/
|
||||||
constructor(
|
constructor(
|
||||||
private readonly platform: Platform,
|
private readonly platform: Platform,
|
||||||
@@ -62,13 +61,14 @@ export class AppComponent implements AfterContentInit {
|
|||||||
private readonly zone: NgZone,
|
private readonly zone: NgZone,
|
||||||
private readonly authHelper: AuthHelperService,
|
private readonly authHelper: AuthHelperService,
|
||||||
private readonly toastController: ToastController,
|
private readonly toastController: ToastController,
|
||||||
private readonly scheduleSync: ScheduleSyncService,
|
private readonly scheduleSyncService: ScheduleSyncService,
|
||||||
) {
|
) {
|
||||||
void this.initializeApp();
|
void this.initializeApp();
|
||||||
}
|
}
|
||||||
|
|
||||||
ngAfterContentInit() {
|
ngAfterContentInit(): void {
|
||||||
void this.scheduleSync.enable();
|
this.scheduleSyncService.init();
|
||||||
|
void this.scheduleSyncService.enable();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -86,10 +86,10 @@ export class AppComponent implements AfterContentInit {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
this.platform.ready().then(async () => {
|
this.platform.ready().then(async () => {
|
||||||
await this.authInit();
|
|
||||||
if (Capacitor.isNativePlatform()) {
|
if (Capacitor.isNativePlatform()) {
|
||||||
await StatusBar.setStyle({style: Style.Dark});
|
await StatusBar.setStyle({style: Style.Dark});
|
||||||
}
|
}
|
||||||
|
await this.authInit();
|
||||||
|
|
||||||
// set order of categories in settings
|
// set order of categories in settings
|
||||||
this.settingsProvider.setCategoriesOrder([
|
this.settingsProvider.setCategoriesOrder([
|
||||||
|
|||||||
@@ -60,7 +60,6 @@ import {DebugDataCollectorService} from './modules/data/debug-data-collector.ser
|
|||||||
import {Browser} from './util/browser.factory';
|
import {Browser} from './util/browser.factory';
|
||||||
import {browserFactory} from './util/browser.factory';
|
import {browserFactory} from './util/browser.factory';
|
||||||
import {AuthModule} from './modules/auth/auth.module';
|
import {AuthModule} from './modules/auth/auth.module';
|
||||||
import {ScheduleSyncService} from './modules/background/schedule/schedule-sync.service';
|
|
||||||
import {BackgroundModule} from './modules/background/background.module';
|
import {BackgroundModule} from './modules/background/background.module';
|
||||||
import {LibraryModule} from './modules/library/library.module';
|
import {LibraryModule} from './modules/library/library.module';
|
||||||
import {StorageProvider} from './modules/storage/storage.provider';
|
import {StorageProvider} from './modules/storage/storage.provider';
|
||||||
@@ -190,7 +189,6 @@ export function createTranslateLoader(http: HttpClient) {
|
|||||||
SettingsProvider,
|
SettingsProvider,
|
||||||
ConfigProvider,
|
ConfigProvider,
|
||||||
TranslateService,
|
TranslateService,
|
||||||
ScheduleSyncService,
|
|
||||||
],
|
],
|
||||||
useFactory: initializerFactory,
|
useFactory: initializerFactory,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ import {hashStringToInt} from './hash';
|
|||||||
import {
|
import {
|
||||||
CALENDAR_NOTIFICATIONS_ENABLED_KEY,
|
CALENDAR_NOTIFICATIONS_ENABLED_KEY,
|
||||||
CALENDAR_SYNC_ENABLED_KEY,
|
CALENDAR_SYNC_ENABLED_KEY,
|
||||||
CALENDAR_SYNC_SETTINGS_KEY,
|
getCalendarSetting,
|
||||||
} from '../../settings/page/calendar-sync-settings-keys';
|
} from '../../settings/page/calendar-sync-settings-keys';
|
||||||
import {filter} from 'rxjs/operators';
|
import {filter} from 'rxjs/operators';
|
||||||
import {Capacitor} from '@capacitor/core';
|
import {Capacitor} from '@capacitor/core';
|
||||||
@@ -49,7 +49,9 @@ export class ScheduleSyncService implements OnDestroy {
|
|||||||
private dateFormatPipe: DateFormatPipe,
|
private dateFormatPipe: DateFormatPipe,
|
||||||
private durationFormatPipe: DurationPipe,
|
private durationFormatPipe: DurationPipe,
|
||||||
private calendar: CalendarService,
|
private calendar: CalendarService,
|
||||||
) {
|
) {}
|
||||||
|
|
||||||
|
init() {
|
||||||
this.scheduleProvider.uuids$
|
this.scheduleProvider.uuids$
|
||||||
.pipe(filter(uuids => uuids?.length > 0))
|
.pipe(filter(uuids => uuids?.length > 0))
|
||||||
.subscribe(uuids => {
|
.subscribe(uuids => {
|
||||||
@@ -67,14 +69,13 @@ export class ScheduleSyncService implements OnDestroy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async isSyncEnabled(): Promise<boolean> {
|
private async isSyncEnabled(): Promise<boolean> {
|
||||||
return await this.storageProvider.get(
|
return getCalendarSetting(this.storageProvider, CALENDAR_SYNC_ENABLED_KEY);
|
||||||
`${CALENDAR_SYNC_SETTINGS_KEY}.${CALENDAR_SYNC_ENABLED_KEY}`,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async isNotificationsEnabled(): Promise<boolean> {
|
private async isNotificationsEnabled(): Promise<boolean> {
|
||||||
return await this.storageProvider.get(
|
return getCalendarSetting(
|
||||||
`${CALENDAR_SYNC_SETTINGS_KEY}.${CALENDAR_NOTIFICATIONS_ENABLED_KEY}`,
|
this.storageProvider,
|
||||||
|
CALENDAR_NOTIFICATIONS_ENABLED_KEY,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,9 +85,10 @@ export class ScheduleSyncService implements OnDestroy {
|
|||||||
await BackgroundFetch.stop();
|
await BackgroundFetch.stop();
|
||||||
|
|
||||||
if (
|
if (
|
||||||
[this.isSyncEnabled, this.isNotificationsEnabled].some(
|
[
|
||||||
async it => await it(),
|
this.isSyncEnabled.bind(this),
|
||||||
)
|
this.isNotificationsEnabled.bind(this),
|
||||||
|
].some(async it => await it())
|
||||||
) {
|
) {
|
||||||
const status = await BackgroundFetch.configure(
|
const status = await BackgroundFetch.configure(
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -13,9 +13,33 @@
|
|||||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import {StorageProvider} from '../../storage/storage.provider';
|
||||||
|
|
||||||
export const CALENDAR_SYNC_SETTINGS_KEY = 'calendarSettings';
|
export const CALENDAR_SYNC_SETTINGS_KEY = 'calendarSettings';
|
||||||
export const CALENDAR_SYNC_ENABLED_KEY = 'sync';
|
export const CALENDAR_SYNC_ENABLED_KEY = 'sync';
|
||||||
export const CALENDAR_NOTIFICATIONS_ENABLED_KEY = 'notifications';
|
export const CALENDAR_NOTIFICATIONS_ENABLED_KEY = 'notifications';
|
||||||
export type CALENDAR_SYNC_KEYS =
|
export type CALENDAR_SYNC_KEYS =
|
||||||
| typeof CALENDAR_SYNC_ENABLED_KEY
|
| typeof CALENDAR_SYNC_ENABLED_KEY
|
||||||
| typeof CALENDAR_NOTIFICATIONS_ENABLED_KEY;
|
| typeof CALENDAR_NOTIFICATIONS_ENABLED_KEY;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
export async function getCalendarSetting(
|
||||||
|
storageProvider: StorageProvider,
|
||||||
|
key: CALENDAR_SYNC_KEYS,
|
||||||
|
defaultValue = false,
|
||||||
|
): Promise<boolean> {
|
||||||
|
try {
|
||||||
|
return await storageProvider.get<boolean>(calendarSettingStorageKey(key));
|
||||||
|
} catch {
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
export function calendarSettingStorageKey(key: string): string {
|
||||||
|
return `${CALENDAR_SYNC_SETTINGS_KEY}.${key}`;
|
||||||
|
}
|
||||||
|
|||||||
@@ -33,7 +33,8 @@ import {
|
|||||||
CALENDAR_NOTIFICATIONS_ENABLED_KEY,
|
CALENDAR_NOTIFICATIONS_ENABLED_KEY,
|
||||||
CALENDAR_SYNC_ENABLED_KEY,
|
CALENDAR_SYNC_ENABLED_KEY,
|
||||||
CALENDAR_SYNC_KEYS,
|
CALENDAR_SYNC_KEYS,
|
||||||
CALENDAR_SYNC_SETTINGS_KEY,
|
calendarSettingStorageKey,
|
||||||
|
getCalendarSetting,
|
||||||
} from './calendar-sync-settings-keys';
|
} from './calendar-sync-settings-keys';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
@@ -71,10 +72,11 @@ export class CalendarSyncSettingsComponent implements OnInit {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getSetting(key: CALENDAR_SYNC_KEYS) {
|
async getSetting(
|
||||||
return (await this.storageProvider.get(
|
key: CALENDAR_SYNC_KEYS,
|
||||||
`${CALENDAR_SYNC_SETTINGS_KEY}.${key}`,
|
defaultValue = false,
|
||||||
)) as boolean;
|
): Promise<boolean> {
|
||||||
|
return getCalendarSetting(this.storageProvider, key, defaultValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
async syncCalendar(sync: boolean) {
|
async syncCalendar(sync: boolean) {
|
||||||
@@ -98,10 +100,7 @@ export class CalendarSyncSettingsComponent implements OnInit {
|
|||||||
async setSetting(settings: Partial<Record<CALENDAR_SYNC_KEYS, boolean>>) {
|
async setSetting(settings: Partial<Record<CALENDAR_SYNC_KEYS, boolean>>) {
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
map(settings, (setting, key) =>
|
map(settings, (setting, key) =>
|
||||||
this.storageProvider.put(
|
this.storageProvider.put(calendarSettingStorageKey(key), setting),
|
||||||
`${CALENDAR_SYNC_SETTINGS_KEY}.${key}`,
|
|
||||||
setting,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user