kui-shell
Version:
This is the monorepo for Kui, the hybrid command-line/GUI electron-based Kubernetes tool
124 lines • 5.73 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const debug_1 = require("debug");
const debug = debug_1.default('webapp/bootstrap/init');
debug('loading');
const events_1 = require("../../core/events");
const nope = (event) => {
event.preventDefault();
return false;
};
const disableDragAndDrop = () => {
debug('disableDragAndDrop');
document.addEventListener('dragover', nope, false);
document.addEventListener('drop', nope, false);
};
function setDefaultCommandContext() {
return __awaiter(this, void 0, void 0, function* () {
const { extractSearchKey } = yield Promise.resolve().then(() => require('../util/search'));
const contextString = process.env.KUI_CONTEXT ||
(typeof window !== 'undefined' && window.location && window.location.search && extractSearchKey('command-context'));
if (contextString) {
try {
const context = JSON.parse(contextString);
const { setDefaultCommandContext: setDefault } = yield Promise.resolve().then(() => require('../../commands/context'));
setDefault(context);
return;
}
catch (err) {
debug('Error parsing KUI_CONTEXT', err);
}
}
});
}
exports.init = () => __awaiter(void 0, void 0, void 0, function* () {
debug('init');
const Capabilities = Promise.resolve().then(() => require('../../core/capabilities'));
const waitForThese = [];
debug('window init');
events_1.default.emit('/window/init');
disableDragAndDrop();
waitForThese.push(setDefaultCommandContext());
window.addEventListener('beforeunload', () => {
events_1.default.emit('/window/reload');
});
waitForThese.push(Promise.resolve().then(() => require('../themes/init')).then(_ => _.default()));
yield Promise.all(waitForThese);
if ((yield Capabilities).inElectron()) {
debug('setting up /init/done handler');
events_1.default.once('/init/done', () => __awaiter(void 0, void 0, void 0, function* () {
debug('got /init/done');
const { remote } = yield Promise.resolve().then(() => require('electron'));
const electronWindow = remote.getCurrentWindow();
const prefs = electronWindow.subwindow;
const argv = electronWindow['executeThisArgvPlease'];
const maybeExecuteThis = argv && argv.length > 0 ? argv : undefined;
const fullShell = maybeExecuteThis && maybeExecuteThis.length === 1 && maybeExecuteThis[0] === 'shell';
if (maybeExecuteThis && !fullShell) {
const command = typeof maybeExecuteThis === 'string' ? maybeExecuteThis : maybeExecuteThis.join(' ');
debug('maybeExecuteThis', maybeExecuteThis, command);
if (prefs && prefs.partialExec) {
const { partial } = yield Promise.resolve().then(() => require('../prompt'));
partial(command);
}
else {
const { pexec } = yield Promise.resolve().then(() => require('../../repl/exec'));
const noEcho = prefs && prefs.noEcho;
pexec(command, Object.assign(prefs || {}, {
causedByHeadless: true,
echo: !noEcho
})).then(() => {
});
}
}
}));
}
debug('init done');
});
exports.preinit = () => __awaiter(void 0, void 0, void 0, function* () {
debug('preinit');
let prefs = {};
if (process.env.___IBM_FSH_FUZZ) {
try {
prefs = yield (yield Promise.resolve().then(() => require('../../core/fuzz-testing'))).default(process.env.___IBM_FSH_FUZZ);
}
catch (err) {
debug('fuzz testing raw', process.env.___IBM_FSH_FUZZ);
console.error('Error parsing fuzz testing prefs', err);
}
debug('parsed fuzz testing config', prefs);
}
document.body.classList.add(`os-${process.platform}`);
try {
const { remote } = yield Promise.resolve().then(() => require('electron'));
const window = remote && remote.getCurrentWindow();
const subwindow = window.subwindow;
if (subwindow && subwindow.fullscreen !== false) {
const titleOverride = typeof subwindow === 'string' ? subwindow : subwindow.title;
if (titleOverride && typeof titleOverride === 'string') {
document.title = titleOverride;
}
if (subwindow.viewName) {
document.body.setAttribute('data-view-name', subwindow.viewName);
}
document.body.classList.add('subwindow');
if (subwindow.theme)
document.body.classList.add(`theme-${subwindow.theme}`);
return subwindow;
}
}
catch (err) {
debug('no electron');
}
return prefs;
});
//# sourceMappingURL=init.js.map