From 9006edb233b01216fafaad9b5b86c7e2e2bd5bc4 Mon Sep 17 00:00:00 2001 From: James Hu Date: Mon, 22 Apr 2024 21:43:10 -0700 Subject: [PATCH] Update safari extension (#11879) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Per Nielsen Tikær --- extensions/safari/CHANGELOG.md | 4 +++ extensions/safari/package.json | 18 ++++++++++-- extensions/safari/src/hooks/useDevices.ts | 36 +++++++++++++---------- 3 files changed, 40 insertions(+), 18 deletions(-) diff --git a/extensions/safari/CHANGELOG.md b/extensions/safari/CHANGELOG.md index 99027cc1401..01ea8b93abc 100644 --- a/extensions/safari/CHANGELOG.md +++ b/extensions/safari/CHANGELOG.md @@ -1,5 +1,9 @@ # Safari Changelog +## [Update] - 2024-04-18 + +- Adds a preference to skip browsing iCloud tabs + ## [Fix] - 2023-12-20 - Fix the title of ReadingListNonSync may possibly be null diff --git a/extensions/safari/package.json b/extensions/safari/package.json index 1ffaa800554..2a444011c3f 100644 --- a/extensions/safari/package.json +++ b/extensions/safari/package.json @@ -11,7 +11,8 @@ "author": "loris", "contributors": [ "thomas", - "HelloImSteven" + "HelloImSteven", + "axsuul" ], "license": "MIT", "commands": [ @@ -19,8 +20,19 @@ "name": "cloud-tabs", "title": "Search Tabs", "subtitle": "Safari", - "description": "Browse your open tabs (Local and iCloud)", - "mode": "view" + "description": "Browse your open tabs", + "mode": "view", + "preferences": [ + { + "name": "areRemoteTabsUsed", + "type": "checkbox", + "required": false, + "title": "Devices", + "description": "Include iCloud tabs across all your devices", + "default": true, + "label": "iCloud" + } + ] }, { "name": "reading-list", diff --git a/extensions/safari/src/hooks/useDevices.ts b/extensions/safari/src/hooks/useDevices.ts index f2961c6130b..a84c4379088 100644 --- a/extensions/safari/src/hooks/useDevices.ts +++ b/extensions/safari/src/hooks/useDevices.ts @@ -1,4 +1,5 @@ import _ from "lodash"; +import { getPreferenceValues } from "@raycast/api"; import { useCachedPromise, useExec, useSQL } from "@raycast/utils"; import { homedir } from "os"; import { resolve } from "path"; @@ -49,31 +50,36 @@ const useDeviceName = () => const useLocalTabs = () => useCachedPromise(fetchLocalTabs, [], { keepPreviousData: true }); const useDevices = () => { + const preferences = getPreferenceValues(); const { data: deviceName } = useDeviceName(); - const remoteTabs = useRemoteTabs(); const localTabs = useLocalTabs(); - const localDevice = { uuid: "local", name: `${deviceName} ★`, tabs: localTabs.data, }; + const devices = [localDevice]; + let permissionView; - const removeDevices = _.chain(remoteTabs.data) - .groupBy("device_uuid") - .transform((devices: Device[], tabs: RemoteTab[], device_uuid: string) => { - devices.push({ - uuid: device_uuid, - name: tabs[0].device_name, - tabs, - }); - }, []) - .reject(["name", deviceName]) - .value(); + if (preferences.areRemoteTabsUsed) { + const remoteTabs = useRemoteTabs(); + const remoteDevices = _.chain(remoteTabs.data) + .groupBy("device_uuid") + .transform((devices: Device[], tabs: RemoteTab[], device_uuid: string) => { + devices.push({ + uuid: device_uuid, + name: tabs[0].device_name, + tabs, + }); + }, []) + .reject(["name", deviceName]) + .value(); - const devices = [localDevice, ...removeDevices]; + devices.push(...remoteDevices); + permissionView = remoteTabs.permissionView; + } - return { devices, permissionView: remoteTabs.permissionView, refreshDevices: localTabs.revalidate }; + return { devices, permissionView, refreshDevices: localTabs.revalidate }; }; export default useDevices;