-
Notifications
You must be signed in to change notification settings - Fork 75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
random fixes and maybe improvements #147
Changes from 27 commits
de70e70
2870a7f
837818b
6057665
aae9f4b
b46b05b
19faecf
5eedc20
e32e040
b1a88e0
f90c85a
4875c45
63e2867
b577e14
2f87583
42a4ee3
6015a53
724bd44
9927022
b8ca0a8
fbe47d7
d058987
34b6abd
58d9ccf
9f51a00
0d11497
e1002e0
56ced94
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
docker/user_data | ||
.mypy_cache | ||
**/__pycache__ | ||
venv | ||
.git | ||
**/.idea | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -112,3 +112,5 @@ tmp/ | |
extension/dist | ||
|
||
geckodriver.log | ||
|
||
.idea |
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
user_data/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,21 @@ | ||
FROM python:3 | ||
|
||
RUN mkdir /data \ | ||
RUN mkdir /user_data \ | ||
mkdir /usr/src/promnisia | ||
|
||
WORKDIR /usr/src/promnesia | ||
COPY src/ . | ||
COPY setup.py /usr/src/ | ||
|
||
#RUN python /usr/src/setup.py #LookupError: setuptools-scm was unable to detect version for '/usr/src/promnesia'. | ||
|
||
RUN pip install --no-cache-dir more_itertools pytz sqlalchemy cachew \ | ||
appdirs urlextract python-magic \ | ||
tzlocal hug \ | ||
logzero HPI beautifulsoup4 lxml mistletoe orgparse dataset | ||
|
||
ENV PPATH=/usr/src/promnesia:${PPATH} | ||
VOLUME /data | ||
VOLUME /user_data | ||
|
||
EXPOSE 13131 | ||
CMD ["python", "-m", "promnesia", "serve", "--db", "/data/promnesia.sqlite", "--port", "13131"] | ||
CMD ["python", "-m", "promnesia", "serve", "--db", "/user_data/promnesia.sqlite", "--port", "13131"] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
FROM promnesia:latest | ||
|
||
RUN apt-get update && apt-get install -y cron | ||
COPY docker/indexer-entrypoint.sh / | ||
COPY docker/docker_files/indexer-entrypoint.sh / | ||
ENTRYPOINT ["/indexer-entrypoint.sh"] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
version: '3.3' | ||
|
||
services: | ||
server: | ||
image: promnesia | ||
build: | ||
context: ../../ | ||
dockerfile: docker/docker_files/Dockerfile | ||
# Uncomment to enable persisent volumes | ||
volumes: | ||
- ../user_data:/user_data | ||
ports: | ||
- "13131:13131" | ||
restart: always | ||
indexer: | ||
depends_on: | ||
- server | ||
image: promnesia-indexer | ||
build: | ||
context: ../../ | ||
dockerfile: docker/docker_files/Dockerfile-indexer | ||
# Uncomment to enable persisent volumes | ||
volumes: | ||
- ../user_data:/user_data | ||
environment: | ||
# run once every ten minutes | ||
CRONTAB: "0-59/1 * * * * cd /usr/src/promnesia && /usr/local/bin/python -m promnesia index --config /user_data/indexer-config.py" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from promnesia import Source | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, not sure about moving this file.. some tests depend on it (and also linked in readme). |
||
from promnesia.sources import auto | ||
|
||
''' | ||
List of sources to use | ||
|
||
You can specify your own, add more sources, etc. | ||
See https://github.com/karlicoss/promnesia#setup for more information | ||
''' | ||
|
||
# we should probably have separate docker volumes for sources and for config/db | ||
|
||
SOURCES = [ | ||
Source( | ||
auto.index, | ||
'/user_data/source1/', | ||
), | ||
# Source( | ||
# auto.index, | ||
# '/source2/', | ||
# ) | ||
] | ||
|
||
OUTPUT_DIR = '/user_data/' | ||
|
||
# this is not supported yet. also, it should probably be named something else than MIME_HANDLER. | ||
#import os | ||
#MIME_HANDLER = 'editor://' + os.path.realpath(os.path.dirname(os.path.realpath(__file__)) + '../') |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/bin/bash | ||
|
||
# note: https://lostindetails.com/articles/How-to-run-cron-inside-Docker | ||
# note: CRONTAB is set in docker-compose.yaml. | ||
|
||
echo "${CRONTAB} > /proc/1/fd/1 2>/proc/1/fd/2" | crontab - | ||
cron -f |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/usr/bin/env bash | ||
|
||
cd "$(dirname "$0")" | ||
|
||
cd user_data/ | ||
mkdir source1 | ||
cd source1 | ||
echo "i like https://github.com/karlicoss/promnesia." >> my_notes.txt | ||
git clone https://github.com/karlicoss/exobrain | ||
git clone https://github.com/koo5/notes | ||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/usr/bin/env bash | ||
|
||
cd "$(dirname "$0")" | ||
mkdir user_data | ||
cp docker_files/indexer-config.py.example user_data/indexer-config.py | ||
./get-some-data.sh | ||
|
||
# the config file will be periodically reloaded by the indexer process, and data sources will be periodically re-indexed. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/usr/bin/env bash | ||
|
||
cd "$(dirname "$0")" | ||
docker-compose -f docker_files/docker-compose.yaml build && docker-compose -f docker_files/docker-compose.yaml up | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -92,7 +92,7 @@ async function queryBackendCommon<R>(params, endp: string): Promise<R> { | |
// right, fetch API doesn't reject on HTTP error status... | ||
const ok = response.ok; | ||
if (!ok) { | ||
throw response.statusText; // TODO... | ||
throw Error(response.statusText + ' (' + response.status + ')'); // TODO... | ||
} | ||
return response.json(); | ||
}); | ||
|
@@ -117,7 +117,8 @@ function getDelayMs(/*url*/) { | |
return 10 * 1000; | ||
} | ||
|
||
const LOCAL_TAG = 'local'; | ||
//hmm having a space in a tag shouldn't cause an error but it does | ||
const LOCAL_TAG = 'this_browser_history'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
|
||
async function getChromeVisits(url: Url): Promise<Visits> { | ||
|
@@ -166,7 +167,12 @@ export async function getVisits(url: Url): Promise<Result> { | |
// it's gona be a mess though.. | ||
const backendRes: Visits | Error = await getBackendVisits(url) | ||
.catch((err: Error) => err); | ||
|
||
//console.log('backendRes'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not needed? |
||
//console.log(backendRes); | ||
|
||
if (backendRes instanceof Error) { | ||
console.log('backend server request error:', backendRes); | ||
return backendRes; | ||
} | ||
|
||
|
@@ -200,7 +206,7 @@ function getIconStyle(visits: Result): IconStyle { | |
|
||
const vcount = visits.visits.length; | ||
if (vcount === 0) { | ||
return {icon: 'images/ic_not_visited_48.png', title: 'Not visited', text: ''}; | ||
return {icon: 'images/ic_not_visited_48.png', title: 'No data', text: ''}; | ||
} | ||
const cp = []; | ||
|
||
|
@@ -229,7 +235,7 @@ function getIconStyle(visits: Result): IconStyle { | |
const boring = visits.visits.every(v => v.tags.length == 1 && v.tags[0] == LOCAL_TAG); | ||
if (boring) { | ||
// TODO not sure if really worth distinguishing.. | ||
return {icon: "images/ic_boring_48.png" , title: `${vcount} visits (local only)`, text: ''}; | ||
return {icon: "images/ic_boring_48.png" , title: `${vcount} visits (${LOCAL_TAG} only)`, text: ''}; | ||
} else { | ||
return {icon: "images/ic_blue_48.png" , title: `${vcount} visits`, text: ''}; | ||
} | ||
|
@@ -255,11 +261,11 @@ async function updateState (tab: chrome$Tab) { | |
.then(() => chromeTabsInsertCSS(tabId, {code: opts.position_css})); | ||
|
||
|
||
// NOTE: if the page is unreachable, we can't inject stuf in it | ||
// NOTE: if the page is unreachable, we can't inject stuff in it | ||
// not sure how to detect it? tab doesn't have any interesting attributes | ||
// firefox sets tab.title to "Server Not Found"? (TODO also see isOk logic below) | ||
// TODO in this case, could set browser action to open a new tab (i.e. search) or something? | ||
await defensify(inject, 'sidebar injection')(); | ||
await defensify(inject, 'sidebar injection for tabId:' + tabId + ' url: ' + url)(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: generally I prefer writing this as
, because in many languages if the string is null, |
||
// TODO crap, at first I forgot () at the end, and flow didn't complain which resulted in flakiness wtf?? | ||
|
||
const visits = await getVisits(url); | ||
|
@@ -458,7 +464,7 @@ function isSpecialProtocol(url: string): boolean { | |
|
||
function ignored(url: string): boolean { | ||
if ([ | ||
'https://www.google.com/_/chrome/newtab?ie=UTF-8', // ugh, not sure how to dix that properly | ||
'https://www.google.com/_/chrome/newtab?ie=UTF-8', // ugh, not sure how to fix that properly | ||
'about:blank', // not sure why about:blank is loading like 5 times.. but this seems to fix it | ||
].includes(url)) { | ||
return true; | ||
|
@@ -665,7 +671,7 @@ export async function injectSidebar(tab: chrome$Tab) { | |
const tid = unwrap(tab.id); | ||
if (ignored(url)) { | ||
// TODO tab notification? | ||
notify(`${url} can't be handled`); | ||
notify(`${url} is an ignored URL`); | ||
return; | ||
} | ||
const blacklist = await Blacklist_get(); | ||
|
@@ -693,7 +699,7 @@ const onCommandCallback = defensify(async cmd => { | |
} else if (cmd === COMMAND_SEARCH) { | ||
await handleOpenSearch(); | ||
} else { | ||
// TODO throw? | ||
// TODO throw? // yea probably | ||
lerror("unexpected command %s", cmd); | ||
} | ||
}, 'onCommand'); | ||
|
@@ -782,7 +788,7 @@ function initBackground() { | |
if (android) { | ||
return; | ||
} | ||
|
||
// $FlowFixMe // err, complains at Promise but nevertheless works | ||
chrome.commands.onCommand.addListener(onCommandCallback); | ||
|
||
|
@@ -802,7 +808,7 @@ function initBackground() { | |
'contexts' : ['page', 'browser_action'], | ||
'title' : "Search in browsing history", | ||
}) | ||
|
||
// $FlowFixMe // err, complains at Promise but nevertheless works | ||
chrome.contextMenus.onClicked.addListener(onMenuClickedCallback); | ||
}) | ||
|
@@ -822,7 +828,6 @@ chrome.runtime.onMessage.addListener((info: any, sender: chrome$MessageSender) = | |
console.log("onmessage %o %o", info, sender); | ||
const aurl = sender.tab == null ? null : sender.tab.url; | ||
|
||
console.info("Registering background page callbacks %s", aurl); | ||
if (backgroundInitialised) { | ||
console.debug("background already initialised"); | ||
return; | ||
|
@@ -833,6 +838,9 @@ chrome.runtime.onMessage.addListener((info: any, sender: chrome$MessageSender) = | |
lwarn("Suppressing special background page %s", aurl); | ||
return; | ||
} | ||
|
||
console.info("Registering background page callbacks in tab %s", aurl); | ||
karlicoss marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/* TODO not sure if ok or not to await? it shouldn't be blocking right? */ | ||
initBackground(); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -150,6 +150,16 @@ export class Binder { | |
link.title = 'Jump to the context'; | ||
// $FlowFixMe | ||
link.href = loc.href; | ||
|
||
// _self seems to "work" only for the "editor://" protocol. Avoids opening a new tab for "editor://" links. Nttp links then require a middle-click, which is undesirable. With normal click, they would not open at all. | ||
// testing on firefox mobile would be useful. | ||
// note that on some pages, like https://news.ycombinator.com/, this (clicking on a _self editor:// link) results in: Content Security Policy: The page’s settings blocked the loading of a resource at editor:///home/koom/promnesia/docker//user_data/source1/notes/g1:12 (“frame-src”). | ||
// but middle-click still works. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right... annoying. I guess this is another usecase where some dynamic JS hooks would be useful (so the users can experiment/work around for themselves). |
||
// on others (https://www.reddit.com/), it just works. | ||
// so, if we should do this at all is a question. | ||
//if (link.href.startsWith('editor://')) | ||
// link.target= '_self'; | ||
|
||
tchild(link, loc.title); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, my primary browser is Firefox! Yeah, it's very annoying indeed that temporary extensions don't survive the restart, but I'm actually using the released version from addons.mozilla.org myself! So using your own build of the extension is hardly a 'quick start' since it's awailable from chrome/mozilla stores :)
And yeah.. for phone it used to work, but then new Firefox happened and now we're waiting till they add extension support back (I hope!). However since covid happened, I'm not using my phone that much either so wasn't too bothered about it so far enough to install Firefox nightly.