mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-20 18:57:17 +03:00
fix(browser): say sign-ins, not cookies, in the import and data texts (#65095)
This commit is contained in:
committed by
GitHub
Unverified
parent
a96327d3e8
commit
d6b7756d17
@@ -1627,9 +1627,10 @@ story("shows the page's cookies in the site information and clears them", async
|
||||
await root.getByRole("button", { name: "Site information", exact: true }).click()
|
||||
const site = page.getByRole("dialog")
|
||||
await site.getByRole("button", { name: "Site settings", exact: true }).click()
|
||||
await expect(site).toContainText("3 cookies in use")
|
||||
// The row is "Cookies and site data", so its count needs no more words.
|
||||
await expect(site.getByText("3 cookies", { exact: true })).toBeVisible()
|
||||
await site.getByRole("button", { name: "Clear", exact: true }).click()
|
||||
await expect(site).toContainText("0 cookies in use")
|
||||
await expect(site.getByText("0 cookies", { exact: true })).toBeVisible()
|
||||
})
|
||||
|
||||
story("site information opens on the site and its connection, with the rest one step away", async ({ page }) => {
|
||||
@@ -1639,19 +1640,19 @@ story("site information opens on the site and its connection, with the rest one
|
||||
// First: where the person is and whether the connection is private. Nothing about cookies or agents yet.
|
||||
await expect(site).toContainText("alpha.example")
|
||||
await expect(site).toContainText("Connection is secure")
|
||||
await expect(site).not.toContainText("cookies in use")
|
||||
await expect(site).not.toContainText(/cookie/i)
|
||||
const settings = site.getByRole("button", { name: "Site settings", exact: true })
|
||||
await settings.click()
|
||||
// Second: everything else, with the way back holding the keyboard.
|
||||
await expect(site.getByRole("button", { name: "Back", exact: true })).toBeFocused()
|
||||
await expect(site).toContainText("3 cookies in use")
|
||||
await expect(site.getByText("3 cookies", { exact: true })).toBeVisible()
|
||||
await expect(site).toContainText("You stay signed in.")
|
||||
await expect(site.getByRole("button", { name: "Clear saved files for this site", exact: true })).toBeEnabled()
|
||||
await expect(site).toContainText("Agents you allow can use this page")
|
||||
// Escape steps back one view, then closes.
|
||||
await page.keyboard.press("Escape")
|
||||
await expect(settings).toBeFocused()
|
||||
await expect(site).not.toContainText("cookies in use")
|
||||
await expect(site).not.toContainText(/cookie/i)
|
||||
await page.keyboard.press("Escape")
|
||||
await expect(site).toBeHidden()
|
||||
})
|
||||
@@ -1662,11 +1663,11 @@ story("says a failed cookie read failed and reads again on retry", async ({ page
|
||||
await root.getByRole("button", { name: "Site information", exact: true }).click()
|
||||
const site = page.getByRole("dialog")
|
||||
await site.getByRole("button", { name: "Site settings", exact: true }).click()
|
||||
await expect(site).toContainText("Couldn't read this site's cookies.")
|
||||
await expect(site.getByText("Could not read site data.", { exact: true })).toBeVisible()
|
||||
const retry = site.getByRole("button", { name: "Try again", exact: true })
|
||||
await expect(retry).toBeEnabled()
|
||||
await retry.click()
|
||||
await expect(site).toContainText("3 cookies in use")
|
||||
await expect(site.getByText("3 cookies", { exact: true })).toBeVisible()
|
||||
await expect(site.getByRole("button", { name: "Clear", exact: true })).toBeEnabled()
|
||||
})
|
||||
|
||||
|
||||
@@ -10,7 +10,10 @@ const modules = {
|
||||
|
||||
// Any story loads the app styles; the fixture mounts the real Settings > Browser page beside it. `target` is the entry
|
||||
// a settings search or the command palette is revealing.
|
||||
async function open(page: Page, options?: { target?: string; extensions?: boolean; installed?: boolean; historyKept?: boolean }) {
|
||||
async function open(
|
||||
page: Page,
|
||||
options?: { target?: string; extensions?: boolean; installed?: boolean; historyKept?: boolean; file?: { imported: number; failed: number } | "unreadable" },
|
||||
) {
|
||||
await page.evaluate(
|
||||
async (input) => {
|
||||
const [{ mountBrowserSettings }, { ui }] = await Promise.all([import(input.modules.fixture), import(input.modules.ui)])
|
||||
@@ -21,6 +24,7 @@ async function open(page: Page, options?: { target?: string; extensions?: boolea
|
||||
extensions: input.options?.extensions,
|
||||
installed: input.options?.installed,
|
||||
historyKept: input.options?.historyKept,
|
||||
file: input.options?.file,
|
||||
})
|
||||
},
|
||||
{ modules, options },
|
||||
@@ -72,17 +76,37 @@ story("no setting decides what an import brings: the import section has its brow
|
||||
await expect(view.stored).not.toContainText("importHistory")
|
||||
})
|
||||
|
||||
story("a sign-out that left the history behind says so in its row, and still forgets the window's last pages", async ({ page }) => {
|
||||
story("clearing browsing data that left the history behind says so in its row, and still forgets the window's last pages", async ({ page }) => {
|
||||
const view = await open(page, { target: "settings-browser-cookies", historyKept: true })
|
||||
const data = view.root.getByRole("region", { name: "Browser data", exact: true })
|
||||
const clear = data.getByRole("button", { name: "Clear browsing data", exact: true })
|
||||
|
||||
await expect(view.root.getByTestId("browser-settings-visits")).toHaveText("1")
|
||||
await view.root.getByRole("button", { name: "Sign out everywhere", exact: true }).click()
|
||||
// The sign-out itself worked, so the row does not call it failed; "everywhere" alone would be a false claim.
|
||||
await expect(view.root.getByText("Signed out everywhere. The history could not be cleared.", { exact: true })).toBeVisible()
|
||||
await expect(data.getByText("0 cookies. Sign-ins are shared across sessions.", { exact: true })).toBeVisible()
|
||||
await clear.click()
|
||||
// The sign-ins and site data went, so the row does not call it failed; it says what stayed.
|
||||
await expect(data.getByText("Cleared browsing data. The history could not be cleared.", { exact: true })).toBeVisible()
|
||||
await expect(view.root.getByTestId("browser-settings-visits")).toHaveText("0")
|
||||
await expect(view.root.getByRole("button", { name: "Sign out everywhere", exact: true })).toBeEnabled()
|
||||
await expect(clear).toBeEnabled()
|
||||
})
|
||||
|
||||
// A cookie file is cookies, so its row counts them: the one place an import says "cookies".
|
||||
for (const [name, file, line] of [
|
||||
["a cookie file that came whole", { imported: 12, failed: 0 }, "Imported 12 cookies."],
|
||||
["a cookie file that lost some", { imported: 12, failed: 3 }, "Imported 12 cookies, 3 skipped."],
|
||||
["a cookie file that brought one", { imported: 1, failed: 1 }, "Imported 1 cookie, 1 skipped."],
|
||||
// No browser's data, and no browser to close: the line is about the file.
|
||||
["a cookie file that cannot be read", "unreadable", "Could not read this file."],
|
||||
] as const)
|
||||
story(`${name} says so in its row: ${line}`, async ({ page }) => {
|
||||
const view = await open(page, { target: "settings-browser-cookies", file })
|
||||
|
||||
await expect(view.root.getByText("Import cookie file", { exact: true })).toBeVisible()
|
||||
await expect(view.root.getByText("Supports cookies.txt or JSON from browser extensions or Playwright.", { exact: true })).toBeVisible()
|
||||
await view.root.getByRole("button", { name: "Choose file", exact: true }).click()
|
||||
await expect(view.root.getByText(line, { exact: true })).toBeVisible()
|
||||
})
|
||||
|
||||
story("Add an extension aligns controls without top clipping and switches cleanly into a confirmation step", async ({ page }) => {
|
||||
const view = await open(page, { extensions: true })
|
||||
|
||||
|
||||
@@ -12,6 +12,9 @@ type SiteScenario = {
|
||||
site?: { name: string; choose: boolean }
|
||||
reveal?: boolean
|
||||
pages?: number
|
||||
none?: boolean
|
||||
keychain?: boolean
|
||||
unreadable?: boolean
|
||||
}
|
||||
|
||||
const source = (path: string) => sourceURL(new URL(path, import.meta.url))
|
||||
@@ -300,7 +303,7 @@ story("shows what the list is doing in its place, with a way to try again", asyn
|
||||
story("says why a profile has no list, and reads it again on Try again", async ({ page }) => {
|
||||
const view = await open(page, { sites: "locked" })
|
||||
|
||||
await expect(view.dialog.getByRole("alert")).toHaveText("Google Chrome keeps its cookies locked while it runs. Quit Google Chrome, then import again.")
|
||||
await expect(view.dialog.getByRole("alert")).toHaveText("Quit Google Chrome and try again.")
|
||||
await view.dialog.getByRole("button", { name: "Try again" }).click()
|
||||
await expect(view.record).toHaveAttribute("data-reads", "Default,Default")
|
||||
})
|
||||
@@ -529,6 +532,42 @@ story("the bar's own dialog brings history alone when Sign-ins is unticked, and
|
||||
await expect(bar.record).toHaveAttribute("data-imported", "0")
|
||||
})
|
||||
|
||||
story("a browser's import never counts cookies: with none brought the bar says nothing was imported, or that the browser locks them", async ({ page }) => {
|
||||
// One sign-in could not be written and none came: no history either, so nothing was imported.
|
||||
const bar = await offer(page, { sites: 5, none: true, partial: true })
|
||||
|
||||
await bar.importing.click()
|
||||
await expect(page.getByRole("alert")).toHaveText("Nothing was imported from Google Chrome.")
|
||||
await expect(bar.confirmation).toHaveCount(0)
|
||||
})
|
||||
|
||||
story("the import dialog stays open to say that the browser locks its sign-ins from other apps", async ({ page }) => {
|
||||
const view = await open(page, { sites: 5, reveal: false, none: true, protected: 12 })
|
||||
|
||||
await view.importButton.click()
|
||||
await expect(view.dialog.getByRole("alert")).toHaveText("Google Chrome locks its sign-ins from other apps. Sign in here instead.")
|
||||
await expect(view.record).toHaveAttribute("data-closed", "false")
|
||||
})
|
||||
|
||||
story("a browser whose data cannot be read says so about the browser, with what to do", async ({ page }) => {
|
||||
const view = await open(page, { sites: 5, reveal: false, unreadable: true })
|
||||
|
||||
await view.importButton.click()
|
||||
await expect(view.dialog.getByRole("alert")).toHaveText("Could not read this browser's data. Close it and try again.")
|
||||
await expect(view.record).toHaveAttribute("data-closed", "false")
|
||||
})
|
||||
|
||||
story("on macOS the dialog says what the Keychain prompt asks while a Chromium import waits, and not to choose Always Allow", async ({ page }) => {
|
||||
const view = await open(page, { sites: 5, reveal: false, keychain: true })
|
||||
|
||||
await view.importButton.click()
|
||||
await expect(view.dialog.getByRole("status")).toHaveText(
|
||||
'macOS asks for your password (shown as "security") to import Google Chrome\'s sign-ins. Choose Allow, not Always Allow, which lets any app read them without asking.',
|
||||
)
|
||||
await page.getByTestId("site-chooser-release").dispatchEvent("click")
|
||||
await expect(view.record).toHaveAttribute("data-closed", "true")
|
||||
})
|
||||
|
||||
story("the offer card has a title and no paragraph, and its Import brings both", async ({ page }) => {
|
||||
const card = await offer(page, { sites: 5, pages: 4210 }, true)
|
||||
const region = page.getByRole("region", { name: "Bring your sign-ins and history", exact: true })
|
||||
|
||||
@@ -57,8 +57,8 @@ export default {
|
||||
"site.file.description": "Only files inside this session's workspace can open here.",
|
||||
"site.network": "Pages load over the internet connection of {{server}}.",
|
||||
"site.cookies": "Cookies and site data",
|
||||
"site.cookies.count.one": "{{count}} cookie in use",
|
||||
"site.cookies.count.other": "{{count}} cookies in use",
|
||||
"site.cookies.count.one": "{{count}} cookie",
|
||||
"site.cookies.count.other": "{{count}} cookies",
|
||||
"site.cookies.clear": "Clear",
|
||||
"site.permissions": "Permissions",
|
||||
"site.permissions.description":
|
||||
@@ -158,8 +158,8 @@ export default {
|
||||
"signins.dismiss": "Not now",
|
||||
"signins.imported.one": "Imported {{count}} cookie.",
|
||||
"signins.imported.other": "Imported {{count}} cookies.",
|
||||
"signins.imported.incomplete.one": "Imported {{count}} cookie. Not imported: {{omitted}}.",
|
||||
"signins.imported.incomplete.other": "Imported {{count}} cookies. Not imported: {{omitted}}.",
|
||||
"signins.imported.incomplete.one": "Imported {{count}} cookie, {{omitted}} skipped.",
|
||||
"signins.imported.incomplete.other": "Imported {{count}} cookies, {{omitted}} skipped.",
|
||||
"signins.imported.from": "Imported sign-ins from {{browser}}",
|
||||
"signins.imported.history.from": "Imported sign-ins and history from {{browser}}",
|
||||
"signins.imported.history.only.from": "Imported history from {{browser}}",
|
||||
@@ -167,25 +167,26 @@ export default {
|
||||
"signins.imported.partial": "Imported. Some sites will ask you to sign in again.",
|
||||
"signins.imported.partial.named": "Imported from {{browser}}. Some sites will ask you to sign in again.",
|
||||
"signins.protected":
|
||||
"This browser keeps its sign-ins locked so that only it can read them. Sign in to your sites here.",
|
||||
"This browser locks its sign-ins from other apps. Sign in here instead.",
|
||||
"signins.protected.named":
|
||||
"{{browser}} keeps its sign-ins locked so that only it can read them. Sign in to your sites here.",
|
||||
"signins.failed.key": "Your system did not unlock this browser's sign-ins. Allow access when your system asks, then try again.",
|
||||
"signins.failed.access": "Your system denied access. On macOS, give OpenCode Full Disk Access to import from Safari.",
|
||||
"signins.failed.locked": "This browser keeps its cookies locked while it runs. Quit it, then import again.",
|
||||
"{{browser}} locks its sign-ins from other apps. Sign in here instead.",
|
||||
"signins.failed.key": "Access was denied. Try again and allow access when asked.",
|
||||
"signins.failed.access": "Access was denied. On macOS, give OpenCode Full Disk Access to import from Safari.",
|
||||
"signins.failed.locked": "Quit this browser and try again.",
|
||||
"signins.failed.locked.named":
|
||||
"{{browser}} keeps its cookies locked while it runs. Quit {{browser}}, then import again.",
|
||||
"signins.failed.read": "This browser's data could not be read. Close the browser and try again.",
|
||||
"signins.failed.format": "This file is not a cookie export.",
|
||||
"signins.failed.storage": "OpenCode cannot save sign-ins on this computer, so nothing was imported.",
|
||||
"Quit {{browser}} and try again.",
|
||||
"signins.failed.read": "Could not read this browser's data. Close it and try again.",
|
||||
"signins.failed.read.file": "Could not read this file.",
|
||||
"signins.failed.format": "This is not a cookie file.",
|
||||
"signins.failed.storage": "OpenCode cannot save sign-ins on this computer.",
|
||||
"signins.keychain":
|
||||
'macOS asks for your password so OpenCode can read the key to {{browser}}\'s cookies. The request names "security", a macOS tool OpenCode uses for this. Choose Allow. Do not choose Always Allow: it lets any app on this Mac read the key without asking.',
|
||||
'macOS asks for your password (shown as "security") to import {{browser}}\'s sign-ins. Choose Allow, not Always Allow, which lets any app read them without asking.',
|
||||
"signins.failed.keychain":
|
||||
"macOS did not give OpenCode the key to {{browser}}'s cookies. Import again and choose Allow when macOS asks. Do not choose Always Allow.",
|
||||
"macOS blocked access to {{browser}}'s sign-ins. Try again and choose Allow, not Always Allow.",
|
||||
"signins.unsaved":
|
||||
"OpenCode cannot save sign-ins: the system did not give it the key that protects them. Sign-ins made here end when OpenCode quits, so importing is off.",
|
||||
"Sign-ins will not be saved after you quit, and importing is off.",
|
||||
"signins.unsaved.mac":
|
||||
"OpenCode cannot save sign-ins: macOS did not give it its Keychain key. Sign-ins made here end when OpenCode quits, so importing is off. Quit OpenCode, open it again, and choose Allow when macOS asks.",
|
||||
"Sign-ins will not be saved after you quit, and importing is off. Restart OpenCode and choose Allow when macOS asks.",
|
||||
"settings.title": "Browser",
|
||||
"settings.open": "Browser settings",
|
||||
"settings.unavailable": "The browser is available in the desktop app.",
|
||||
@@ -211,8 +212,8 @@ export default {
|
||||
"sites.loading": "Reading the sites in {{browser}}…",
|
||||
"sites.empty": "This profile has no sites to import.",
|
||||
"sites.unmatched": "No site matches your search.",
|
||||
"settings.import.file.title": "Import a cookie file",
|
||||
"settings.import.file.description": "A cookies.txt file, or a JSON export from a cookie extension or Playwright.",
|
||||
"settings.import.file.title": "Import cookie file",
|
||||
"settings.import.file.description": "Supports cookies.txt or JSON from browser extensions or Playwright.",
|
||||
"settings.import.file.action": "Choose file",
|
||||
"settings.import.file.pick": "Choose a cookie file",
|
||||
"settings.extensions.title": "Extensions",
|
||||
@@ -235,13 +236,13 @@ export default {
|
||||
"settings.extensions.done": "Done",
|
||||
"settings.extensions.remove": "Remove {{name}}",
|
||||
"settings.extensions.enable": "Turn on {{name}}",
|
||||
"settings.data.title": "Site data",
|
||||
"settings.data.title": "Browser data",
|
||||
"settings.cookies.title": "Cookies and site data",
|
||||
"settings.cookies.count.one": "{{count}} cookie. Every session uses the same sign-ins.",
|
||||
"settings.cookies.count.other": "{{count}} cookies. Every session uses the same sign-ins.",
|
||||
"settings.cookies.clear": "Sign out everywhere",
|
||||
"settings.cleared": "Signed out everywhere.",
|
||||
"settings.cleared.history": "Signed out everywhere. The history could not be cleared.",
|
||||
"settings.cookies.count.one": "{{count}} cookie. Sign-ins are shared across sessions.",
|
||||
"settings.cookies.count.other": "{{count}} cookies. Sign-ins are shared across sessions.",
|
||||
"settings.cookies.clear": "Clear browsing data",
|
||||
"settings.cleared": "Cleared browsing data.",
|
||||
"settings.cleared.history": "Cleared browsing data. The history could not be cleared.",
|
||||
"menu.back": "Back",
|
||||
"menu.forward": "Forward",
|
||||
"menu.reload": "Reload",
|
||||
@@ -335,7 +336,7 @@ export default {
|
||||
"prompt.system.camera.other": "The system did not let OpenCode use the camera.",
|
||||
"prompt.system.microphone.other": "The system did not let OpenCode use the microphone.",
|
||||
"settings.sites.title": "Site permissions",
|
||||
"settings.sites.note": "Your saved answers apply in the tabs you use yourself. Sites ask again in tabs the agent works in and in tabs of remote servers. Signing out everywhere keeps these answers.",
|
||||
"settings.sites.note": "Your saved answers apply in the tabs you use yourself. Sites ask again in tabs the agent works in and in tabs of remote servers. Clearing browsing data keeps these answers.",
|
||||
"settings.sites.none": "No saved site permissions",
|
||||
"settings.sites.allow": "Allowed",
|
||||
"settings.sites.block": "Blocked",
|
||||
@@ -410,7 +411,7 @@ export default {
|
||||
"link.copyFailed": "Couldn't copy the link.",
|
||||
"link.failed": "Couldn't open this link. Try again.",
|
||||
"site.clearFailed": "Couldn't clear this site's data. Try again.",
|
||||
"site.cookies.failed": "Couldn't read this site's cookies.",
|
||||
"site.cookies.failed": "Could not read site data.",
|
||||
"site.clearCache.description": "You stay signed in.",
|
||||
"refused.failed": "Couldn't do that. Try again.",
|
||||
"model.failed": "The browser couldn't open",
|
||||
@@ -418,7 +419,7 @@ export default {
|
||||
"settings.failed.import": "Couldn't import. Try again.",
|
||||
"settings.failed.install": "Couldn't add this extension. Try again.",
|
||||
"settings.failed.extension": "Couldn't change this extension. Try again.",
|
||||
"settings.failed.clear": "Couldn't sign out. Try again.",
|
||||
"settings.failed.clear": "Couldn't clear browsing data. Try again.",
|
||||
"sites.failed": "Couldn't read the sites in this browser.",
|
||||
"settings.developers": "For developers",
|
||||
"site.settings": "Site settings",
|
||||
@@ -429,7 +430,7 @@ export default {
|
||||
"import.some.other": "Import {{number}} sites",
|
||||
"settings.import.open": "Import…",
|
||||
"settings.advanced": "Advanced",
|
||||
"settings.advanced.summary": "Remote servers, site permissions, sign out, cookie file",
|
||||
"settings.advanced.summary": "Remote servers, site permissions, browsing data, cookie file",
|
||||
"review.works": "Works here",
|
||||
"review.summary.allSites": "Can read and change every website you visit.",
|
||||
"review.summary.someSites": "Can read and change pages on some sites.",
|
||||
|
||||
@@ -219,21 +219,29 @@ export function createProfileJobs(
|
||||
if (result.type === "failed" && result.reason === "key" && browser && keychain(finished.job))
|
||||
return { text: ctx.t("signins.failed.keychain", { browser }), error: true }
|
||||
|
||||
// A cookie file that cannot be read is no browser's data, and there is no browser to close.
|
||||
if (result.type === "failed" && result.reason === "read" && finished.job.type === "import-file")
|
||||
return { text: ctx.t("signins.failed.read.file"), error: true }
|
||||
|
||||
if (result.type === "failed") return { text: ctx.t(`signins.failed.${result.reason}`), error: true }
|
||||
|
||||
const loss = importLoss(result)
|
||||
|
||||
// A cookie file is cookies and says so in counts: how many came, and how many did not. A browser's import counts
|
||||
// them only when none came.
|
||||
if (loss?.reason === "other" && (result.imported === 0 || finished.job.type === "import-file"))
|
||||
// A cookie file is cookies and says so in counts: how many came, and how many did not. A browser's import never
|
||||
// counts cookies.
|
||||
if (loss?.reason === "other" && finished.job.type === "import-file")
|
||||
return { text: ctx.plural("signins.imported.incomplete", result.imported, { omitted: loss.count }), error: result.imported === 0 }
|
||||
|
||||
if (result.imported === 0 && loss)
|
||||
if (result.imported === 0 && loss?.reason === "protected")
|
||||
return {
|
||||
text: browser ? ctx.t("signins.protected.named", { browser }) : ctx.t("signins.protected"),
|
||||
error: true,
|
||||
}
|
||||
|
||||
// No sign-in could be brought and no history came with them: nothing was imported.
|
||||
if (result.imported === 0 && loss && !result.pages)
|
||||
return { text: browser ? ctx.t("signins.imported.none.from", { browser }) : ctx.t("settings.failed.import"), error: true }
|
||||
|
||||
// Some sign-ins stayed behind, as Chrome's and Edge's app-bound ones on Windows do: their sites open signed out.
|
||||
if (loss)
|
||||
return {
|
||||
|
||||
@@ -34,7 +34,7 @@ const setup: Plugin.MainSetup = (ctx) => {
|
||||
const loads = new Map<number, ReturnType<typeof Promise.withResolvers<Pane>>>()
|
||||
let disposing: Promise<void> | undefined
|
||||
const refs = ctx.storage.store("refs", RefsStore)
|
||||
// The permission decisions the user kept for sites; "Sign out everywhere" keeps them, as they are settings.
|
||||
// The permission decisions the user kept for sites; "Clear browsing data" keeps them, as they are settings.
|
||||
const sites = createSitePermissions(ctx.storage, () => sitesIpc.changed())
|
||||
// The desktop's one browser profile, created the first time a pane or the settings page needs it. A failed creation
|
||||
// is forgotten, so the next request tries again.
|
||||
|
||||
@@ -488,7 +488,7 @@ const setup: Plugin.Setup<typeof definition> = (ctx) => {
|
||||
title: ctx.t("settings.remote.title"),
|
||||
keywords: "remote server sign in cookies share",
|
||||
},
|
||||
{ id: "settings-browser-cookies", title: ctx.t("settings.cookies.title"), keywords: "cookies sign out history clear" },
|
||||
{ id: "settings-browser-cookies", title: ctx.t("settings.cookies.title"), keywords: "cookies sign out browsing data history clear" },
|
||||
{
|
||||
id: "settings-browser-import",
|
||||
title: ctx.t("settings.import.title"),
|
||||
|
||||
@@ -6,7 +6,7 @@ import { liveAccessor, PluginContext } from "@opencode/plugin/gui/host"
|
||||
import type { Context, SetupContext, Ui } from "@opencode/plugin/gui"
|
||||
import browserEn from "./i18n/en"
|
||||
import type definition from "./index"
|
||||
import type { ExtensionAccess, ExtensionCompatibility, InstallResult, ProfileSource } from "./profile/ipc"
|
||||
import type { ExtensionAccess, ExtensionCompatibility, ImportResult, InstallResult, ProfileSource } from "./profile/ipc"
|
||||
import BrowserSettings from "./settings"
|
||||
|
||||
type SampleExtension = {
|
||||
@@ -77,8 +77,16 @@ const sampleExtensionEntries: readonly (readonly [string, readonly SampleExtensi
|
||||
// their Ipcs, and the stored preferences shown beside the page. `target` is the entry a settings search is revealing,
|
||||
// which stays set for the whole visit, as the host leaves it. With `extensions`, Chromium browsers and their extensions
|
||||
// are populated so the real Add an extension dialog can be driven end to end. `historyKept` is a sign-out that left
|
||||
// main's history behind: its file could not be removed.
|
||||
export function mountBrowserSettings(input: { ui: Ui; target?: string; extensions?: boolean; installed?: boolean; historyKept?: boolean }) {
|
||||
// main's history behind: its file could not be removed. `file` is what importing the cookie file the person picks
|
||||
// brings: how many cookies came and how many could not be imported, or that the file could not be read.
|
||||
export function mountBrowserSettings(input: {
|
||||
ui: Ui
|
||||
target?: string
|
||||
extensions?: boolean
|
||||
installed?: boolean
|
||||
historyKept?: boolean
|
||||
file?: { imported: number; failed: number } | "unreadable"
|
||||
}) {
|
||||
const host = document.createElement("main")
|
||||
host.dataset.testid = "browser-settings-fixture"
|
||||
document.body.appendChild(host)
|
||||
@@ -127,6 +135,11 @@ export function mountBrowserSettings(input: { ui: Ui; target?: string; extension
|
||||
sources: async () => (input.extensions ? [...sampleSources] : []),
|
||||
summary: async () => ({ cookies: 0, persistent: true }),
|
||||
clear: async () => ({ history: !input.historyKept }),
|
||||
importFile: async (): Promise<ImportResult> => {
|
||||
if (input.file === "unreadable") return { type: "failed", reason: "read" }
|
||||
|
||||
return { type: "imported", imported: input.file?.imported ?? 0, skipped: 0, protected: 0, failed: input.file?.failed ?? 0 }
|
||||
},
|
||||
browserExtensions: async (request: { source: string; profile: string }) =>
|
||||
input.extensions
|
||||
? (sampleExtensions.get(request.source) ?? []).map((item) => ({
|
||||
@@ -205,7 +218,8 @@ export function mountBrowserSettings(input: { ui: Ui; target?: string; extension
|
||||
t(`${key}.${count === 1 ? "one" : "other"}`, { ...params, count }),
|
||||
use: () => live,
|
||||
signal: controller.signal,
|
||||
desktop: { os: "windows" },
|
||||
// The person picks a made-up cookie file.
|
||||
desktop: { os: "windows", pick: async () => ["C:\\made-up\\cookies.txt"] },
|
||||
dialogs: {
|
||||
open: (content: (handle: { close: () => void }) => JSX.Element) => {
|
||||
const handle = { close: () => dialog.close() }
|
||||
|
||||
@@ -26,6 +26,12 @@ export type SiteScenario = {
|
||||
readonly empty?: boolean
|
||||
readonly site?: { readonly name: string; readonly choose: boolean }
|
||||
readonly pages?: number
|
||||
/** The browser's files could not be read when the import ran. */
|
||||
readonly unreadable?: boolean
|
||||
/** No cookie could be brought: the import counts none, whatever it lost. */
|
||||
readonly none?: boolean
|
||||
/** The app runs on macOS, where a Chromium browser's import waits at the Keychain prompt: this one waits for the test. */
|
||||
readonly keychain?: boolean
|
||||
}
|
||||
|
||||
/** The dialog host, once the opener mounts under it: the offer opens its own import dialog there. */
|
||||
@@ -105,8 +111,12 @@ export function mountSiteChooser(input: { ui: Ui; scenario: SiteScenario; direct
|
||||
},
|
||||
importBrowser: async (request: { source: string; profile: string; sites?: readonly string[]; cookies?: boolean; history?: boolean }): Promise<ImportResult> => {
|
||||
setStore("imports", (items) => [...items, request])
|
||||
|
||||
if (input.scenario.keychain) await held.promise
|
||||
|
||||
if (input.scenario.unreadable) return { type: "failed", reason: "read" }
|
||||
// Without a list of sites, main imports the whole profile; without cookies, only its history.
|
||||
const count = request.cookies === false ? 0 : (request.sites?.length ?? 5) * 2
|
||||
const count = request.cookies === false || input.scenario.none ? 0 : (request.sites?.length ?? 5) * 2
|
||||
|
||||
return {
|
||||
type: "imported",
|
||||
@@ -135,7 +145,7 @@ export function mountSiteChooser(input: { ui: Ui; scenario: SiteScenario; direct
|
||||
t(`${key}.${count === 1 ? "one" : "other"}`, { ...params, count }),
|
||||
use: () => live,
|
||||
signal: controller.signal,
|
||||
desktop: { os: "windows" },
|
||||
desktop: { os: input.scenario.keychain ? "macos" : "windows" },
|
||||
stores: { preferences: { value: { links: true, welcomed: !input.offer }, set() {} } },
|
||||
layout: { settings() {} },
|
||||
dialogs: {
|
||||
|
||||
Reference in New Issue
Block a user