Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update safari extension #11879

Merged
merged 9 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;