Skip to content

Commit

Permalink
Update safari extension (raycast#14378)
Browse files Browse the repository at this point in the history
* Update safari extension

- Update safari extension
- Update safari extension
- Initial commit

* Update safari extension

* Update CHANGELOG.md and optimise images

---------

Co-authored-by: raycastbot <bot@raycast.com>
  • Loading branch information
xilopaint and raycastbot authored Sep 11, 2024
1 parent bb7586f commit dc4c457
Show file tree
Hide file tree
Showing 41 changed files with 992 additions and 2,514 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

## [Improve] - 2024-09-11

- Changed the behavior of the `Add to Reading List` command to add the current tab to the Reading List.

## [Improve] - 2024-08-09

- Changed fuzzy search weights
Expand Down
Binary file removed extensions/safari/metadata/history.png
Binary file not shown.
Binary file added extensions/safari/metadata/safari-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added extensions/safari/metadata/safari-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added extensions/safari/metadata/safari-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed extensions/safari/metadata/screenshot-01.png
Binary file not shown.
Binary file removed extensions/safari/metadata/screenshot-02.png
Binary file not shown.
Binary file removed extensions/safari/metadata/tabs.png
Binary file not shown.
2,937 changes: 729 additions & 2,208 deletions extensions/safari/package-lock.json

Large diffs are not rendered by default.

34 changes: 17 additions & 17 deletions extensions/safari/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"thomas",
"HelloImSteven",
"axsuul",
"iwex"
"iwex",
"xilopaint"
],
"license": "MIT",
"commands": [
Expand Down Expand Up @@ -56,8 +57,8 @@
"name": "add-to-reading-list",
"title": "Add to Reading List",
"subtitle": "Safari",
"description": "Add an item to your reading list",
"mode": "view"
"description": "Add the current Safari tab to your Reading List",
"mode": "no-view"
},
{
"name": "search-history",
Expand Down Expand Up @@ -95,29 +96,28 @@
}
],
"dependencies": {
"@raycast/api": "^1.49.3",
"@raycast/utils": "1.5.2",
"@raycast/api": "^1.82.3",
"@raycast/utils": "1.17.0",
"bplist-creator": "^0.1.1",
"fuse.js": "^7.0.0",
"lodash": "^4.17.21",
"osascript-tag": "^0.1.2",
"simple-plist": "^1.4.0"
},
"devDependencies": {
"@types/lodash": "^4.14.191",
"@raycast/eslint-config": "^1.0.11",
"@types/lodash": "^4.17.7",
"@types/node": "~18.11.10",
"@types/react": "^18.0.26",
"@typescript-eslint/eslint-plugin": "^5.45.0",
"@typescript-eslint/parser": "^5.45.0",
"eslint": "^8.29.0",
"eslint-config-prettier": "^8.5.0",
"prettier": "^3.1.1",
"react-devtools": "^5.3.1",
"typescript": "^4.9.3"
"@types/react": "^18.3.5",
"eslint": "^8.57.0",
"prettier": "^3.3.3",
"typescript": "^5.5.4"
},
"scripts": {
"build": "ray build -e dist",
"build": "ray build --skip-types -e dist -o dist",
"dev": "ray develop",
"lint": "ray lint"
"fix-lint": "ray lint --fix",
"lint": "ray lint",
"publish": "npx @raycast/api@latest publish"
}
}
}
25 changes: 25 additions & 0 deletions extensions/safari/src/add-to-reading-list.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { closeMainWindow, showToast, Toast } from "@raycast/api";
import { runAppleScript } from "@raycast/utils";
import { safariAppIdentifier } from "./utils";

export default async function Command() {
try {
await runAppleScript(`
tell application "${safariAppIdentifier}"
set theURL to URL of current tab of window 1
add reading list item theURL
end tell
`);
await closeMainWindow();
await showToast({
style: Toast.Style.Success,
title: "Added to Reading List",
});
} catch (error) {
showToast({
style: Toast.Style.Failure,
title: "Failed to add to Reading List",
message: error instanceof Error ? error.message : undefined,
});
}
}
19 changes: 0 additions & 19 deletions extensions/safari/src/add-to-reading-list.tsx

