Update extension to set endpoint

This commit is contained in:
Dima Gerasimov 2019-01-16 22:24:10 +00:00 committed by Dmitrii Gerasimov
parent 4a0439567d
commit ec231636d1
5 changed files with 21 additions and 21 deletions

View file

@ -14,7 +14,7 @@ No third party dependencies! Just `python 3.6`.
Or alternatively, just run it directly if you don't want to autostart it: `server/grasp_server.py --path /path/to/your/capture.org [--port <custom_port>] [--template <custom org-capture template>]`. Or alternatively, just run it directly if you don't want to autostart it: `server/grasp_server.py --path /path/to/your/capture.org [--port <custom_port>] [--template <custom org-capture template>]`.
2. Install chrome extension and configure hotkeys 2. Install chrome extension and configure hotkeys
That's it! If you're using custom port make sure it's same as in the extension settings. That's it! If you're using custom port make sure it's same as in the extension settings (default is `12212`).
# Motivation # Motivation
Why use org-capture? Well, it's hard to explain, maybe some other time... However if you do know you want to use it instead/alongside your browser bookmarks, by default Why use org-capture? Well, it's hard to explain, maybe some other time... However if you do know you want to use it instead/alongside your browser bookmarks, by default
@ -42,7 +42,10 @@ You're gonna need `npm` for building extension.
npm install npm install
npm run build npm run build
After that you can find the extension in `build` directory and 'Load unpacked' if necessary. There is also Flow and Eslint set up. After that you can find the extension in `build` directory and 'Load unpacked** if necessary. There is also Flow and Eslint set up.
## Unrestricted url
If you want to run server remotely, you need extra permissions. Chrome store requires some extra checks when publishing if you do that, so I figured it's better to have localhost only by default. If you do need unresticted url permissions, build the extensions like that: `ANY_URL=yes npm run build`. Then don't forget to set the endpoint in extension settings.
# Permissions used # Permissions used
* `storage` for settings * `storage` for settings

View file

@ -2,7 +2,7 @@
// TODO do I really need to annotate all files with @flow?? // TODO do I really need to annotate all files with @flow??
import {COMMAND_CAPTURE_SIMPLE, METHOD_CAPTURE_WITH_EXTRAS, showNotification} from './common'; import {COMMAND_CAPTURE_SIMPLE, METHOD_CAPTURE_WITH_EXTRAS, showNotification} from './common';
import {get_options, capture_url} from './options'; import {get_options} from './options';
type Params = { type Params = {
url: string, url: string,
@ -25,7 +25,9 @@ function makeCaptureRequest(
console.log(`[background] capturing ${data}`); console.log(`[background] capturing ${data}`);
var request = new XMLHttpRequest(); var request = new XMLHttpRequest();
const curl = capture_url(options); const curl = options.endpoint;
request.timeout = 10 * 1000; // TODO should it be configurable?
request.open('POST', curl, true); request.open('POST', curl, true);
request.onreadystatechange = () => { request.onreadystatechange = () => {
if (request.readyState != 4) { if (request.readyState != 4) {

View file

@ -1,16 +1,14 @@
/* @flow */ /* @flow */
const capture_endpoint = 'capture';
type Options = { type Options = {
port: string; endpoint: string;
default_tags: string; default_tags: string;
notification: boolean; notification: boolean;
} }
function default_options(): Options { function default_options(): Options {
return { return {
port: "12212", endpoint: "http://localhost:12212/capture",
default_tags: "grasp", default_tags: "grasp",
notification: true, notification: true,
}; };
@ -27,7 +25,3 @@ export function set_options(opts: Options, cb: () => void) {
console.log('Saving %s', JSON.stringify(opts)); console.log('Saving %s', JSON.stringify(opts));
chrome.storage.local.set(opts, cb); chrome.storage.local.set(opts, cb);
} }
export function capture_url(options: Options): string {
return `http://localhost:${options.port}/${capture_endpoint}`;
}

View file

@ -1,14 +1,15 @@
/* @flow */ /* @flow */
import {get_options, set_options} from './options'; import {get_options, set_options} from './options';
const SAVE_ID = 'save_id'; const ENDPOINT_ID = 'endpoint_id';
const PORT_ID = 'port_id';
const NOTIFICATION_ID = 'notification_id'; const NOTIFICATION_ID = 'notification_id';
const DEFAULT_TAGS_ID = 'default_tags_id'; const DEFAULT_TAGS_ID = 'default_tags_id';
// TODO specify capture path here? // TODO specify capture path here?
function getPort(): HTMLInputElement { const SAVE_ID = 'save_id';
return ((document.getElementById(PORT_ID): any): HTMLInputElement);
function getEndpoint(): HTMLInputElement {
return ((document.getElementById(ENDPOINT_ID): any): HTMLInputElement);
} }
function getDefaultTags(): HTMLInputElement { function getDefaultTags(): HTMLInputElement {
@ -26,7 +27,7 @@ function getSaveButton(): HTMLInputElement {
function restoreOptions() { function restoreOptions() {
get_options(opts => { get_options(opts => {
getPort().value = opts.port; getEndpoint().value = opts.endpoint;
getDefaultTags().value = opts.default_tags; getDefaultTags().value = opts.default_tags;
getEnableNotification().checked = opts.notification; getEnableNotification().checked = opts.notification;
}); });
@ -34,11 +35,11 @@ function restoreOptions() {
function saveOptions() { function saveOptions() {
const opts = { const opts = {
port: getPort().value, // TODO validate?? endpoint: getEndpoint().value, // TODO validate??
default_tags: getDefaultTags().value, default_tags: getDefaultTags().value,
notification: getEnableNotification().checked, notification: getEnableNotification().checked,
}; };
set_options(opts, () => { console.log('fewf'); alert('Saved!'); }); set_options(opts, () => { alert('Saved!'); });
} }

View file

@ -5,8 +5,8 @@
<title></title> <title></title>
</head> </head>
<body> <body>
<label for="port_id">Port</label> <label for="endpoint_id">Endpoint</label>
<div><input type="text" id="port_id"/></div> <div><input type="text" id="endpoint_id"/></div>
<label for="notification_id">Notification after capturing</label> <label for="notification_id">Notification after capturing</label>
<div><input type="checkbox" id="notification_id"/></div> <div><input type="checkbox" id="notification_id"/></div>
<label for="default_tags_id">Default tags</label> <label for="default_tags_id">Default tags</label>