Skip to content

Commit

Permalink
Merge branch 'develop' into hotfix/3.12.14
Browse files Browse the repository at this point in the history
  • Loading branch information
blackforestboi committed Feb 9, 2024
2 parents ad7d2e7 + c9d19c5 commit 6bab36a
Show file tree
Hide file tree
Showing 47 changed files with 1,159 additions and 736 deletions.
2 changes: 1 addition & 1 deletion external/@worldbrain/memex-common
9 changes: 1 addition & 8 deletions src/annotations/annotation-save-logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,7 @@ export async function createAnnotation({
}: SaveAnnotationParams<AnnotationCreateData>): Promise<
SaveAnnotationReturnValue
> {
let remoteAnnotationId: string = null

let syncSettings: SyncSettingsStore<'extension'>

syncSettings = createSyncSettingsStore({
syncSettingsBG: syncSettingsBG,
})

const remoteAnnotationId = await contentSharingBG.generateRemoteAnnotationId()
return {
remoteAnnotationId,
savePromise: (async () => {
Expand Down
27 changes: 13 additions & 14 deletions src/annotations/background/index.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,36 @@
import Storex from '@worldbrain/storex'
import { Tabs, Browser } from 'webextension-polyfill'
import type Storex from '@worldbrain/storex'
import type { Tabs, Browser } from 'webextension-polyfill'
import {
normalizeUrl,
isFullUrl,
} from '@worldbrain/memex-common/lib/url-utils/normalize'
import { URLNormalizer } from '@worldbrain/memex-common/lib/url-utils/normalize/types'
import type { URLNormalizer } from '@worldbrain/memex-common/lib/url-utils/normalize/types'

import {
makeRemotelyCallable,
remoteFunction,
runInTab,
} from 'src/util/webextensionRPC'
import AnnotationStorage from './storage'
import { AnnotSearchParams } from 'src/search/background/types'
import { KeyboardActions } from 'src/sidebar-overlay/sidebar/types'
import SocialBG from 'src/social-integration/background'
import type { AnnotSearchParams } from 'src/search/background/types'
import type { KeyboardActions } from 'src/sidebar-overlay/sidebar/types'
import type SocialBG from 'src/social-integration/background'
import { buildPostUrlId } from 'src/social-integration/util'
import type { Annotation } from 'src/annotations/types'
import type { AnnotationInterface, CreateAnnotationParams } from './types'
import { InPageUIContentScriptRemoteInterface } from 'src/in-page-ui/content_script/types'
import { InPageUIRibbonAction } from 'src/in-page-ui/shared-state/types'
import type { InPageUIContentScriptRemoteInterface } from 'src/in-page-ui/content_script/types'
import type { InPageUIRibbonAction } from 'src/in-page-ui/shared-state/types'
import { generateAnnotationUrl } from 'src/annotations/utils'
import { PageIndexingBackground } from 'src/page-indexing/background'
import { Analytics } from 'src/analytics/types'
import type { Analytics } from 'src/analytics/types'
import { getUnderlyingResourceUrl } from 'src/util/uri-utils'
import { ServerStorageModules } from 'src/storage/types'
import { GetUsersPublicDetailsResult } from '@worldbrain/memex-common/lib/user-management/types'
import type { GetUsersPublicDetailsResult } from '@worldbrain/memex-common/lib/user-management/types'
import { trackAnnotationCreate } from '@worldbrain/memex-common/lib/analytics/events'
import { AnalyticsCoreInterface } from '@worldbrain/memex-common/lib/analytics/types'
import type { AnalyticsCoreInterface } from '@worldbrain/memex-common/lib/analytics/types'
import type { PKMSyncBackgroundModule } from 'src/pkm-integrations/background'
import { ImageSupportInterface } from '@worldbrain/memex-common/lib/image-support/types'
import { AuthBackground } from 'src/authentication/background'
import { RGBAColor } from '@worldbrain/memex-common/lib/annotations/types'
import type { ImageSupportInterface } from '@worldbrain/memex-common/lib/image-support/types'
import type { AuthBackground } from 'src/authentication/background'

interface TabArg {
tab: Tabs.Tab
Expand Down
2 changes: 0 additions & 2 deletions src/annotations/cache/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -672,8 +672,6 @@ export class PageAnnotationsCache implements PageAnnotationsCacheInterface {
// updates.color = annotColorObject
// }

console.log('updatesbody', updates.body)

const next: UnifiedAnnotation = {
...previous,
privacyLevel,
Expand Down
17 changes: 7 additions & 10 deletions src/background-script/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import * as utils from './utils'
import { makeRemotelyCallable, runInTab } from '../util/webextensionRPC'
import type { StorageChangesManager } from '../util/storage-changes'
import { migrations, MIGRATION_PREFIX } from './quick-and-dirty-migrations'
import { removeDupeSpaces } from './quick-and-dirty-migrations/tag-space-dupe-removal'
import { generateUserId } from 'src/analytics/utils'
import { STORAGE_KEYS } from 'src/analytics/constants'
import insertDefaultTemplates from 'src/copy-paster/background/default-templates'
Expand All @@ -33,11 +32,9 @@ import { getLocalStorage, setLocalStorage } from 'src/util/storage'
import { MISSING_PDF_QUERY_PARAM } from 'src/dashboard-refactor/constants'
import type { BackgroundModules } from './setup'
import type { InPageUIContentScriptRemoteInterface } from 'src/in-page-ui/content_script/types'
import { isExtensionTab, isBrowserPageTab } from 'src/tab-management/utils'
import { captureException } from 'src/util/raven'
import { browser } from 'webextension-polyfill-ts'
import { checkStripePlan } from 'src/util/subscriptions/storage'
import { AnalyticsCoreInterface } from '@worldbrain/memex-common/lib/analytics/types'
import type { AnalyticsCoreInterface } from '@worldbrain/memex-common/lib/analytics/types'
import { trackOnboardingPath } from '@worldbrain/memex-common/lib/analytics/events'

interface Dependencies {
Expand Down Expand Up @@ -164,7 +161,7 @@ class BackgroundScript {
},
}

await browser.storage.local.set(tutorials)
await this.deps.storageAPI.local.set(tutorials)
}

/**
Expand Down Expand Up @@ -321,17 +318,17 @@ class BackgroundScript {
runtimeAPI.onUpdateAvailable.addListener(async () => {
try {
await bgModules.tabManagement.mapTabChunks(
async ({ url, id }) => {
async (tab) => {
if (
!url ||
isExtensionTab({ url }) ||
isBrowserPageTab({ url })
!bgModules.tabManagement.canTabRunContentScripts(
tab,
)
) {
return
}

await runInTab<InPageUIContentScriptRemoteInterface>(
id,
tab.id,
).teardownContentScripts()
},
{
Expand Down
2 changes: 1 addition & 1 deletion src/content-scripts/background/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export class ContentScriptsBackground {

this.options.browserAPIs.tabs.onUpdated.addListener(
(tabId, changeInfo) => {
if (changeInfo.url.includes('mail.google.com/mail')) {
if (changeInfo?.url?.includes('mail.google.com/mail')) {
runInTab<InPageUIContentScriptRemoteInterface>(
tabId,
).handleHistoryStateUpdate(tabId)
Expand Down
52 changes: 35 additions & 17 deletions src/content-scripts/content_script/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import { PageAnnotationsCache } from 'src/annotations/cache'
import type { AnalyticsEvent } from 'src/analytics/types'
import analytics from 'src/analytics'
import { main as highlightMain } from 'src/content-scripts/content_script/highlights'
import { main as searchInjectionMain } from 'src/content-scripts/content_script/search-injection'
import { main as InPageUIInjectionMain } from 'src/content-scripts/content_script/search-injection'
import type { PageIndexingInterface } from 'src/page-indexing/background/types'
import { copyToClipboard } from 'src/annotations/content_script/utils'
import { getUnderlyingResourceUrl } from 'src/util/uri-utils'
Expand Down Expand Up @@ -85,7 +85,10 @@ import {
trackPageActivityIndicatorHit,
} from '@worldbrain/memex-common/lib/analytics/events'
import { AnalyticsCoreInterface } from '@worldbrain/memex-common/lib/analytics/types'
import { promptPdfScreenshot } from '@worldbrain/memex-common/lib/pdf/screenshots/selection'
import {
PdfScreenshot,
promptPdfScreenshot,
} from '@worldbrain/memex-common/lib/pdf/screenshots/selection'
import { processCommentForImageUpload } from '@worldbrain/memex-common/lib/annotations/processCommentForImageUpload'
import { theme } from 'src/common-ui/components/design-library/theme'
import { PDFRemoteInterface } from 'src/pdf/background/types'
Expand Down Expand Up @@ -454,6 +457,7 @@ export async function main(
},
})

// TODO: Type this
async function saveHighlight(
shouldShare: boolean,
shouldCopyShareLink: boolean,
Expand All @@ -462,6 +466,18 @@ export async function main(
imageSupport?,
highlightColor?: { color: RGBAColor; id: string; label: string },
): Promise<{ annotationId: AutoPk; createPromise: Promise<void> }> {
const handleError = async (err: Error) => {
captureException(err)
await contentScriptRegistry.registerInPageUIInjectionScript(
InPageUIInjectionMain,
{
errorMessage: err.message,
title: 'Error saving note',
blockedBackground: true,
},
)
}

try {
const result = await highlightRenderer.saveAndRenderHighlight({
currentUser,
Expand All @@ -483,12 +499,11 @@ export async function main(
highlightColor,
})
const annotationId = result.annotationId
const createPromise = result.createPromise
const createPromise = result.createPromise.catch(handleError)

return { annotationId, createPromise }
} catch (err) {
captureException(err)
await inPageUI.toggleErrorMessage({ type: 'annotation' })
await handleError(err)
throw err
}
}
Expand Down Expand Up @@ -525,7 +540,7 @@ export async function main(
action: 'show_annotation',
})
}
let screenshotGrabResult
let screenshotGrabResult: PdfScreenshot
if (
isPdfViewerRunning &&
window.getSelection().toString().length === 0
Expand Down Expand Up @@ -757,14 +772,15 @@ export async function main(
})
inPageUI.hideTooltip()
},
createTimestampWithAISummary: async (includeLastFewSecs) => {
createTimestampWithAISummary: async (includeLastFewSecs, prompt) => {
const timestampToPass = await getTimestampedNoteWithAIsummaryForYoutubeNotes(
includeLastFewSecs,
)

inPageUI.showSidebar({
action: 'create_youtube_timestamp_with_AI_summary',
videoRangeTimestamps: timestampToPass,
prompt,
})
inPageUI.hideTooltip()
},
Expand Down Expand Up @@ -839,7 +855,7 @@ export async function main(
// dependencies

const contentScriptRegistry: ContentScriptRegistry = {
async registerRibbonScript(execute): Promise<void> {
async registerRibbonScript(execute) {
await execute({
inPageUI,
currentUser,
Expand Down Expand Up @@ -874,7 +890,7 @@ export async function main(
})
components.ribbon?.resolve()
},
async registerHighlightingScript(execute): Promise<void> {
async registerHighlightingScript(execute) {
await execute({
inPageUI,
annotationsCache,
Expand All @@ -884,7 +900,7 @@ export async function main(
})
components.highlights?.resolve()
},
async registerSidebarScript(execute): Promise<void> {
async registerSidebarScript(execute) {
await execute({
events: sidebarEvents,
initialState: inPageUI.componentsShown.sidebar
Expand Down Expand Up @@ -919,7 +935,7 @@ export async function main(
})
components.sidebar?.resolve()
},
async registerTooltipScript(execute): Promise<void> {
async registerTooltipScript(execute) {
await execute({
inPageUI,
createHighlight: annotationsFunctions.createHighlight({
Expand All @@ -942,11 +958,13 @@ export async function main(
})
components.tooltip?.resolve()
},
async registerSearchInjectionScript(execute): Promise<void> {
async registerInPageUIInjectionScript(execute, errorDisplayProps) {
await execute({
syncSettingsBG,
syncSettings: createSyncSettingsStore({ syncSettingsBG }),
requestSearcher: remoteFunction('search'),
annotationsFunctions,
errorDisplayProps,
})
},
}
Expand All @@ -958,8 +976,8 @@ export async function main(
) ||
window.location.href.includes('youtube.com')
) {
await contentScriptRegistry.registerSearchInjectionScript(
searchInjectionMain,
await contentScriptRegistry.registerInPageUIInjectionScript(
InPageUIInjectionMain,
)
}

Expand All @@ -984,7 +1002,7 @@ export async function main(
}
return extractRawPageContent(doc, url)
},
ping: async () => true,
confirmTabScriptLoaded: async () => {},
showSidebar: inPageUI.showSidebar.bind(inPageUI),
showRibbon: inPageUI.showRibbon.bind(inPageUI),
testIfSidebarSetup: inPageUI.testIfSidebarSetup.bind(inPageUI),
Expand Down Expand Up @@ -1046,8 +1064,8 @@ export async function main(
) ||
window.location.href.includes('youtube.com')
) {
await contentScriptRegistry.registerSearchInjectionScript(
searchInjectionMain,
await contentScriptRegistry.registerInPageUIInjectionScript(
InPageUIInjectionMain,
)
}

Expand Down
6 changes: 3 additions & 3 deletions src/content-scripts/content_script/search-injection.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { initSearchInjection } from 'src/search-injection/content_script'
import { SearchInjectionMain } from 'src/content-scripts/content_script/types'
import type { SearchInjectionMain } from 'src/content-scripts/content_script/types'

export const main: SearchInjectionMain = async (options) => {
initSearchInjection(options)
export const main: SearchInjectionMain = async (...options) => {
initSearchInjection(...options)
}
16 changes: 15 additions & 1 deletion src/content-scripts/content_script/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,18 @@ import type { RemoteSyncSettingsInterface } from 'src/sync-settings/background/t
import type { PageAnnotationsCacheInterface } from 'src/annotations/cache/types'
import type { MaybePromise } from 'src/util/types'
import { AnalyticsCoreInterface } from '@worldbrain/memex-common/lib/analytics/types'
import { SyncSettingsStore } from 'src/sync-settings/util'
import type { ErrorDisplayProps } from 'src/search-injection/error-display'

export interface ContentScriptRegistry {
registerRibbonScript(main: RibbonScriptMain): Promise<void>
registerSidebarScript(main: SidebarScriptMain): Promise<void>
registerHighlightingScript(main: HighlightsScriptMain): Promise<void>
registerTooltipScript(main: TooltipScriptMain): Promise<void>
registerSearchInjectionScript(main: SearchInjectionMain): Promise<void>
registerInPageUIInjectionScript(
main: SearchInjectionMain,
errorDisplayProps?: ErrorDisplayProps,
): Promise<void>
}

export type SidebarScriptMain = (
Expand Down Expand Up @@ -52,7 +57,16 @@ export interface HighlightDependencies {
export interface SearchInjectionDependencies {
requestSearcher: any
syncSettingsBG: RemoteSyncSettingsInterface
syncSettings: SyncSettingsStore<
| 'extension'
| 'inPageUI'
| 'activityIndicator'
| 'openAI'
| 'searchInjection'
| 'dashboard'
>
annotationsFunctions: any
errorDisplayProps?: ErrorDisplayProps
}

export type HighlightsScriptMain = (
Expand Down
13 changes: 3 additions & 10 deletions src/custom-lists/background/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@ import type Storex from '@worldbrain/storex'
import type { Windows, Tabs, Storage } from 'webextension-polyfill'
import { normalizeUrl } from '@worldbrain/memex-common/lib/url-utils/normalize'
import { isFullUrl } from '@worldbrain/memex-common/lib/url-utils/normalize/utils'

import CustomListStorage from './storage'
import type { SearchIndex } from 'src/search'
import type {
RemoteCollectionsInterface,
CollectionsSettings,
PageList,
PageListEntry,
} from './types'
import { maybeIndexTabs } from 'src/page-indexing/utils'
Expand All @@ -19,7 +17,6 @@ import type { PageIndexingBackground } from 'src/page-indexing/background'
import type TabManagementBackground from 'src/tab-management/background'
import type { AuthServices } from 'src/services/types'
import type { ContentIdentifier } from '@worldbrain/memex-common/lib/page-indexing/types'
import { isExtensionTab } from 'src/tab-management/utils'
import type { AnalyticsCoreInterface } from '@worldbrain/memex-common/lib/analytics/types'
import type ContentSharingBackground from 'src/content-sharing/background'
import type { PKMSyncBackgroundModule } from 'src/pkm-integrations/background'
Expand Down Expand Up @@ -624,13 +621,9 @@ export default class CustomListBackground {

// Ensure content scripts are injected into each tab, so they can init page content identifier
await Promise.all(
tabs
.filter((tab) => !isExtensionTab(tab))
.map(async (tab) => {
await this.options.tabManagement.injectContentScriptsIfNeeded(
tab.id,
)
}),
tabs.map((tab) =>
this.options.tabManagement.injectContentScriptsIfNeeded(tab.id),
),
)

const indexed = await maybeIndexTabs(tabs, {
Expand Down
Loading

0 comments on commit 6bab36a

Please sign in to comment.