UNPKG

@btfuse/core

Version:

A native-first framework for building hybdrid web-native applications

81 lines (78 loc) 2.86 kB
"use strict"; /* Copyright 2023 Breautek Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.FuseContextBuilder = void 0; const FuseAPIFactory_1 = require("./FuseAPIFactory"); const FuseContextFactory_1 = require("./FuseContextFactory"); const FuseLoggerFactory_1 = require("./FuseLoggerFactory"); const FuseLoggerLevel_1 = require("./FuseLoggerLevel"); const PlatformResolver_1 = require("./PlatformResolver"); class FuseContextBuilder { constructor() { this.$loggerFactory = null; this.$apiFactory = null; this.$platformResolver = new PlatformResolver_1.PlatformResolver(); this.$contextFactory = null; } setPlatformResolver(resolver) { this.$platformResolver = resolver; return this; } setAPIFactory(factory) { this.$apiFactory = factory; return this; } setLoggerFactory(factory) { this.$loggerFactory = factory; return this; } setContextFactory(factory) { this.$contextFactory = factory; return this; } async _isDebugMode(context) { return await context.isDebugMode(); } async build() { const platform = this.$platformResolver.resolve(); let apiFactory; if (this.$apiFactory) { apiFactory = this.$apiFactory; } else { apiFactory = new FuseAPIFactory_1.FuseAPIFactory(); } let loggerFactory; if (this.$loggerFactory) { loggerFactory = this.$loggerFactory; } else { loggerFactory = new FuseLoggerFactory_1.FuseLoggerFactory(platform); } let contextFactory = this.$contextFactory; if (contextFactory === null) { contextFactory = new FuseContextFactory_1.FuseContextFactory(); } const context = contextFactory.create(platform, apiFactory, loggerFactory.create()); const isDebugMode = await this._isDebugMode(context); const logger = context.getLogger(); logger.enableNativeBridge(isDebugMode); let level = logger.getLevel(); level |= FuseLoggerLevel_1.FuseLoggerLevel.DEBUG; logger.setLevel(level); return context; } } exports.FuseContextBuilder = FuseContextBuilder; //# sourceMappingURL=FuseContextBuilder.js.map