Skip to content

Commit

Permalink
100% offline mode
Browse files Browse the repository at this point in the history
  • Loading branch information
trashhalo committed Jun 3, 2022
1 parent 6cf8ca8 commit afce866
Show file tree
Hide file tree
Showing 229 changed files with 4,799 additions and 186 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@ jobs:
run: |
npm install -g yarn
yarn
yarn workspace @summarizer/worker build
yarn workspace @summarizer/logseq build
yarn build
mkdir ${{ env.PLUGIN_NAME }}
cp README.md logseq/package.json logseq/icon.png logseq/demo.gif ${{ env.PLUGIN_NAME }}
cp README.md logseq/icon.png logseq/demo.gif ${{ env.PLUGIN_NAME }}
mv logseq/dist ${{ env.PLUGIN_NAME }}
zip -r ${{ env.PLUGIN_NAME }}.zip ${{ env.PLUGIN_NAME }}
ls
Expand Down
27 changes: 24 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
node_modules/
yarn-error.log
.DS_store
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "sumy"]
path = sumy
url = [email protected]:miso-belica/sumy.git
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ Super WIP!!! May not work
## Development

1. yarn
2. yarn workspace @summarizer/worker build
3. yarn workspace @summarizer/logseq build
4. Load the unpacked plugin
2. yarn build
3. Load the unpacked plugin from `dist`

## Icon

Expand Down
File renamed without changes
File renamed without changes.
19 changes: 15 additions & 4 deletions logseq/index.js → index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import "@logseq/libs";
import createWorker from "@summarizer/worker";
import PromiseWorker from "promise-worker";
import InlineWorker from "./worker.js?worker&inline";
import wheels from "./wheels";

