diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 8318e280..2cf4c952 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -49,7 +49,6 @@ jobs: else git checkout -b releases fi - - name: Collect commit ranges run: | diff --git a/CHANGELOG.txt b/CHANGELOG.txt index b47aa8e4..dfe942bb 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,8 +1,3 @@ -- fix release flow -- Remove artifacts from 'main' (#227) -- Add config to ignore linting PRs (#224) -- Consistent Prettier config (#222) -- Bump typedoc from 0.26.8 to 0.26.11 (#199) -- Shared eslint config (#198) -- Adds JSON example to Toggle Report guide (#197) -- Grey out icons depending on phishingStatus (#195) \ No newline at end of file +- windows interop messaging (#228) +- prettier +- add netlify file \ No newline at end of file diff --git a/build/app/public/js/base.js b/build/app/public/js/base.js index f1dbf9cb..d5a77485 100644 --- a/build/app/public/js/base.js +++ b/build/app/public/js/base.js @@ -14654,8 +14654,8 @@ resolveInitialRender3(); } function windowsPostMessage(name, data) { - assert(typeof window.chrome.webview?.postMessage === "function"); - window.chrome.webview.postMessage({ + assert(typeof globalThis.windowsInteropPostMessage === "function"); + globalThis.windowsInteropPostMessage({ Feature: "PrivacyDashboard", Name: name, Data: data @@ -14761,13 +14761,13 @@ } } function setup5() { - if (!window.chrome.webview) { - console.error("window.chrome.webview not available"); + if (!globalThis.windowsInteropPostMessage) { + console.error("globalThis.windowsInteropPostMessage"); return; } setupColorScheme(); - assert(typeof window.chrome.webview?.addEventListener === "function", "window.chrome.webview.addEventListener is required"); - window.chrome.webview.addEventListener("message", (event) => { + assert(typeof globalThis.windowsInteropAddEventListener === "function", "globalThis.windowsInteropAddEventListener required"); + globalThis.windowsInteropAddEventListener("message", (event) => { handleIncomingMessage(event.data); }); setupMutationObserver((height) => { diff --git a/netlify.toml b/netlify.toml new file mode 100644 index 00000000..e8b6b7c4 --- /dev/null +++ b/netlify.toml @@ -0,0 +1,2 @@ +[build] +ignore = "git log -1 --pretty=%B | grep dependabot" diff --git a/shared/js/browser/utils/communication-mocks.mjs b/shared/js/browser/utils/communication-mocks.mjs index 7ddf2412..2a360d67 100644 --- a/shared/js/browser/utils/communication-mocks.mjs +++ b/shared/js/browser/utils/communication-mocks.mjs @@ -68,17 +68,12 @@ export function windowsMockApis() { }, calls: [], }; - // override some methods on window.chrome.runtime to fake the incoming/outgoing messages - window.chrome.webview = { - // @ts-ignore - addEventListener: (messageName, listener) => { - window.__playwright.listeners?.push(listener); - }, - postMessage(arg) { - window.__playwright.mocks.outgoing.push([arg.Name, arg]); - }, + globalThis.windowsInteropAddEventListener = (messageName, listener) => { + window.__playwright.listeners?.push(listener); + }; + globalThis.windowsInteropPostMessage = (arg) => { + window.__playwright.mocks.outgoing.push([arg.Name, arg]); }; - // console.log('window.chrome.webview', window.chrome.webview) } catch (e) { console.error("❌couldn't set up mocks"); console.error(e); diff --git a/shared/js/browser/windows-communication.js b/shared/js/browser/windows-communication.js index 50c8eff4..0e0c3598 100644 --- a/shared/js/browser/windows-communication.js +++ b/shared/js/browser/windows-communication.js @@ -5,7 +5,7 @@ * The Dashboard receives data from Windows by registering a listener on `window.chrome.webview` * * ```js - * window.chrome.webview.addEventListener('message', (event) => handleViewModelUpdate(event.data)) + * globalThis.windowsInteropAddEventListener('message', (event) => handleViewModelUpdate(event.data)) * ``` * * Tip: See {@link "Windows integration".handleIncomingMessage} for details of supported messages. @@ -15,7 +15,7 @@ * When the dashboard needs to communicate back to the Windows application, it will do so in the following way... * * ```js - * window.chrome.webview.postMessage({ + * globalThis.windowsInteropPostMessage({ * Feature: 'PrivacyDashboard', * Name: name, * Data: data @@ -96,7 +96,7 @@ const resolveInitialRender = function () { * @example * * ```js - * window.chrome.webview.addEventListener('message', event => handleViewModelUpdate(event.data)) + * globalThis.windowsInteropAddEventListener('message', event => handleViewModelUpdate(event.data)) * ``` * * @param {import('../../../schema/__generated__/schema.types').WindowsViewModel} viewModel @@ -121,8 +121,8 @@ function handleViewModelUpdate(viewModel) { // ----------------------------------------------------------------------------- function windowsPostMessage(name, data) { - assert(typeof window.chrome.webview?.postMessage === 'function'); - window.chrome.webview.postMessage({ + assert(typeof globalThis.windowsInteropPostMessage === 'function'); + globalThis.windowsInteropPostMessage({ Feature: 'PrivacyDashboard', Name: name, Data: data, @@ -190,7 +190,7 @@ async function fetch(message) { * @example * * ```javascript - * window.chrome.webview.postMessage({ + * globalThis.windowsInteropPostMessage({ * Feature: 'PrivacyDashboard', * Name: 'SubmitBrokenSiteReport', * Data: { category: "videos", description: "something was broken :(" } @@ -212,7 +212,7 @@ export function SubmitBrokenSiteReport(report) { * @example * * ```javascript - * window.chrome.webview.postMessage({ + * globalThis.windowsInteropPostMessage({ * Feature: 'PrivacyDashboard', * Name: 'OpenInNewTab', * Data: { url: "https://example.com" } @@ -233,7 +233,7 @@ export function OpenInNewTab(args) { * @example * * ```javascript - * window.chrome.webview.postMessage({ + * globalThis.windowsInteropPostMessage({ * Feature: 'PrivacyDashboard', * Name: 'SetSize', * Data: { height: 445 } @@ -252,7 +252,7 @@ export function SetSize(payload) { * @example * * ```javascript - * window.chrome.webview.postMessage({ + * globalThis.windowsInteropPostMessage({ * Feature: 'PrivacyDashboard', * Name: 'OpenSettings', * Data: { target: 'cpm' } @@ -271,7 +271,7 @@ export function OpenSettings(args) { * @example * * ```javascript - * window.chrome.webview.postMessage({ + * globalThis.windowsInteropPostMessage({ * Feature: 'PrivacyDashboard', * Name: 'SetPermissionCommand', * Data: { permission: 'camera', value: "grant" } @@ -327,7 +327,7 @@ const getBackgroundTabData = () => { const eventShape = z.discriminatedUnion('Name', [windowsIncomingViewModelSchema, windowsIncomingVisibilitySchema]); /** - * Handle all messages sent from Windows via `window.chrome.webview.addEventListener` + * Handle all messages sent from Windows via `globalThis.windowsInteropAddEventListener` * * Currently accepted messages: * - {@link "Generated Schema Definitions".WindowsIncomingViewModel} @@ -357,13 +357,13 @@ export function handleIncomingMessage(message) { } export function setup() { - if (!window.chrome.webview) { - console.error('window.chrome.webview not available'); + if (!globalThis.windowsInteropPostMessage) { + console.error('globalThis.windowsInteropPostMessage'); return; } setupColorScheme(); - assert(typeof window.chrome.webview?.addEventListener === 'function', 'window.chrome.webview.addEventListener is required'); - window.chrome.webview.addEventListener('message', (event) => { + assert(typeof globalThis.windowsInteropAddEventListener === 'function', 'globalThis.windowsInteropAddEventListener required'); + globalThis.windowsInteropAddEventListener('message', (event) => { handleIncomingMessage(event.data); }); setupMutationObserver((height) => {