This file was deleted.

10 changes: 3 additions & 7 deletions extensions/safari/src/cloud-tabs.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import { List } from "@raycast/api";
import _ from "lodash";
import { useState } from "react";
import { List } from "@raycast/api";

import { DeviceListSection, FallbackSearchSection } from "./components";
import { useDevices } from "./hooks";
import { Device, Tab } from "./types";
import { search } from "./utils";
import { url } from "inspector";

const Command = () => {
export default function Command() {
const { devices, permissionView, refreshDevices } = useDevices();
const [searchText, setSearchText] = useState<string>("");

Expand All @@ -32,6 +30,4 @@ const Command = () => {
<FallbackSearchSection searchText={searchText} />
</List>
);
};

export default Command;
}
32 changes: 0 additions & 32 deletions extensions/safari/src/components/AddToReadingListAction.tsx

This file was deleted.

49 changes: 24 additions & 25 deletions extensions/safari/src/components/BookmarkListItem.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { ActionPanel, List, Action, Icon } from "@raycast/api";
import { Action, ActionPanel, List } from "@raycast/api";
import { getFavicon } from "@raycast/utils";

import { GeneralBookmark, ReadingListBookmark } from "../types";
import { formatDate } from "../utils";
import CopyMarkdownLinkAction from "./CopyMarkdownLinkAction";
Expand Down Expand Up @@ -28,26 +27,26 @@ const Actions = (props: { bookmark: ReadingListBookmark | GeneralBookmark }) =>
</ActionPanel>
);

const BookmarkListItem = (props: { bookmark: ReadingListBookmark | GeneralBookmark }) => (
<List.Item
title={props.bookmark.title}
subtitle={props.bookmark.domain}
icon={getFavicon(props.bookmark.url)}
actions={<Actions bookmark={props.bookmark} />}
accessories={
"dateAdded" in props.bookmark
? [
{
text: formatDate(props.bookmark.dateAdded),
},
]
: [
{
tag: props.bookmark.folder,
},
]
}
/>
);

export default BookmarkListItem;
export default function BookmarkListItem(props: { bookmark: ReadingListBookmark | GeneralBookmark }) {
return (
<List.Item
title={props.bookmark.title}
subtitle={props.bookmark.domain}
icon={getFavicon(props.bookmark.url)}
actions={<Actions bookmark={props.bookmark} />}
accessories={
"dateAdded" in props.bookmark
? [
{
text: formatDate(props.bookmark.dateAdded),
},
]
: [
{
tag: props.bookmark.folder,
},
]
}
/>
);
}
20 changes: 10 additions & 10 deletions extensions/safari/src/components/BookmarkListSection.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { List } from "@raycast/api";
import _ from "lodash";
import BookmarkListItem from "./BookmarkListItem";
import { GeneralBookmark } from "../types";
import { plural } from "../utils";
import BookmarkListItem from "./BookmarkListItem";

const BookmarkListSection = (props: { title: string; filteredBookmarks: GeneralBookmark[] }) => (
<List.Section title={_.startCase(props.title)} subtitle={plural(props.filteredBookmarks.length, "bookmark")}>
{props.filteredBookmarks.map((bookmark) => (
<BookmarkListItem key={bookmark.uuid} bookmark={bookmark} />
))}
</List.Section>
);

export default BookmarkListSection;
export default function BookmarkListSection(props: { title: string; filteredBookmarks: GeneralBookmark[] }) {
return (
<List.Section title={_.startCase(props.title)} subtitle={plural(props.filteredBookmarks.length, "bookmark")}>
{props.filteredBookmarks.map((bookmark) => (
<BookmarkListItem key={bookmark.uuid} bookmark={bookmark} />
))}
</List.Section>
);
}
6 changes: 2 additions & 4 deletions extensions/safari/src/components/BookmarksDropdown.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { List } from "@raycast/api";

