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 Anybox extension #11880

Merged
merged 4 commits into from
Apr 22, 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/anybox/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Anybox Changelog

## [New Feature] - 2024-04-19

- Add options to show folders and tags next to URL in Search Links command.

## [Bug Fixes] - 2023-12-01

- Fix some issues reported by Raycast.
Expand Down
179 changes: 83 additions & 96 deletions extensions/anybox/package-lock.json

Large diffs are not rendered by default.

38 changes: 27 additions & 11 deletions extensions/anybox/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,33 @@
"type": "checkbox",
"required": false,
"default": true,
"label": "Show Tags in Search Results",
"label": "Search Tags",
"description": "Search tags and limit search scope to one specific tag."
},
{
"name": "searchFolders",
"type": "checkbox",
"required": false,
"default": false,
"label": "Show Folders in Search Results",
"label": "Search Folders",
"description": "Search folders and limit search scope to one specific folder."
},
{
"name": "showTags",
"type": "checkbox",
"required": false,
"default": true,
"label": "Show Tags",
"description": "Show tags next to URL."
},
{
"name": "showFolders",
"type": "checkbox",
"required": false,
"default": true,
"label": "Show Folders",
"description": "Show folder next to URL."
},
{
"name": "asIcons",
"type": "checkbox",
Expand Down Expand Up @@ -80,14 +96,14 @@
},
{
"name": "saveCurrentTabWithTags",
"title": "Save Current Tab With Tags",
"title": "Save Current Tab with Tags",
"subtitle": "Anybox",
"description": "Save URL of current tab to Anybox with optional tags.",
"mode": "view"
},
{
"name": "saveCurrentTabWithFolder",
"title": "Save Current Tab With Folder",
"title": "Save Current Tab with Folder",
"subtitle": "Anybox",
"description": "Save URL of current tab to Anybox with optional folder.",
"mode": "view"
Expand All @@ -101,14 +117,14 @@
},
{
"name": "pasteWithTags",
"title": "Save Clipboard With Tags",
"title": "Save Clipboard with Tags",
"subtitle": "Anybox",
"description": "Save clipboard to Anybox with optional tags.",
"mode": "view"
},
{
"name": "pasteWithFolder",
"title": "Save Clipboard With Folder",
"title": "Save Clipboard with Folder",
"subtitle": "Anybox",
"description": "Save clipboard to Anybox with optional Folder.",
"mode": "view"
Expand Down Expand Up @@ -174,17 +190,17 @@
}
],
"dependencies": {
"@raycast/api": "^1.62.2",
"@raycast/api": "^1.71.4",
"dayjs": "^1.11.10",
"node-fetch": "^3.3.2"
},
"devDependencies": {
"@raycast/eslint-config": "^1.0.8",
"@types/node": "18.18.4",
"@types/react": "18.2.27",
"eslint": "^8.54.0",
"prettier": "^3.1.0",
"typescript": "^5.3.2"
"@types/react": "18.2.79",
"eslint": "^8.57.0",
"prettier": "^3.2.5",
"typescript": "^5.4.5"
},
"scripts": {
"build": "ray build -e dist",
Expand Down
3 changes: 1 addition & 2 deletions extensions/anybox/src/components/FolderItem.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { ActionPanel, Action, List, Grid, Icon, getPreferenceValues } from "@raycast/api";
import { FolderProp } from "../utilities/fetch";
import { Preferences } from "../utilities/searchRequest";
import SearchFolder from "../searchFolder";

interface Props {
Expand All @@ -9,7 +8,7 @@ interface Props {

export default function FolderItem(props: Props) {
const folder = props.item;
const preferences: Preferences = getPreferenceValues();
const preferences = getPreferenceValues<Preferences.Search>();
if (preferences.asIcons) {
return (
<Grid.Item
Expand Down
33 changes: 29 additions & 4 deletions extensions/anybox/src/components/LinkItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ import dayjs from "dayjs";
import calendar from "dayjs/plugin/calendar";
import "dayjs/locale/en";
import { Link } from "../utilities/searchRequest";
import { Preferences } from "../utilities/searchRequest";

const preferences: Preferences = getPreferenceValues();
const preferences = getPreferenceValues<Preferences.Search>();

dayjs.locale("en");
dayjs.extend(calendar);
Expand All @@ -39,7 +38,7 @@ function relativeDate(dateString: string): string {
sameDay: "[Today at] HH:mm",
lastDay: "[Yesterday at] HH:mm",
lastWeek: "[Last] dddd",
sameElse: "MMM D, YYYY",
sameElse: "D MMM YYYY",
});
return result;
}
Expand Down Expand Up @@ -241,7 +240,33 @@ export default function LinkItem(props: Props) {
);
} else {
const accessories: List.Item.Accessory[] = [];
accessories.push({ text: isSearchEngine ? "" : relativeDate(item.dateLastOpened) });
if (item.folder && preferences.showFolders) {
accessories.push({
tag: {
value: item.folder.originalName,
color: item.folder.color,
},
});
}
if (preferences.showTags) {
for (const tag of item.tags) {
accessories.push({
tag: {
value: tag.originalName,
color: tag.color,
},
});
}
}
if (!isSearchEngine) {
let dateText = "";
if (preferences.showFolders || preferences.showTags) {
accessories.push({ date: new Date(item.dateLastOpened) });
} else {
dateText = relativeDate(item.dateLastOpened);
accessories.push({ text: dateText });
}
}
return (
<List.Item
title={item.title}
Expand Down
3 changes: 1 addition & 2 deletions extensions/anybox/src/components/TagItem.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { ActionPanel, Action, List, Grid, Icon, getPreferenceValues } from "@raycast/api";
import { TagProp } from "../utilities/fetch";
import { Preferences } from "../utilities/searchRequest";
import SearchTag from "../searchTag";

interface Props {
Expand All @@ -9,7 +8,7 @@ interface Props {

export default function TagItem(props: Props) {
const tag = props.item;
const preferences: Preferences = getPreferenceValues();
const preferences = getPreferenceValues<Preferences.Search>();
if (preferences.asIcons) {
return (
<Grid.Item
Expand Down
6 changes: 1 addition & 5 deletions extensions/anybox/src/saveNote.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,14 @@ interface FolderProp {
name: string;
}

interface Preferences {
autoFill: boolean;
}

interface SaveNoteResponse {
code: number;
message: string;
url: string;
}

function NoteForm() {
const preferences = getPreferenceValues<Preferences>();
const preferences = getPreferenceValues<Preferences.SaveNote>();
const [note, setNote] = useState<string>();
const [comment, setComment] = useState<string>();
const [tags, setTags] = useState<TagProp[]>([]);
Expand Down
6 changes: 3 additions & 3 deletions extensions/anybox/src/search.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { List, Grid, getPreferenceValues } from "@raycast/api";
import { useState, useEffect } from "react";
import searchRequest, { SearchQuery, Link, Preferences } from "./utilities/searchRequest";
import searchRequest, { SearchQuery, Link } from "./utilities/searchRequest";
import LinkItem from "./components/LinkItem";
import TagItem from "./components/TagItem";
import { TagProp, fetchTags as fetchTags, fetchSearchEngines, FolderProp, fetchFolders } from "./utilities/fetch";
Expand Down Expand Up @@ -52,7 +52,7 @@ export default function SearchResult() {
isSearchEngines: false,
});
const [searchText, setSearchText] = useState("");
const preferences: Preferences = getPreferenceValues();
const preferences = getPreferenceValues<Preferences.Search>();

useEffect(() => {
const searchLinks = async () => {
Expand Down Expand Up @@ -166,7 +166,7 @@ export default function SearchResult() {
return (
<Grid
isLoading={state.isLoading}
enableFiltering={false}
filtering={false}
throttle={true}
onSearchTextChange={setSearchText}
navigationTitle={navigationTitle}
Expand Down
3 changes: 1 addition & 2 deletions extensions/anybox/src/searchFolder.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { List, Grid, getPreferenceValues } from "@raycast/api";
import { useState, useEffect } from "react";
import searchRequest, { SearchQuery, Link } from "./utilities/searchRequest";
import { Preferences } from "./utilities/searchRequest";
import LinkItem from "./components/LinkItem";
import { FolderProp, fetchSearchEngines } from "./utilities/fetch";

Expand All @@ -23,7 +22,7 @@ export default function SearchFolder(props: Props) {
});
const folder = props.folder;
const [searchText, setSearchText] = useState("");
const preferences: Preferences = getPreferenceValues();
const preferences = getPreferenceValues<Preferences.Search>();

useEffect(() => {
const searchLinks = async () => {
Expand Down
3 changes: 1 addition & 2 deletions extensions/anybox/src/searchTag.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { List, Grid, getPreferenceValues } from "@raycast/api";
import { useState, useEffect } from "react";
import searchRequest, { SearchQuery, Link } from "./utilities/searchRequest";
import { Preferences } from "./utilities/searchRequest";
import LinkItem from "./components/LinkItem";
import { TagProp, fetchSearchEngines } from "./utilities/fetch";

Expand All @@ -23,7 +22,7 @@ export default function SearchTag(props: Props) {
});
const tag = props.tag;
const [searchText, setSearchText] = useState("");
const preferences: Preferences = getPreferenceValues();
const preferences = getPreferenceValues<Preferences.Search>();

useEffect(() => {
const searchLinks = async () => {
Expand Down
8 changes: 1 addition & 7 deletions extensions/anybox/src/utilities/fetch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,7 @@ export function handleError(error: FetchError) {
primaryAction: {
title: "Open Anybox",
onAction: async (toast) => {
const installedApplications = await getApplications();
const app = installedApplications.filter((application) => application.bundleId == "ltd.anybox.Anybox-setapp");
if (app.length > 0) {
open("open", "ltd.anybox.Anybox-setapp");
} else {
open("open", "cc.anybox.Anybox");
}
open("anybox://show");
toast.hide();
},
},
Expand Down
10 changes: 1 addition & 9 deletions extensions/anybox/src/utilities/searchRequest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,8 @@ export interface Link {
hasLinkImage: boolean;
}

export interface Preferences {
api_key: string;
searchTags: boolean;
searchFolders: boolean;
asIcons: boolean;
preferLinkIcons: boolean;
}

export default async function searchRequest(query: SearchQuery): Promise<[Link]> {
const preferences: Preferences = getPreferenceValues();
const preferences = getPreferenceValues<Preferences.Search>();
// @ts-expect-error: Don’t know how to satify URLSearchParams’s type.
const searchParams = new URLSearchParams(query);
return fetch("http://127.0.0.1:6391/search?" + searchParams, {
Expand Down
2 changes: 1 addition & 1 deletion extensions/anybox/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"display": "Node 16",
"include": ["src/**/*"],
"include": ["src/**/*", "raycast-env.d.ts"],
"compilerOptions": {
"lib": ["es2021"],
"module": "commonjs",
Expand Down