const showError = (err) => {
logseq.App.showMsg(err.toString(), "error");
Expand All @@ -25,13 +27,22 @@ const settingsSchema = [
];

let worker;
async function main() {
worker = new PromiseWorker(new InlineWorker());

function main() {
worker = createWorker();
await worker.postMessage({
type: "init",
urls: {
pyodide: logseq.resolveResourceFullUrl("pyodide/pyodide.js"),
punkt: logseq.resolveResourceFullUrl("punkt.zip"),
},
wheels: wheels.map((wheel) =>
logseq.resolveResourceFullUrl(`wheels/${wheel}`)
),
});

logseq.Editor.registerSlashCommand("Summary", async () => {
try {
console.log("settings", logseq.settings);
const { language, numberOfSentences } = logseq.settings;
const { content, uuid } = await logseq.Editor.getCurrentBlock();
const summary = await worker.postMessage({
Expand Down
24 changes: 0 additions & 24 deletions logseq/.gitignore

This file was deleted.

10 changes: 0 additions & 10 deletions logseq/dist/assets/index.8e3ea1aa.js

This file was deleted.

13 changes: 0 additions & 13 deletions logseq/dist/index.html

This file was deleted.

21 changes: 0 additions & 21 deletions logseq/package.json

This file was deleted.

28 changes: 20 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
{
"name": "@summarizer/monorepo",
"version": "0.0.0",
"private": true,
"license": "MIT",
"workspaces": [
"worker",
"logseq"
]
"name": "logseq-summarizer",
"version": "0.0.2",
"main": "index.html",
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview"
},
"devDependencies": {
"vite": "^2.9.9",
"vite-plugin-compile-time": "^0.1.2"
},
"dependencies": {
"@logseq/libs": "^0.0.6",
"promise-worker": "^2.0.1"
},
"logseq": {
"id": "_trashhalo-logseq-summarizer",
"icon": "./icon.png"
}
}
File renamed without changes
1 change: 1 addition & 0 deletions public/package.json
Binary file added public/punkt.zip
Binary file not shown.
Binary file added public/pyodide/CLAPACK-3.2.1.zip
Binary file not shown.
Binary file added public/pyodide/Jinja2-3.1.1-py3-none-any.whl
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added public/pyodide/Pygments-2.11.2-py3-none-any.whl
Binary file not shown.
Binary file not shown.
Binary file added public/pyodide/asciitree-0.3.3-py3-none-any.whl
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added public/pyodide/attrs-21.4.0-py2.py3-none-any.whl
Binary file not shown.
Binary file added public/pyodide/autograd-1.4-py3-none-any.whl
Binary file not shown.
Binary file added public/pyodide/autograd-tests.tar
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added public/pyodide/bleach-5.0.0-py3-none-any.whl
Binary file not shown.
Binary file added public/pyodide/bokeh-2.4.2-py3-none-any.whl
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added public/pyodide/cloudpickle-2.0.0-py3-none-any.whl
Binary file not shown.
Binary file added public/pyodide/cmyt-1.0.4-py3-none-any.whl
Binary file not shown.
Binary file added public/pyodide/cmyt-tests.tar
Binary file not shown.
Binary file not shown.
168 changes: 168 additions & 0 deletions public/pyodide/console.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<script src="https://cdn.jsdelivr.net/npm/jquery"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/js/jquery.terminal.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/js/unix_formatting.min.js"></script>
<link
href="https://cdn.jsdelivr.net/npm/[email protected]/css/jquery.terminal.min.css"
rel="stylesheet"
/>
<script src="./pyodide.js"></script>
<style>
.terminal {
--size: 1.5;
--color: rgba(255, 255, 255, 0.8);
}
</style>
</head>
<body>
<script>
"use strict";
function sleep(s) {
return new Promise((resolve) => setTimeout(resolve, s));
}

async function main() {
globalThis.pyodide = await loadPyodide();
let namespace = pyodide.globals.get("dict")();
pyodide.runPython(
`
import sys
from pyodide import to_js
from pyodide.console import PyodideConsole, repr_shorten, BANNER
import __main__
BANNER = "Welcome to the Pyodide terminal emulator 🐍\\n" + BANNER
pyconsole = PyodideConsole(__main__.__dict__)
import builtins
async def await_fut(fut):
res = await fut
if res is not None:
builtins._ = res
return to_js([res], depth=1)
def clear_console():
pyconsole.buffer = []
`,
{ globals: namespace }
);
let repr_shorten = namespace.get("repr_shorten");
let banner = namespace.get("BANNER");
let await_fut = namespace.get("await_fut");
let pyconsole = namespace.get("pyconsole");
let clear_console = namespace.get("clear_console");
namespace.destroy();

let ps1 = ">>> ",
ps2 = "... ";

async function lock() {
let resolve;
let ready = term.ready;
term.ready = new Promise((res) => (resolve = res));
await ready;
return resolve;
}

async function interpreter(command) {
let unlock = await lock();
term.pause();
// multiline should be split (useful when pasting)
for (const c of command.split("\n")) {
let fut = pyconsole.push(c);
term.set_prompt(fut.syntax_check === "incomplete" ? ps2 : ps1);
switch (fut.syntax_check) {
case "syntax-error":
term.error(fut.formatted_error.trimEnd());
continue;
case "incomplete":
continue;
case "complete":
break;
default:
throw new Error(`Unexpected type ${ty}`);
}
// In JavaScript, await automatically also awaits any results of
// awaits, so if an async function returns a future, it will await
// the inner future too. This is not what we want so we
// temporarily put it into a list to protect it.
let wrapped = await_fut(fut);
// complete case, get result / error and print it.
try {
let [value] = await wrapped;
if (value !== undefined) {
term.echo(
repr_shorten.callKwargs(value, {
separator: "\n[[;orange;]<long output truncated>]\n",
})
);
}
if (pyodide.isPyProxy(value)) {
value.destroy();
}
} catch (e) {
if (e.constructor.name === "PythonError") {
const message = fut.formatted_error || e.message;
term.error(message.trimEnd());
} else {
throw e;
}
} finally {
fut.destroy();
wrapped.destroy();
}
}
term.resume();
await sleep(10);
unlock();
}

let term = $("body").terminal(interpreter, {
greetings: banner,
prompt: ps1,
completionEscape: false,
completion: function (command, callback) {
callback(pyconsole.complete(command).toJs()[0]);
},
keymap: {
"CTRL+C": async function (event, original) {
clear_console();
term.enter();
term.echo("KeyboardInterrupt");
term.set_command("");
term.set_prompt(ps1);
},
TAB: (event, original) => {
const command = term.before_cursor();
// Disable completion for whitespaces.
if (command.trim() === "") {
term.insert("\t");
return false;
}
return original(event);
},
},
});
window.term = term;
pyconsole.stdout_callback = (s) => term.echo(s, { newline: false });
pyconsole.stderr_callback = (s) => {
term.error(s.trimEnd());
};
term.ready = Promise.resolve();
pyodide._api.on_fatal = async (e) => {
term.error(
"Pyodide has suffered a fatal error. Please report this to the Pyodide maintainers."
);
term.error("The cause of the fatal error was:");
term.error(e);
term.error("Look in the browser console for more details.");
await term.ready;
term.pause();
await sleep(15);
term.pause();
};
}
window.console_ready = main();
</script>
</body>
</html>
Binary file added public/pyodide/cpp-exceptions-test-0.1.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added public/pyodide/cycler-0.11.0-py3-none-any.whl
Binary file not shown.
Binary file not shown.
Binary file added public/pyodide/cytoolz-tests.tar
Binary file not shown.
Binary file added public/pyodide/decorator-5.1.1-py3-none-any.whl
Binary file not shown.
Binary file not shown.
Binary file added public/pyodide/distutils.tar
Binary file not shown.
Binary file not shown.
Binary file added public/pyodide/fonts/DejaVuSans-Bold.ttf
Binary file not shown.
Binary file added public/pyodide/fonts/DejaVuSans-BoldOblique.ttf
Binary file not shown.
Binary file added public/pyodide/fonts/DejaVuSans-Oblique.ttf
Binary file not shown.
Binary file added public/pyodide/fonts/DejaVuSans.ttf
Binary file not shown.
Binary file added public/pyodide/fonts/DejaVuSansDisplay.ttf
Binary file not shown.
Binary file added public/pyodide/fonts/DejaVuSansMono-Bold.ttf
Binary file not shown.
Binary file not shown.
Binary file added public/pyodide/fonts/DejaVuSansMono-Oblique.ttf
Binary file not shown.
Binary file added public/pyodide/fonts/DejaVuSansMono.ttf
Binary file not shown.
Binary file added public/pyodide/fonts/DejaVuSerif-Bold.ttf
Binary file not shown.
Binary file added public/pyodide/fonts/DejaVuSerif-BoldItalic.ttf
Binary file not shown.
Binary file added public/pyodide/fonts/DejaVuSerif-Italic.ttf
Binary file not shown.
Binary file added public/pyodide/fonts/DejaVuSerif.ttf
Binary file not shown.
Binary file added public/pyodide/fonts/DejaVuSerifDisplay.ttf
Binary file not shown.
Binary file added public/pyodide/fonts/Humor-Sans.ttf
Binary file not shown.
Loading

0 comments on commit afce866

Please sign in to comment.