replace all window.prompt() with kiri.ui.prompt() for electron. open electron links in os browser

This commit is contained in:
Stewart Allen 2024-06-17 15:21:50 -04:00
commit 995b338946
6 changed files with 86 additions and 56 deletions

View file

@ -1,4 +1,4 @@
const { app, BrowserWindow } = require('electron');
const { app, shell, BrowserWindow } = require('electron');
const path = require('path');
const server = require('@gridspace/app-server');
@ -8,8 +8,8 @@ const appDir = path.join(usrDir, 'gapp');
const cnfDir = path.join(appDir, 'conf');
const logDir = path.join(appDir, 'logs');
const datDir = path.join(appDir, 'data');
const debug = process.argv.slice(2).map(v => v.replaceAll('-','')).contains('debugg');
const devel = process.argv.slice(2).map(v => v.replaceAll('-','')).contains('devel');
const debug = process.argv.slice(2).map(v => v.replaceAll('-', '')).contains('debugg');
const devel = process.argv.slice(2).map(v => v.replaceAll('-', '')).contains('devel');
// console.log({ appDir, usrDir, logDir, datDir, basDir });
// console.log({ argv: process.argv, debug, devel });
@ -21,12 +21,13 @@ const devel = process.argv.slice(2).map(v => v.replaceAll('-','')).contains('dev
// });
server({
single: true,
port: 5309,
apps: basDir,
data: datDir,
conf: cnfDir,
logs: logDir,
cache: path.join(basDir,"data","cache"),
cache: path.join(basDir, "data", "cache"),
single: true,
electron: true,
debug
});
@ -40,7 +41,12 @@ function createWindow() {
}
});
mainWindow.loadURL('http://localhost:8080/kiri');
mainWindow.loadURL('http://localhost:5309/kiri');
mainWindow.webContents.setWindowOpenHandler((details) => {
shell.openExternal(details.url);
return { action: 'deny' }
});
if (devel) {
console.log("opening developer tools");
@ -49,11 +55,13 @@ function createWindow() {
}
app.on('ready', createWindow);
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();

View file

@ -1688,12 +1688,13 @@ function createPopOp(type, map) {
const { divid, noteid } = op.note;
const div = $(divid);
if (div) div.onclick = () => {
let note = op.x = prompt('Edit Note for Operation', poppedRec.note || '');
if (note !== undefined && note !== null) {
$(noteid).innerText = poppedRec.note = note;
API.conf.save();
}
func.opRender();
API.uc.prompt('Edit Note for Operation', poppedRec.note || '').then(note => {
if (note !== undefined && note !== null) {
poppedRec.note = op.x = note;
API.conf.save();
}
func.opRender();
});
};
const note = $(noteid);
if (note) note.innerText = poppedRec.note || '';

View file

@ -537,13 +537,14 @@ gapp.register("kiri.init", [], (root, exports) => {
api.show.alert("select object to rotate");
return;
}
let coord = (prompt("Enter X,Y,Z degrees of rotation") || '').split(','),
prod = Math.PI / 180,
x = parseFloat(coord[0] || 0.0) * prod,
y = parseFloat(coord[1] || 0.0) * prod,
z = parseFloat(coord[2] || 0.0) * prod;
api.selection.rotate(x, y, z);
api.uc.prompt("Enter X,Y,Z degrees of rotation","").then(coord => {
coord = (coord || '').split(',');
let prod = Math.PI / 180,
x = parseFloat(coord[0] || 0.0) * prod,
y = parseFloat(coord[1] || 0.0) * prod,
z = parseFloat(coord[2] || 0.0) * prod;
api.selection.rotate(x, y, z);
});
}
function positionSelection() {
@ -554,18 +555,21 @@ gapp.register("kiri.init", [], (root, exports) => {
let current = settings(),
{ device, process} = current,
center = process.ctOriginCenter || process.camOriginCenter || device.bedRound || device.originCenter,
bounds = boundsSelection(),
coord = prompt("Enter X,Y coordinates for selection").split(','),
x = parseFloat(coord[0] || 0.0),
y = parseFloat(coord[1] || 0.0),
z = parseFloat(coord[2] || 0.0);
bounds = boundsSelection();
if (!center) {
x = x - device.bedWidth/2 + (bounds.max.x - bounds.min.x)/2;
y = y - device.bedDepth/2 + (bounds.max.y - bounds.min.y)/2
}
api.uc.prompt("Enter X,Y coordinates for selection","").then(coord => {
coord = (coord || '').split(',');
let x = parseFloat(coord[0] || 0.0),
y = parseFloat(coord[1] || 0.0),
z = parseFloat(coord[2] || 0.0);
api.selection.move(x, y, z, true);
if (!center) {
x = x - device.bedWidth/2 + (bounds.max.x - bounds.min.x)/2;
y = y - device.bedDepth/2 + (bounds.max.y - bounds.min.y)/2
}
api.selection.move(x, y, z, true);
});
}
function deviceExport(exp, name) {
@ -1018,8 +1022,14 @@ gapp.register("kiri.init", [], (root, exports) => {
showDevices();
};
ui.deviceRename.onclick = function() {
const newname = prompt(`Rename "${selected}`, selected);
if (newname) updateDeviceName(newname);
api.uc.prompt(`Rename "${selected}`, selected).then(newname => {
if (newname) {
updateDeviceName(newname);
showDevices();
} else {
showDevices();
}
});
};
ui.deviceExport.onclick = function(event) {
const record = {
@ -1430,12 +1440,13 @@ gapp.register("kiri.init", [], (root, exports) => {
renm.setAttribute('title', 'rename file');
renm.innerHTML = '<i class="far fa-edit"></i>';
renm.onclick = () => {
let newname = prompt(`rename file`, short);
if (newname && newname !== short) {
catalog.rename(name, `${newname}${ext}`, then => {
catalog.refresh();
});
}
api.uc.prompt(`rename file`, short).then(newname => {
if (newname && newname !== short) {
catalog.rename(name, `${newname}${ext}`, then => {
api.modal.show('files');
});
}
});
};
load.setAttribute('load', name);

View file

@ -687,19 +687,22 @@ gapp.register("kiri.main", [], (root, exports) => {
mode = getMode(),
name = e.target.getAttribute("name"),
load = current.sproc[mode][name],
edit = prompt(`settings for "${name}"`, JSON.stringify(load));
if (edit) {
try {
current.sproc[mode][name] = JSON.parse(edit);
if (name === current.proc().processName) {
api.conf.load(null, name);
loadstr = JSON.stringify(load,null,4).split('\n');
UC.prompt(`settings for "${name}"`, loadstr).then(edit => {
if (edit) {
try {
current.sproc[mode][name] = JSON.parse(edit);
if (name === settings.proc().processName) {
api.conf.load(null, name);
}
api.conf.save();
api.settings.sync.put();
} catch (e) {
console.log({ malformed_settings: e });
UC.alert('malformed settings object');
}
api.conf.save();
api.settings.sync.put();
} catch (e) {
UC.alert('malformed settings object');
}
}
});
}
function exportSettings(e) {

View file

@ -111,9 +111,12 @@ gapp.register("kiri.ui", [], (root, exports) => {
html = opt.pre.appendAll(html);
}
let iid;
if (input !== undefined) {
if (typeof(input) === 'string') {
iid = `confirm-input-${rnd}`;
html.append(`<div><input class="grow" type="text" spellcheck="false" value="${input}" id="${iid}"/></div>`);
html.append(`<div><input class="grow" type="text" spellcheck="false" id="${iid}"/></div>`);
} else if (Array.isArray(input)) {
iid = `confirm-input-${rnd}`;
html.append(`<div><textarea rows="15" cols="40" class="grow" type="text" spellcheck="false" id="${iid}"></textarea></div>`);
}
html.append(`<div class="f-row j-end">`);
Object.entries(btns).forEach((row,i) => {
@ -129,7 +132,10 @@ gapp.register("kiri.ui", [], (root, exports) => {
setTimeout(() => { resolve(value) }, 150);
}
if (iid) {
let array = Array.isArray(input);
iid = $(iid);
iid.value = array ? input.join('\n') : input;
if (!array)
iid.onkeypress = (ev) => {
if (ev.key === 'Enter' || ev.charCode === 13) {
done(ev.target.value);

View file

@ -36,12 +36,13 @@ function rename(sel) {
return;
}
let widget = widgets[0];
const newname = prompt("new widget name", widget.meta.file);
if (newname) {
widget.meta.file = newname;
api.platform.changed();
api.space.save(true);
}
kiri.ui.prompt("new widget name", widget.meta.file || "no name").then(newname => {
if (newname) {
widget.meta.file = newname;
api.platform.changed();
api.space.save(true);
}
});
}
function replace(vertices, sel) {