1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-11-27 08:21:03 +02:00

Clipper: Better handling of clipper server detection

This commit is contained in:
Laurent Cozic 2018-05-25 11:18:47 +01:00
parent 012e70d668
commit d11ecd8fac
2 changed files with 28 additions and 12 deletions

View File

@ -24,6 +24,21 @@ class AppComponent extends Component {
text: event.currentTarget.value
});
}
this.clipScreenshot_click = async () => {
try {
const baseUrl = await bridge().clipperServerBaseUrl();
bridge().sendCommandToActiveTab({
name: 'screenshot',
apiBaseUrl: baseUrl,
});
window.close();
} catch (error) {
this.props.dispatch({ type: 'CONTENT_UPLOAD', operation: { uploading: false, success: false, errorMessage: error.message } });
}
}
}
clipSimplified_click() {
@ -38,15 +53,6 @@ class AppComponent extends Component {
});
}
clipScreenshot_click() {
bridge().sendCommandToActiveTab({
name: 'screenshot',
apiBaseUrl: 'http://127.0.0.1:9967',
});
window.close();
}
async loadContentScripts() {
await bridge().tabsExecuteScript({file: "/content_scripts/JSDOMParser.js"});
await bridge().tabsExecuteScript({file: "/content_scripts/Readability.js"});
@ -75,7 +81,9 @@ class AppComponent extends Component {
if (operation) {
let msg = '';
if (operation.uploading) {
if (operation.searchingClipperServer) {
msg = 'Searching clipper service... Please make sure that Joplin is running.';
} else if (operation.uploading) {
msg = 'Processing note... The note will be available in Joplin as soon as the web page and images have been downloaded and converted. In the meantime you may close this popup.';
} else if (operation.success) {
msg = 'Note was successfully created!';

View File

@ -86,13 +86,21 @@ class Bridge {
if (checkStatus()) return;
this.dispatch({ type: 'CONTENT_UPLOAD', operation: { searchingClipperServer: true } });
const waitIID = setInterval(() => {
if (!checkStatus()) return;
this.dispatch({ type: 'CONTENT_UPLOAD', operation: null });
clearInterval(waitIID);
}, 1000);
});
}
async clipperServerBaseUrl() {
const port = await this.clipperServerPort();
return 'http://127.0.0.1:' + port;
}
async tabsExecuteScript(options) {
if (this.browserSupportsPromises_) return this.browser().tabs.executeScript(options);
@ -145,9 +153,9 @@ class Bridge {
if (!content) throw new Error('Cannot send empty content');
const port = await this.clipperServerPort();
const baseUrl = await this.clipperServerBaseUrl();
const response = await fetch("http://127.0.0.1:" + port + "/notes", {
const response = await fetch(baseUrl + "/notes", {
method: "POST",
headers: {
'Accept': 'application/json',