mirror of
https://github.com/vale981/tridactyl
synced 2025-03-05 09:31:41 -05:00
Add dependencies and tertiary files for new cli.
This commit is contained in:
parent
208adb2dfa
commit
9454aa189e
5 changed files with 125 additions and 0 deletions
|
@ -8,13 +8,17 @@
|
||||||
"command-line-args": "^5.1.1",
|
"command-line-args": "^5.1.1",
|
||||||
"csp-serdes": "github:cmcaine/csp-serdes",
|
"csp-serdes": "github:cmcaine/csp-serdes",
|
||||||
"css": "^2.2.4",
|
"css": "^2.2.4",
|
||||||
|
"flyd": "^0.2.8",
|
||||||
"fuse.js": "^3.4.5",
|
"fuse.js": "^3.4.5",
|
||||||
|
"immer": "^3.1.2",
|
||||||
"mark.js": "^8.11.1",
|
"mark.js": "^8.11.1",
|
||||||
|
"mithril": "^1.1.6",
|
||||||
"rss-parser": "^3.7.1",
|
"rss-parser": "^3.7.1",
|
||||||
"semver-compare": "^1.0.0"
|
"semver-compare": "^1.0.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/jest": "^24.0.13",
|
"@types/jest": "^24.0.13",
|
||||||
|
"@types/mithril": "^1.1.16",
|
||||||
"@types/node": "^12.0.3",
|
"@types/node": "^12.0.3",
|
||||||
"awesome-typescript-loader": "^5.2.1",
|
"awesome-typescript-loader": "^5.2.1",
|
||||||
"cleanslate": "^0.10.1",
|
"cleanslate": "^0.10.1",
|
||||||
|
|
20
src/components/iframe.ts
Normal file
20
src/components/iframe.ts
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
import * as m from "mithril"
|
||||||
|
|
||||||
|
const proxy = function(vnode: any) {
|
||||||
|
const doc = vnode.dom.contentDocument || vnode.dom.contentWindow.document;
|
||||||
|
|
||||||
|
if (doc.readyState === "complete") {
|
||||||
|
m.render( vnode.dom.contentDocument.documentElement, vnode.children )
|
||||||
|
} else {
|
||||||
|
setTimeout(function() {proxy(vnode); }, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const Iframe = {
|
||||||
|
oncreate: proxy,
|
||||||
|
onupdate: proxy,
|
||||||
|
view: ({attrs}) =>
|
||||||
|
m("iframe", attrs)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Iframe
|
19
src/components/input.ts
Normal file
19
src/components/input.ts
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
import * as m from "mithril"
|
||||||
|
import {ContentAttrs, dispatch} from "@src/content"
|
||||||
|
|
||||||
|
const TriInput: m.Component<ContentAttrs> = {
|
||||||
|
view: (vnode) => {
|
||||||
|
const {model, actions} = vnode.attrs
|
||||||
|
return m("div", {id: "command-line-holder"}, [
|
||||||
|
m("span", {id: "tridactyl-colon"}),
|
||||||
|
m("input", {
|
||||||
|
id: "tridactyl-input",
|
||||||
|
type: "text",
|
||||||
|
oninput: (e: any) => dispatch(actions.uiframe.oninput(e.target.value)),
|
||||||
|
value: model.uiframe.commandline.text
|
||||||
|
})
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export default TriInput
|
15
src/components/status.ts
Normal file
15
src/components/status.ts
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
import * as m from "mithril"
|
||||||
|
import {ContentAttrs} from "@src/content"
|
||||||
|
|
||||||
|
const TriStatus: m.Component<ContentAttrs> = {
|
||||||
|
view: (vnode) => {
|
||||||
|
const {model, actions} = vnode.attrs as ContentAttrs
|
||||||
|
return m("div", {id: "status-bar-holder"}, [
|
||||||
|
m("span", {id: "tridactyl-status-left"}),
|
||||||
|
m("span", {id: "tridactyl-status-middle"}),
|
||||||
|
m("span", {id: "tridactyl-status-right"}),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export default TriStatus
|
67
src/rpc.ts
Normal file
67
src/rpc.ts
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
import {BGRPCExports} from '~background'
|
||||||
|
|
||||||
|
import * as R from 'ramda'
|
||||||
|
|
||||||
|
export type Sender = browser.runtime.MessageSender
|
||||||
|
|
||||||
|
export type RPCMsg = {
|
||||||
|
path: string[],
|
||||||
|
args: any[],
|
||||||
|
}
|
||||||
|
|
||||||
|
export type RPCFunc = (...args: any[]) => Promise<any>;
|
||||||
|
export type RPCExports = {
|
||||||
|
[key: string]: RPCFunc | { [key: string]: RPCFunc }
|
||||||
|
}
|
||||||
|
|
||||||
|
export type Target =
|
||||||
|
'background' | { tab: number } // | { frame: number }
|
||||||
|
|
||||||
|
let uuid = 0
|
||||||
|
|
||||||
|
export const send = async (who: Target, msg: RPCMsg) => {
|
||||||
|
const id = uuid++
|
||||||
|
console.log('Tx', id, who, msg)
|
||||||
|
|
||||||
|
let prom
|
||||||
|
if (who === 'background')
|
||||||
|
prom = browser.runtime.sendMessage(msg)
|
||||||
|
else if (who.tab !== undefined)
|
||||||
|
prom = browser.tabs.sendMessage(who.tab, msg)
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await prom
|
||||||
|
console.log('TxRx', id, response)
|
||||||
|
return response
|
||||||
|
} catch (err) {
|
||||||
|
console.error('TxRxErr', id, err)
|
||||||
|
throw err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getIn(path: any[], obj: Object) {
|
||||||
|
return path.reduce((o, n) => o[n], obj)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const onMessage = (rpcexports: RPCExports) =>
|
||||||
|
async (msg: RPCMsg, sender: Sender) => {
|
||||||
|
const {path, args} = msg
|
||||||
|
console.log(`Rx`, msg, sender)
|
||||||
|
return getIn(path, rpcexports)(...args)
|
||||||
|
}
|
||||||
|
|
||||||
|
// For a proxy to be callable, the target to the proxy must also be callable,
|
||||||
|
// even though you don't have to do anything with it :/
|
||||||
|
const voidfn = () => {}
|
||||||
|
|
||||||
|
export function nestingproxy (target: Target, path: string[] = []): RPCExports {
|
||||||
|
return new Proxy(voidfn, {
|
||||||
|
get: (_, name: string) => nestingproxy(target, path.concat([name])),
|
||||||
|
apply: (_, __, args: any[]) => send(target, {path, args})
|
||||||
|
}) as any
|
||||||
|
}
|
||||||
|
|
||||||
|
export function rpc(target: 'background'): BGRPCExports;
|
||||||
|
export function rpc(target: Target) {
|
||||||
|
return nestingproxy(target) as any
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue