Object.defineProperty(exports, "__esModule", { value: true });
exports.MainClient = void 0;
var tslib_1 = require("tslib");
var core_1 = require("@sentry/core");
var utils_1 = require("@sentry/utils");
var backend_1 = require("./backend");
var context_1 = require("./context");
var normalize_1 = require("./normalize");
/** Frontend implementation for Electron renderer backends. */
var MainClient = /** @class */ (function (_super) {
    tslib_1.__extends(MainClient, _super);
    /**
     * Creates a new Electron SDK instance.
     * @param options Configuration options for this SDK.
     */
    function MainClient(options) {
        return _super.call(this, backend_1.MainBackend, options) || this;
    }
    /**
     * Uploads a native crash dump (Minidump) to Sentry.
     *
     * @param path The relative or absolute path to the minidump.
     * @param event Optional event payload to attach to the minidump.
     * @param scope Optional SDK scope used to upload.
     */
    MainClient.prototype.captureMinidump = function (path, event, scope) {
        var _this = this;
        if (event === void 0) { event = {}; }
        var eventId;
        this._processing += 1;
        event.tags = tslib_1.__assign({ event_type: 'native' }, event.tags);
        // We are not calling _processEvent here since we do not have beforeSend for minidump crashes
        this._prepareEvent(event, scope, undefined).then(function (finalEvent) {
            if (finalEvent) {
                eventId = finalEvent && finalEvent.event_id;
                _this._getBackend().uploadMinidump(path, finalEvent);
            }
            _this._processing -= 1;
        }, function (reason) {
            utils_1.logger.error(reason);
            _this._processing -= 1;
        });
        return eventId;
    };
    /**
     * @inheritDoc
     */
    MainClient.prototype.captureEvent = function (event, hint, scope) {
        event.tags = tslib_1.__assign({ event_type: 'javascript' }, event.tags);
        return _super.prototype.captureEvent.call(this, event, hint, scope);
    };
    /**
     * Does nothing in main/node
     */
    MainClient.prototype.showReportDialog = function (_) {
        // noop
    };
    /**
     * @inheritDoc
     */
    MainClient.prototype._prepareEvent = function (event, scope, hint) {
        var _this = this;
        event.platform = event.platform || 'node';
        return _super.prototype._prepareEvent.call(this, event, scope, hint).then(function (filledEvent) {
            return new utils_1.SyncPromise(function (resolve) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
                var _a, _b;
                return tslib_1.__generator(this, function (_c) {
                    switch (_c.label) {
                        case 0:
                            if (!filledEvent) return [3 /*break*/, 2];
                            _a = resolve;
                            _b = normalize_1.normalizeEvent;
                            return [4 /*yield*/, context_1.addEventDefaults(this._options.appName, filledEvent)];
                        case 1:
                            _a.apply(void 0, [_b.apply(void 0, [_c.sent()])]);
                            return [3 /*break*/, 3];
                        case 2:
                            resolve(filledEvent);
                            _c.label = 3;
                        case 3: return [2 /*return*/];
                    }
                });
            }); }).then(function (e) { return e; });
        });
    };
    return MainClient;
}(core_1.BaseClient));
exports.MainClient = MainClient;
//# sourceMappingURL=client.js.map