@ayonli/jsext
Version:
A JavaScript extension package for building strong and modern applications.
62 lines (57 loc) • 2.17 kB
JavaScript
;
Object.defineProperty(exports, '__esModule', { value: true });
var dialog_cli_util = require('./util.js');
var string = require('../../string.js');
var runtime = require('../../runtime.js');
var cli = require('../../cli.js');
var dialog_cli_question = require('./question.js');
var cli_common = require('../../cli/common.js');
function createAppleScript(message) {
return string.dedent `
tell application (path to frontmost application as text)
display dialog "${dialog_cli_util.escape(message)}" with title "Alert" buttons {"OK"} default button "OK"
end
`;
}
function createPowerShellScript(message) {
return string.dedent `
Add-Type -AssemblyName PresentationFramework
[System.Windows.MessageBox]::Show("${dialog_cli_util.escape(message)}", "Alert")
`;
}
async function alert(message, options = {}) {
if ((options === null || options === void 0 ? void 0 : options.gui) && runtime.platform() === "darwin") {
const { code, stderr } = await cli.run("osascript", [
"-e",
createAppleScript(message)
]);
if (code) {
throw new Error(stderr);
}
}
else if ((options === null || options === void 0 ? void 0 : options.gui) && (runtime.platform() === "windows" || cli_common.isWSL())) {
const { code, stderr } = await cli.powershell(createPowerShellScript(message));
if (code) {
throw new Error(stderr);
}
}
else if ((options === null || options === void 0 ? void 0 : options.gui) && (runtime.platform() === "linux" || await cli.which("zenity"))) {
const args = [
"--info",
"--title", "Alert",
"--width", "365",
];
if (message) {
args.push("--text", message);
}
const { code, stderr } = await cli.run("zenity", args);
if (code && code !== 1) {
throw new Error(stderr);
}
}
else {
await cli_common.lockStdin(() => dialog_cli_question.default(message + " [Enter] "));
}
}
exports.default = alert;
//# sourceMappingURL=alert.js.map