@nativescript-community/flipper
Version:
A desktop debugging platform for mobile developers.
120 lines • 6.3 kB
JavaScript
import { ClientBase } from './flipper.common';
import { Application } from '@nativescript/core';
var Client = /** @class */ (function (_super) {
__extends(Client, _super);
function Client() {
return _super !== null && _super.apply(this, arguments) || this;
}
Client.prototype.runInit = function () {
var context = Application.android.context;
if (context) {
if (com.facebook.flipper.android.utils.FlipperUtils.shouldEnableFlipper(context)) {
com.facebook.soloader.SoLoader.init(context, false);
var client_1 = (this._client = com.facebook.flipper.android.AndroidFlipperClient.getInstance(context));
var plugins = (this.config && this.config.plugins) || [];
plugins.forEach(function (s) {
if (!(typeof s === 'string') && s.install) {
try {
s.install(client_1);
return;
}
catch (err) {
console.error(err);
}
}
switch (s) {
case 'network':
var plugin = new com.facebook.flipper.plugins.network.NetworkFlipperPlugin();
client_1.addPlugin(plugin);
try {
var addNetworkInterceptor = require('@nativescript-community/https').addNetworkInterceptor;
addNetworkInterceptor(new com.facebook.flipper.plugins.network.FlipperOkhttpInterceptor(plugin));
}
catch (err) {
console.error('error installing network plugin', err);
}
break;
case 'layout':
client_1.addPlugin(new com.facebook.flipper.plugins.inspector.InspectorFlipperPlugin(context, com.facebook.flipper.plugins.inspector.DescriptorMapping.withDefaults()));
break;
case 'database':
client_1.addPlugin(new com.facebook.flipper.plugins.databases.DatabasesFlipperPlugin(context));
break;
case 'prefs':
client_1.addPlugin(new com.facebook.flipper.plugins.sharedpreferences.SharedPreferencesFlipperPlugin(context, 'prefs.db'));
break;
case 'crash':
client_1.addPlugin(com.facebook.flipper.plugins.crashreporter.CrashReporterPlugin.getInstance());
break;
case 'image':
//@ts-ignore
var leakTracker = new com.facebook.imagepipeline.debug.FlipperCloseableReferenceLeakTracker();
try {
var initialize = require('@nativescript-community/ui-image').initialize;
initialize({ leakTracker: leakTracker });
}
catch (err) {
console.error('error installing image plugin', err);
}
//@ts-ignore
client_1.addPlugin(new com.facebook.flipper.plugins.fresco.FrescoFlipperPlugin(
//@ts-ignore
new com.facebook.imagepipeline.debug.FlipperImageTracker(),
//@ts-ignore
com.facebook.drawee.backends.pipeline.Fresco.getImagePipelineFactory().getPlatformBitmapFactory(), null, new com.facebook.common.memory.manager.NoOpDebugMemoryManager(), new com.facebook.flipper.perflogger.NoOpFlipperPerfLogger(), null, leakTracker));
break;
case 'leakCanary':
try {
//@ts-ignore
var config = leakcanary.LeakCanary.getConfig().newBuilder()
//@ts-ignore
.onHeapAnalyzedListener(new com.facebook.flipper.plugins.leakcanary2.FlipperLeakListener())
.build();
//@ts-ignore
leakcanary.LeakCanary.setConfig(config);
}
catch (err) {
console.error('error installing leak plugin', err);
}
//@ts-ignore
client_1.addPlugin(new com.facebook.flipper.plugins.leakcanary2.LeakCanary2FlipperPlugin());
break;
case 'navigation':
// client.addPlugin(com.facebook.flipper.plugins.navigation.NavigationFlipperPlugin.getInstance());
break;
}
});
client_1.start();
}
}
};
Client.prototype.start = function (conf) {
var _this = this;
if (!this._client) {
this.config = conf;
return new Promise(function (resolve, reject) {
var onLaunched = function () {
try {
Application.off(Application.launchEvent, onLaunched);
_this.runInit();
resolve(_this._client);
}
catch (ex) {
console.log('Error in Flipper.init: ' + ex);
reject(ex);
}
};
if (Application.android.nativeApp) {
onLaunched();
}
else {
Application.on(Application.launchEvent, onLaunched);
}
});
}
return Promise.resolve(this._client);
};
return Client;
}(ClientBase));
export { Client };
//# sourceMappingURL=flipper.android.js.map