Skip to content

Commit

Permalink
feat: fix not working in Ubuntu 20.04 ( Boscop/web-view#289 )
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Forrester committed Nov 1, 2021
1 parent 5431908 commit 05cd332
Show file tree
Hide file tree
Showing 5 changed files with 138 additions and 14 deletions.
113 changes: 105 additions & 8 deletions js-lib/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions js-lib/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wv-linewise-js-lib",
"version": "0.0.2",
"version": "0.0.3",
"repository": {
"type": "git",
"url": "https://github.com/forbesmyester/wv-linewise"
Expand All @@ -14,7 +14,9 @@
},
"author": "Matt Forrester <[email protected]>",
"license": "MIT",
"dependencies": {},
"dependencies": {
"typescript-language-server": "^0.5.1"
},
"typings": "./dist/main.d.ts",
"devDependencies": {
"@rollup/plugin-typescript": "^4.1.2",
Expand Down
4 changes: 1 addition & 3 deletions js-lib/src/wv-linewise-fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,7 @@ export function getWvLinewiseFetch(wvl: WvLinewise, responseStream: string) {

function wvLinewiseFetchSerialize(request: WvLinewiseRequest): string {
let m = (request.opts.method || 'GET').toUpperCase();
let o = {...request.opts};
delete o.method;
return `REQUEST: ${request.id}: ${m}: ${request.url} ${JSON.stringify(o)}`;
return `REQUEST: ${request.id}: ${m}: ${request.url} ${request.opts.body || '{}'}`;
}

wvLinewiseFetch.request = wvLinewiseFetchRequest;
Expand Down
23 changes: 23 additions & 0 deletions js-lib/src/wv-linewise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,29 @@ export class WvLinewise {
}

export function runningInWvLinewise(): boolean {

if ((window as any).webkit && (window as any).webkit.messageHandlers && (window as any).webkit.messageHandlers.external && (window as any).webkit.messageHandlers.external.postMessage) {
(window as any).external = {
invoke: (e: string) => {
(window as any).webkit.messageHandlers.external.postMessage(e);
}
};
return true;
}

return !!((window as any).external && (window.external as any).invoke);
}

export function externalInvoke(e: any) {

if ((window as any).webkit && (window as any).webkit.messageHandlers && (window as any).webkit.messageHandlers.external && (window as any).webkit.messageHandlers.external.postMessage) {
return (window as any).webkit.messageHandlers.external.postMessage(e);
}

if ((window as any).external && (window.external as any).invoke) {
return (window.external as any).invoke(e);
}

throw new Error("WV Linewise: Could not post message: " + JSON.stringify(e));
}

6 changes: 5 additions & 1 deletion js-lib/test/wv-linewise-fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ tap.test('testSerialize', function testSerialize(test) {

test.is(
fet.serialize({ opts: { cache: "no-cache", method: "post", body: JSON.stringify({ a: 2 }) }, id: 3, url: '/snow' }),
'REQUEST: 3: POST: /snow {"cache":"no-cache","body":"{\\"a\\":2}"}'
'REQUEST: 3: POST: /snow {"a":2}'
);
test.is(
fet.serialize({ opts: { cache: "no-cache", method: "get" }, id: 3, url: '/snow' }),
'REQUEST: 3: GET: /snow {}'
);
test.end()

Expand Down

0 comments on commit 05cd332

Please sign in to comment.