Skip to content

Commit

Permalink
Merge branch 'hotfix/3.13.3' of https://github.com/WorldBrain/Memex i…
Browse files Browse the repository at this point in the history
…nto hotfix/3.13.3
  • Loading branch information
blackforestboi committed Feb 27, 2024
2 parents 2888e38 + 2c36754 commit c36a35b
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 67 deletions.
123 changes: 59 additions & 64 deletions src/content-scripts/content_script/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ import { injectSubstackButtons } from './injectionUtils/substack'
import { extractRawPageContent } from '@worldbrain/memex-common/lib/page-indexing/content-extraction/extract-page-content'
import { extractRawPDFContent } from 'src/page-analysis/content_script/extract-page-content'
import type { ActivityIndicatorInterface } from 'src/activity-indicator/background'
import type { SearchDisplayProps } from 'src/search-injection/search-display'
import { createUIServices } from 'src/services/ui'
import type { ImageSupportInterface } from 'src/image-support/background/types'
import type { ContentConversationsInterface } from 'src/content-conversations/background/types'
Expand Down Expand Up @@ -458,6 +457,10 @@ export async function main(

// 3. Creates an instance of the InPageUI manager class to encapsulate
// business logic of initialising and hide/showing components.
const loadContentScript = createContentScriptLoader({
contentScriptsBG,
loadRemotely: params.loadRemotely,
})
const inPageUI = new SharedInPageUIState({
getNormalizedPageUrl: pageInfo.getNormalizedPageUrl,
loadComponent: async (component) => {
Expand Down Expand Up @@ -489,6 +492,7 @@ export async function main(
): Promise<{ annotationId: AutoPk; createPromise: Promise<void> }> {
const handleError = async (err: Error) => {
captureException(err)
await components.in_page_ui_injections
inPageUI.loadOnDemandInPageUI({
component: 'error-display',
options: {
Expand Down Expand Up @@ -883,6 +887,24 @@ export async function main(

return newState
}
async function maybeLoadOnDemandInPageUI() {
if (
shouldIncludeSearchInjection(
window.location.hostname,
window.location.href,
)
) {
await components.in_page_ui_injections
inPageUI.loadOnDemandInPageUI({
component: 'search-engine-integration',
})
} else if (window.location.href.includes('youtube.com')) {
await components.in_page_ui_injections
inPageUI.loadOnDemandInPageUI({
component: 'youtube-integration',
})
}
}

// 4. Create a contentScriptRegistry object with functions for each content script
// component, that when run, initialise the respective component with its
Expand Down Expand Up @@ -1000,56 +1022,46 @@ export async function main(
syncSettingsBG,
syncSettings: createSyncSettingsStore({ syncSettingsBG }),
requestSearcher: remoteFunction('search'),
searchDisplayProps,
searchDisplayProps: {
activityIndicatorBG,
searchBG: runInBackground(),
pdfViewerBG: runInBackground(),
summarizeBG,
analyticsBG,
authBG,
annotationsBG,
pageIndexingBG,
contentShareBG: contentSharingBG,
contentShareByTabsBG: contentSharingByTabsBG,
pageActivityIndicatorBG,
listsBG: collectionsBG,
contentConversationsBG,
contentScriptsBG,
imageSupportBG,
copyPasterBG,
syncSettingsBG,
analytics,
document,
location,
history,
annotationsCache,
copyToClipboard,
tabsAPI: browser.tabs,
runtimeAPI: browser.runtime,
localStorage: browser.storage.local,
services: createUIServices(),
renderUpdateNotifBanner: () => null,
bgScriptBG,
},
annotationsFunctions,
})
components.in_page_ui_injections?.resolve()
},
}
globalThis['contentScriptRegistry'] = contentScriptRegistry
await inPageUI.loadComponent('in_page_ui_injections')

const searchDisplayProps: SearchDisplayProps = {
activityIndicatorBG,
searchBG: runInBackground(),
pdfViewerBG: runInBackground(),
summarizeBG,
analyticsBG,
authBG,
annotationsBG,
pageIndexingBG,
contentShareBG: contentSharingBG,
contentShareByTabsBG: contentSharingByTabsBG,
pageActivityIndicatorBG,
listsBG: collectionsBG,
contentConversationsBG,
contentScriptsBG,
imageSupportBG,
copyPasterBG,
syncSettingsBG,
analytics,
document,
location,
history,
annotationsCache,
copyToClipboard,
tabsAPI: browser.tabs,
runtimeAPI: browser.runtime,
localStorage: browser.storage.local,
services: createUIServices(),
renderUpdateNotifBanner: () => null,
bgScriptBG,
}

if (
shouldIncludeSearchInjection(
window.location.hostname,
window.location.href,
) ||
window.location.href.includes('youtube.com')
) {
inPageUI.loadOnDemandInPageUI({
component: 'search-engine-integration',
})
}
await maybeLoadOnDemandInPageUI()

const pageHasBookark =
(await bookmarks.pageHasBookmark(fullPageUrl)) ||
Expand Down Expand Up @@ -1128,19 +1140,7 @@ export async function main(
return
}
await inPageUI.hideRibbon()

if (
shouldIncludeSearchInjection(
window.location.hostname,
window.location.href,
) ||
window.location.href.includes('youtube.com')
) {
inPageUI.loadOnDemandInPageUI({
component: 'youtube-integration',
})
}

await maybeLoadOnDemandInPageUI()
await injectCustomUIperPage(
annotationsFunctions,
pkmSyncBG,
Expand Down Expand Up @@ -1176,10 +1176,6 @@ export async function main(

// 6. Setup other interactions with this page (things that always run)
// setupScrollReporter()
const loadContentScript = createContentScriptLoader({
contentScriptsBG,
loadRemotely: params.loadRemotely,
})

// 7. check if highlights are enabled
const areHighlightsEnabled = await tooltipUtils.getHighlightsState()
Expand Down Expand Up @@ -1214,7 +1210,6 @@ export async function main(
// EXECUTE PROGRESSIVE LOADING SEQUENCES
////////////////////////////////////////////

globalThis['contentScriptRegistry'] = contentScriptRegistry
window['__annotationsCache'] = annotationsCache

await loadCacheDataPromise
Expand All @@ -1225,7 +1220,6 @@ export async function main(
// so it is included in this global content script where it adds less than 500kb.
await contentScriptRegistry.registerHighlightingScript(highlightMain)

await inPageUI.loadComponent('in_page_ui_injections')
if (areHighlightsEnabled) {
inPageUI.showHighlights()
if (!annotationsCache.isEmpty) {
Expand Down Expand Up @@ -1667,6 +1661,7 @@ export function setupWebUIActions(args: {
}
}

// TODO: Move this stuff to in-page-uis CS
export async function injectCustomUIperPage(
annotationsFunctions,
pkmSyncBG,
Expand Down
4 changes: 1 addition & 3 deletions src/content-scripts/content_script/tooltip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,15 @@ import {
} from 'src/in-page-ui/tooltip/content_script/interactions'
import { conditionallyShowOnboardingNotifications } from 'src/in-page-ui/tooltip/onboarding-interactions'
import { insertTutorial } from 'src/in-page-ui/tooltip/content_script/tutorialInteractions'
import { browser } from 'webextension-polyfill-ts'
import type { InPageUIRootMount } from 'src/in-page-ui/types'
import { createInPageUI, destroyInPageUI } from 'src/in-page-ui/utils'
import { IGNORE_CLICK_OUTSIDE_CLASS } from '../constants'

export const main: TooltipScriptMain = async (options) => {
const cssFile = browser.runtime.getURL(`/content_script_tooltip.css`)
let mount: InPageUIRootMount | null = null
const createMount = () => {
if (!mount) {
mount = createInPageUI('tooltip', cssFile, [
mount = createInPageUI('tooltip', null, [
IGNORE_CLICK_OUTSIDE_CLASS,
])
}
Expand Down

0 comments on commit c36a35b

Please sign in to comment.