Skip to content

Commit

Permalink
Update safari extension (raycast#11879)
Browse files Browse the repository at this point in the history
Co-authored-by: Per Nielsen Tikær <per@raycast.com>
  • Loading branch information
2 people authored and JoltCode committed Apr 23, 2024
1 parent 352ff92 commit 35e8d2d
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 18 deletions.
4 changes: 4 additions & 0 deletions extensions/safari/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
18 changes: 15 additions & 3 deletions extensions/safari/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,28 @@
"author": "loris",
"contributors": [
"thomas",
"HelloImSteven"
"HelloImSteven",
"axsuul"
],
"license": "MIT",
"commands": [
{
"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",
Expand Down
36 changes: 21 additions & 15 deletions extensions/safari/src/hooks/useDevices.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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;

0 comments on commit 35e8d2d

Please sign in to comment.