looper/web/api.js

55 lines
1.4 KiB
JavaScript
Raw Normal View History

2024-04-24 09:59:51 -07:00
addToLibrary({
open_filepicker: function() {
window.filePicker.show();
},
set_filter: function(filter) {
window.filePicker.setFilter(Module.UTF8ToString(filter));
},
file_picker_confirmed: function() {
return window.filePicker.wasConfirmed();
},
file_picker_closed: function() {
return window.filePicker.wasClosed();
},
file_picker_cancelled: function() {
return window.filePicker.wasCancelled();
},
get_first_file: function() {
if (window.filePicker.wasConfirmed()) {
let output = window.filePicker.getFirstFile();
let len = Module.lengthBytesUTF8(output) + 1;
let outptr = Module._malloc(len);
for (let i = 0; i < len; i++) {
setValue(outptr + i, 0, 'i8');
}
Module.stringToUTF8(output, outptr, len);
return outptr;
} else {
return 0;
}
},
file_picker_visible: function() {
return window.filePicker.visible;
},
file_picker_loading: function() {
return window.filePicker.loading;
},
clear_file_selection: function() {
window.filePicker.clearSelection();
},
get_size: function(x, y) {
let canvas = document.getElementById("canvas");
setValue(x, canvas.offsetWidth, "i32");
setValue(y, canvas.offsetHeight, "i32");
},
is_puter_enabled: function() {
return window.filePicker.puterEnabled;
},
enable_puter: function(enable) {
window.filePicker.puterEnabled = enable;
},
quit: function() {
puter.ui.exit();
}
})