MOBILE-3833 app: Avoid services in constructor
This commit is contained in:
		
							parent
							
								
									f485099a67
								
							
						
					
					
						commit
						7b41b7716c
					
				| @ -50,7 +50,7 @@ type SchemaVersionsManager = { | |||||||
| @Injectable({ providedIn: 'root' }) | @Injectable({ providedIn: 'root' }) | ||||||
| export class CoreAppProvider { | export class CoreAppProvider { | ||||||
| 
 | 
 | ||||||
|     protected db: SQLiteDB; |     protected db?: SQLiteDB; | ||||||
|     protected logger: CoreLogger; |     protected logger: CoreLogger; | ||||||
|     protected ssoAuthenticationDeferred?: PromiseDefer<void>; |     protected ssoAuthenticationDeferred?: PromiseDefer<void>; | ||||||
|     protected isKeyboardShown = false; |     protected isKeyboardShown = false; | ||||||
| @ -65,7 +65,6 @@ export class CoreAppProvider { | |||||||
| 
 | 
 | ||||||
|     constructor() { |     constructor() { | ||||||
|         this.schemaVersionsManager = new Promise(resolve => this.resolveSchemaVersionsManager = resolve); |         this.schemaVersionsManager = new Promise(resolve => this.resolveSchemaVersionsManager = resolve); | ||||||
|         this.db = CoreDB.getDB(DBNAME); |  | ||||||
|         this.logger = CoreLogger.getInstance('CoreAppProvider'); |         this.logger = CoreLogger.getInstance('CoreAppProvider'); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| @ -82,13 +81,13 @@ export class CoreAppProvider { | |||||||
|      * Initialize database. |      * Initialize database. | ||||||
|      */ |      */ | ||||||
|     async initializeDatabase(): Promise<void> { |     async initializeDatabase(): Promise<void> { | ||||||
|         await this.db.createTableFromSchema(SCHEMA_VERSIONS_TABLE_SCHEMA); |         await this.getDB().createTableFromSchema(SCHEMA_VERSIONS_TABLE_SCHEMA); | ||||||
| 
 | 
 | ||||||
|         this.resolveSchemaVersionsManager({ |         this.resolveSchemaVersionsManager({ | ||||||
|             get: async name => { |             get: async name => { | ||||||
|                 try { |                 try { | ||||||
|                     // Fetch installed version of the schema.
 |                     // Fetch installed version of the schema.
 | ||||||
|                     const entry = await this.db.getRecord<SchemaVersionsDBEntry>(SCHEMA_VERSIONS_TABLE_NAME, { name }); |                     const entry = await this.getDB().getRecord<SchemaVersionsDBEntry>(SCHEMA_VERSIONS_TABLE_NAME, { name }); | ||||||
| 
 | 
 | ||||||
|                     return entry.version; |                     return entry.version; | ||||||
|                 } catch (error) { |                 } catch (error) { | ||||||
| @ -97,7 +96,7 @@ export class CoreAppProvider { | |||||||
|                 } |                 } | ||||||
|             }, |             }, | ||||||
|             set: async (name, version) => { |             set: async (name, version) => { | ||||||
|                 await this.db.insertRecord(SCHEMA_VERSIONS_TABLE_NAME, { name, version }); |                 await this.getDB().insertRecord(SCHEMA_VERSIONS_TABLE_NAME, { name, version }); | ||||||
|             }, |             }, | ||||||
|         }); |         }); | ||||||
|     } |     } | ||||||
| @ -149,10 +148,10 @@ export class CoreAppProvider { | |||||||
|         this.logger.debug(`Migrating schema '${schema.name}' of app DB from version ${oldVersion} to ${schema.version}`); |         this.logger.debug(`Migrating schema '${schema.name}' of app DB from version ${oldVersion} to ${schema.version}`); | ||||||
| 
 | 
 | ||||||
|         if (schema.tables) { |         if (schema.tables) { | ||||||
|             await this.db.createTablesFromSchema(schema.tables); |             await this.getDB().createTablesFromSchema(schema.tables); | ||||||
|         } |         } | ||||||
|         if (schema.migrate && oldVersion > 0) { |         if (schema.migrate && oldVersion > 0) { | ||||||
|             await schema.migrate(this.db, oldVersion); |             await schema.migrate(this.getDB(), oldVersion); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         // Set installed version.
 |         // Set installed version.
 | ||||||
| @ -165,6 +164,10 @@ export class CoreAppProvider { | |||||||
|      * @return App's DB. |      * @return App's DB. | ||||||
|      */ |      */ | ||||||
|     getDB(): SQLiteDB { |     getDB(): SQLiteDB { | ||||||
|  |         if (!this.db) { | ||||||
|  |             this.db = CoreDB.getDB(DBNAME); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|         return this.db; |         return this.db; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user