v1.5.0
AtheraStudio Code
- (function () {
- "use strict";
-
- var desktop = window.atheraDesktop;
- var A = window.Athera;
- if (!desktop || !desktop.isDesktop || !A) return;
-
- function baseName(p) {
- return String(p).split(/[\\/]/).pop();
- }
-
- function makeHandle(filePath) {
- var name = baseName(filePath);
- return {
- kind: "file",
- name: name,
- _path: filePath,
- getFile: async function () {
- var r = await desktop.readFile(filePath);
- return new File([r.data], name, { lastModified: r.mtime || Date.now() });
- },
- createWritable: async function () {
- var chunks = [];
- return {
- write: async function (d) { chunks.push(d); },
- close: async function () {
- var buf = new Uint8Array(await new Blob(chunks).arrayBuffer());
- await desktop.writeFile(filePath, buf);
- },
- abort: async function () { chunks = []; }
- };
- },
- isSameEntry: async function (other) { return !!other && other._path === filePath; },
- queryPermission: async function () { return "granted"; },
- requestPermission: async function () { return "granted"; }
- };
- }
-
- async function openFromSystem(filePath) {
- try {
- for (var t of A.tabs.list) {
- if (t.handle && t.handle._path === filePath) return A.tabs.activate(t);
- }
- var handle = makeHandle(filePath);
- var file = await handle.getFile();
- var tab = await A.tabs.openFile({ name: handle.name, handle: null, file: file });
- if (tab && tab.kind) A.tabs.retarget(tab, tab.name, undefined, handle);
- } catch (e) {
- console.error(e);
- A.ui.toast(String((e && e.message) || e), "danger");
- }
- }
-
- var chain = Promise.resolve();
- desktop.onOpenFile(function (filePath) {
- chain = chain.then(function () { return openFromSystem(filePath); });
- });
- })();
-