Skip to content

Commit

Permalink
[WIP] Remote Func Refac: Results from testing: Fix some func argument…
Browse files Browse the repository at this point in the history
… types and small fixes
  • Loading branch information
cdharris committed Jun 25, 2019
1 parent 2b2e8fa commit dafb191
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 20 deletions.
2 changes: 2 additions & 0 deletions src/activity-logger/background/log-page-visit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import { Tabs } from 'webextension-polyfill-ts'
import moment from 'moment'

import { TabManager } from './tab-manager'
// @ts-ignore
import analyzePage, { PageAnalyzer } from '../../page-analysis/background'
import * as searchIndex from '../../search'

import { FavIconChecker } from './types'

interface Props {
Expand Down
4 changes: 2 additions & 2 deletions src/bookmarks/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ It is currently un-used as previously, only the call to bookmark a search result

### Remote function usage:

1. Remote Function call, with only url
1. Remote Function call, with only url (note this is `addPageBookmark` not `addBookmark`)

In `src/overview/results/actions.ts:95` as `bookmarkRPC({ url })`
In `src/overview/results/actions.ts:95` as `addPageBookmark({ url })`

2. Remote Function call, with tabId

Expand Down
4 changes: 2 additions & 2 deletions src/content-tooltip/interactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,9 @@ export function userSelectedText() {
const container = selection.getRangeAt(0).commonAncestorContainer
const extras = isAnchorOrContentEditable(container)

const userSelectedText =
const userSelectedTextString =
!!selection && !selection.isCollapsed && !!selectedString && !extras
return userSelectedText
return userSelectedTextString
}

function isTargetInsideTooltip(event) {
Expand Down
2 changes: 0 additions & 2 deletions src/page-analysis/background/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ export default async function analysePage({

// Fetch the data
const dataFetchingPromises = [
// todo: remote-functions-refactor: should extractPageContent ever be called like this without params? is it used?
// @ts-ignore
allowContent ? extractPageContent() : Promise.resolve(),
allowScreenshot ? makeScreenshot({ tabId }) : Promise.resolve(),
allowFavIcon ? getFavIcon({ tabId }) : Promise.resolve(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { getMetadata } from 'page-metadata-parser'
import transformPageHTML from 'src/util/transform-page-html'
import PAGE_METADATA_RULES from './page-metadata-rules'
import extractPdfContent from './extract-pdf-content'
import { ExtractPageContent } from 'src/page-analysis/types'

export const DEF_LANG = 'en'

Expand All @@ -21,7 +22,7 @@ export default async function extractPageContent(
) {
// If it is a PDF, run code for pdf instead.
if (url.endsWith('.pdf')) {
return extractPdfContent({ url })
return extractPdfContent({ url, blob: undefined })
}

// Apply simple transformations to clean the page's HTML
Expand Down
9 changes: 3 additions & 6 deletions src/page-analysis/content_script/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { makeRemotelyCallable } from 'src/util/webextensionRPC'
import extractPageContent from './extract-page-content'
import { PageAnalyzerInterface } from 'src/page-analysis/types'

makeRemotelyCallable <
PageAnalyzerInterface >
{
extractPageContent,
}
makeRemotelyCallable({
extractPageContent,
})
2 changes: 1 addition & 1 deletion src/page-analysis/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ export interface PageAnalyzerInterface {
extractPageContent: ExtractPageContent
}

export type ExtractPageContent = (doc, url: string) => any
export type ExtractPageContent = (doc?, url?: any) => any
1 change: 1 addition & 0 deletions src/search/bookmarks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const addBookmark = (getDb: DBGet, tabManager: TabManager) => async ({
timestamp?: number
tabId?: number
}) => {
// url = normalizeUrl(url);
let page = await getPage(getDb)(url)

if (page == null || page.isStub) {
Expand Down
2 changes: 1 addition & 1 deletion src/sidebar-overlay/ribbon/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default interface State {

export interface RibbonInteractionsInterface {
insertRibbon: ({ override, ...args }?: { override?: boolean } | any) => any
removeRibbon: ({ override }: { override?: boolean }) => any
removeRibbon: ({ override }?: { override?: boolean }) => any
insertOrRemoveRibbon: () => any
updateRibbon: () => any
}
2 changes: 1 addition & 1 deletion src/util/notification-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Notifications } from 'webextension-polyfill-ts/src/generated/notificati
// Chrome allows some extra notif opts that the standard web ext API doesn't support
export interface NotifOpts extends Notifications.CreateNotificationOptions {
[chromeKeys: string]: any
requireInteraction: boolean
requireInteraction?: boolean
}

export type CreateNotificationInterface = (
Expand Down
11 changes: 7 additions & 4 deletions src/util/webextensionRPC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class RemoteError extends Error {
interface RPCOpts {
tabId?: number

//todo: remove any references to this
// todo: remove any references to this
throwWhenNoResponse?: boolean
}

Expand Down Expand Up @@ -76,7 +76,9 @@ type InterfaceWithTabId<T> = T & { tabId: number }
export function runInBackground<T extends object>(): T {
return new Proxy<T>({} as T, {
get(target, property): any {
return (...args) => remoteFunction(property.toString())(args)
return (...args) => {
return remoteFunction(property.toString())(...args)
}
},
})
}
Expand All @@ -85,8 +87,9 @@ export function runInBackground<T extends object>(): T {
export function runInTab<T extends object>(tabId): T {
return new Proxy<T>({} as T, {
get(target, property): any {
return (...args) =>
remoteFunction(property.toString(), { tabId })(args)
return (...args) => {
return remoteFunction(property.toString(), { tabId })(...args)
}
},
})
}
Expand Down

0 comments on commit dafb191

Please sign in to comment.