const BookmarksDropdown = (props: { folderNames: string[]; onSelection: (newValue: string) => void }) => {
export default function BookmarksDropdown(props: { folderNames: string[]; onSelection: (newValue: string) => void }) {
return (
<List.Dropdown
tooltip="Select Bookmarks Folder"
Expand All @@ -17,6 +17,4 @@ const BookmarksDropdown = (props: { folderNames: string[]; onSelection: (newValu
</List.Dropdown.Section>
</List.Dropdown>
);
};

export default BookmarksDropdown;
}
32 changes: 18 additions & 14 deletions extensions/safari/src/components/CloseLocalTabAction.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
import { Icon, Action } from "@raycast/api";

import { Action, Icon } from "@raycast/api";
import { runAppleScript } from "@raycast/utils";
import { LocalTab, Tab } from "../types";
import { executeJxa, safariAppIdentifier } from "../utils";
import { safariAppIdentifier } from "../utils";

async function closeLocalTab(tab: LocalTab) {
const script = `
tell application "${safariAppIdentifier}"
set windowID to ${tab.window_id}
set tabID to ${tab.index}
tell window id windowID
close tab tabID
end tell
end tell
`;

const closeLocalTab = async (tab: LocalTab) =>
executeJxa(`
const safari = Application("${safariAppIdentifier}");
const window = safari.windows.byId(${tab.window_id});
const tab = window.tabs[${tab.index - 1}];
tab.close();
`);
await runAppleScript(script);
}

const CloseLocalTabAction = (props: { tab: Tab; refresh: () => void }) => {
export default function CloseLocalTabAction(props: { tab: Tab; refresh: () => void }) {
return props.tab.is_local ? (
<Action
title="Close Tab"
Expand All @@ -23,6 +29,4 @@ const CloseLocalTabAction = (props: { tab: Tab; refresh: () => void }) => {
}}
/>
) : null;
};

export default CloseLocalTabAction;
}
18 changes: 9 additions & 9 deletions extensions/safari/src/components/CopyMarkdownLinkAction.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Action } from "@raycast/api";

const CopyMarkdownLinkAction = (props: { title?: string; url: string }) => (
<Action.CopyToClipboard
title="Copy Markdown"
content={`[${props.title ?? "Untitled"}](${props.url})`}
shortcut={{ modifiers: ["cmd", "ctrl"], key: "." }}
/>
);

export default CopyMarkdownLinkAction;
export default function CopyMarkdownLinkAction(props: { title?: string; url: string }) {
return (
<Action.CopyToClipboard
title="Copy Markdown"
content={`[${props.title ?? "Untitled"}](${props.url})`}
shortcut={{ modifiers: ["cmd", "ctrl"], key: "." }}
/>
);
}
6 changes: 2 additions & 4 deletions extensions/safari/src/components/CopyTitleAction.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { Action } from "@raycast/api";

const CopyTitleAction = (props: { title?: string }) => {
export default function CopyTitleAction(props: { title?: string }) {
return props.title ? (
<Action.CopyToClipboard
title="Copy Title"
content={props.title}
shortcut={{ modifiers: ["cmd", "shift"], key: "." }}
/>
) : null;
};

export default CopyTitleAction;
}
8 changes: 3 additions & 5 deletions extensions/safari/src/components/CopyUrlAction.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { Action } from "@raycast/api";

const CopyUrlAction = (props: { url: string }) => (
<Action.CopyToClipboard title="Copy URL" content={props.url} shortcut={{ modifiers: ["cmd"], key: "." }} />
);

export default CopyUrlAction;
export default function CopyUrlAction(props: { url: string }) {
return <Action.CopyToClipboard title="Copy URL" content={props.url} shortcut={{ modifiers: ["cmd"], key: "." }} />;
}
15 changes: 7 additions & 8 deletions extensions/safari/src/components/DefaultActions.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { ActionPanel } from "@raycast/api";

import SearchInBrowserAction from "./SearchInBrowserAction";

const DefaultActions = (props: { searchText: string }) => (
<ActionPanel>
<SearchInBrowserAction searchText={props.searchText} />
</ActionPanel>
);

export default DefaultActions;
export default function DefaultActions(props: { searchText: string }) {
return (
<ActionPanel>
<SearchInBrowserAction searchText={props.searchText} />
</ActionPanel>
);
}
Loading

0 comments on commit dc4c457

Please sign in to comment.