From c62adc30cb9978434079b342a88e94ed42484e70 Mon Sep 17 00:00:00 2001 From: Oliver Schwendener Date: Tue, 10 Dec 2024 05:58:31 +0100 Subject: [PATCH 1/3] 9.12.0 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 36d7bd176..bbb9c6dad 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "ueli", - "version": "9.11.1", + "version": "9.12.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "ueli", - "version": "9.11.1", + "version": "9.12.0", "hasInstallScript": true, "license": "MIT", "dependencies": { diff --git a/package.json b/package.json index 9a0819d7f..3984f3cb2 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "ueli", "description": "Cross-Platform Keystroke Launcher", - "version": "9.11.1", + "version": "9.12.0", "license": "MIT", "author": { "email": "oliver.schwendener@proton.me", From 4a717c67f0eec65e11b5310e666d9f3bca080791 Mon Sep 17 00:00:00 2001 From: Oliver Schwendener Date: Tue, 10 Dec 2024 13:54:37 +0100 Subject: [PATCH 2/3] refactor: remove `useContextBridge` hook (#1292) --- src/renderer/Core/App.tsx | 23 ++++------- src/renderer/Core/Components/BasicSearch.tsx | 10 ++--- src/renderer/Core/Hooks/index.ts | 1 - src/renderer/Core/Hooks/useContextBridge.ts | 3 -- .../Hooks/useExcludedSearchResultItems.ts | 14 +++---- src/renderer/Core/Hooks/useExtensionProps.ts | 4 +- .../Core/Hooks/useExtensionSetting.ts | 9 ++--- src/renderer/Core/Hooks/useFavorites.ts | 11 ++---- .../Core/Hooks/useSearchResultItems.ts | 11 ++---- src/renderer/Core/Hooks/useSetting.ts | 7 +--- src/renderer/Core/I18n/useI18n.ts | 7 ++-- .../Core/Search/ActionsMenu/ActionsMenu.tsx | 11 +++--- .../Core/Search/ConfirmationDialog.tsx | 5 +-- src/renderer/Core/Search/Search.tsx | 38 +++++++++---------- src/renderer/Core/Search/SearchBar.tsx | 5 +-- .../Core/Search/SearchHistoryController.ts | 7 ++-- .../Core/Search/SearchViewController.ts | 8 ++-- src/renderer/Core/Settings/Navigation.tsx | 4 +- src/renderer/Core/Settings/Pages/About.tsx | 5 +-- .../Settings/Pages/Appearance/Appearance.tsx | 13 +++---- .../Core/Settings/Pages/Debug/Logs.tsx | 10 ++--- .../Settings/Pages/Debug/ResetSettings.tsx | 4 +- .../Core/Settings/Pages/Extensions.tsx | 13 +++---- .../Core/Settings/Pages/Favorites.tsx | 7 ++-- .../Core/Settings/Pages/General/Autostart.tsx | 6 +-- .../Settings/Pages/General/DockSettings.tsx | 5 +-- .../Core/Settings/Pages/General/HotKey.tsx | 6 +-- .../Pages/SearchEngine/ExcludedItems.tsx | 11 +++--- .../Pages/SearchEngine/RescanInterval.tsx | 6 +-- .../Core/Settings/Pages/Window/Window.tsx | 6 +-- .../Pages/Window/WorkspaceVisibility.tsx | 6 +-- src/renderer/Core/Settings/Settings.tsx | 4 +- src/renderer/Core/useAppCssProperties.ts | 17 ++++----- .../ApplicationSearchSettings.tsx | 7 +--- .../ApplicationSearch/Linux/LinuxSettings.tsx | 6 +-- .../ApplicationSearch/MacOs/MacOsSettings.tsx | 6 +-- .../ApplicationSearch/Windows/Folders.tsx | 6 +-- .../Extensions/Base64Conversion/Converter.tsx | 4 +- .../BrowserBookmarksSettings.tsx | 5 +-- .../FileSearch/FileSearchSettings.tsx | 9 ++--- .../SimpleFileSearch/EditFolder.tsx | 11 +++--- .../TerminalLauncherSettings.tsx | 5 +-- .../WebSearch/WebSearchSettings.tsx | 5 +-- .../Extensions/Workflow/NewActionOpenFile.tsx | 4 +- .../Workflow/NewActionOpenTerminal.tsx | 6 +-- 45 files changed, 143 insertions(+), 228 deletions(-) delete mode 100644 src/renderer/Core/Hooks/useContextBridge.ts diff --git a/src/renderer/Core/App.tsx b/src/renderer/Core/App.tsx index d32f2154b..f3f39eff8 100644 --- a/src/renderer/Core/App.tsx +++ b/src/renderer/Core/App.tsx @@ -4,13 +4,7 @@ import type { IpcRendererEvent } from "electron"; import { useEffect, useState } from "react"; import { Route, Routes, useNavigate } from "react-router"; import { Extension } from "./Extension"; -import { - useContextBridge, - useExcludedSearchResultItems, - useFavorites, - useScrollBar, - useSearchResultItems, -} from "./Hooks"; +import { useExcludedSearchResultItems, useFavorites, useScrollBar, useSearchResultItems } from "./Hooks"; import { useI18n } from "./I18n"; import { Search } from "./Search"; import { Settings } from "./Settings"; @@ -19,8 +13,7 @@ import { ThemeContext } from "./ThemeContext"; import { useAppCssProperties } from "./useAppCssProperties"; export const App = () => { - const { contextBridge } = useContextBridge(); - const [theme, setTheme] = useState(getTheme(contextBridge)); + const [theme, setTheme] = useState(getTheme(window.ContextBridge)); const [shouldPreferDarkColors, setShouldPreferDarkColors] = useState( window.matchMedia("(prefers-color-scheme: dark)").matches, ); @@ -31,7 +24,7 @@ export const App = () => { const navigate = useNavigate(); const { appCssProperties } = useAppCssProperties(); - useI18n({ contextBridge }); + useI18n(); useScrollBar({ document, theme }); useEffect(() => { @@ -39,16 +32,16 @@ export const App = () => { navigate({ pathname }); const nativeThemeChangedEventHandler = () => { - setTheme(getTheme(contextBridge)); + setTheme(getTheme(window.ContextBridge)); setShouldPreferDarkColors(window.matchMedia("(prefers-color-scheme: dark)").matches); }; - contextBridge.ipcRenderer.on("navigateTo", navigateToEventHandler); - contextBridge.ipcRenderer.on("nativeThemeChanged", nativeThemeChangedEventHandler); + window.ContextBridge.ipcRenderer.on("navigateTo", navigateToEventHandler); + window.ContextBridge.ipcRenderer.on("nativeThemeChanged", nativeThemeChangedEventHandler); return () => { - contextBridge.ipcRenderer.off("navigateTo", navigateToEventHandler); - contextBridge.ipcRenderer.off("nativeThemeChanged", nativeThemeChangedEventHandler); + window.ContextBridge.ipcRenderer.off("navigateTo", navigateToEventHandler); + window.ContextBridge.ipcRenderer.off("nativeThemeChanged", nativeThemeChangedEventHandler); }; }, []); diff --git a/src/renderer/Core/Components/BasicSearch.tsx b/src/renderer/Core/Components/BasicSearch.tsx index 84c72e051..b1ec3cf33 100644 --- a/src/renderer/Core/Components/BasicSearch.tsx +++ b/src/renderer/Core/Components/BasicSearch.tsx @@ -1,6 +1,5 @@ import { BaseLayout } from "@Core/BaseLayout"; import { Header } from "@Core/Header"; -import { useContextBridge } from "@Core/Hooks"; import { getNextSearchResultItemId } from "@Core/Search/Helpers/getNextSearchResultItemId"; import { getPreviousSearchResultItemId } from "@Core/Search/Helpers/getPreviousSearchResultItemId"; import { SearchResultList } from "@Core/Search/SearchResultList"; @@ -24,7 +23,6 @@ export const BasicSearch = ({ debounceDurationInMs, showGoBackButton, }: BasicSearchProps) => { - const { contextBridge } = useContextBridge(); const navigate = useNavigate(); const [searchTerm, setSearchTerm] = useState(""); const [isLoading, setIsLoading] = useState(false); @@ -64,17 +62,17 @@ export const BasicSearch = ({ const selectedSearchResultItem = getSelectedSearchResultItem(); if (selectedSearchResultItem) { - await contextBridge.invokeAction(selectedSearchResultItem.defaultAction); + await window.ContextBridge.invokeAction(selectedSearchResultItem.defaultAction); } }; const clickHandlers: Record void> = { selectSearchResultItem: (s) => setSelectedItemId(s.id), - invokeSearchResultItem: (s) => contextBridge.invokeAction(s.defaultAction), + invokeSearchResultItem: (s) => window.ContextBridge.invokeAction(s.defaultAction), }; const handleSearchResultItemClickEvent = (searchResultItem: SearchResultItem) => { - const singleClickBehavior = contextBridge.getSettingValue( + const singleClickBehavior = window.ContextBridge.getSettingValue( "keyboardAndMouse.singleClickBehavior", "selectSearchResultItem", ); @@ -83,7 +81,7 @@ export const BasicSearch = ({ }; const handleSearchResultItemDoubleClickEvent = (searchResultItem: SearchResultItem) => { - const doubleClickBehavior = contextBridge.getSettingValue( + const doubleClickBehavior = window.ContextBridge.getSettingValue( "keyboardAndMouse.doubleClickBehavior", "invokeSearchResultItem", ); diff --git a/src/renderer/Core/Hooks/index.ts b/src/renderer/Core/Hooks/index.ts index 750b43180..d84904e99 100644 --- a/src/renderer/Core/Hooks/index.ts +++ b/src/renderer/Core/Hooks/index.ts @@ -1,4 +1,3 @@ -export * from "./useContextBridge"; export * from "./useExcludedSearchResultItems"; export * from "./useExtensionProps"; export * from "./useExtensionSetting"; diff --git a/src/renderer/Core/Hooks/useContextBridge.ts b/src/renderer/Core/Hooks/useContextBridge.ts deleted file mode 100644 index c45de1324..000000000 --- a/src/renderer/Core/Hooks/useContextBridge.ts +++ /dev/null @@ -1,3 +0,0 @@ -import type { ContextBridge } from "@common/Core"; - -export const useContextBridge = (): { contextBridge: ContextBridge } => ({ contextBridge: window.ContextBridge }); diff --git a/src/renderer/Core/Hooks/useExcludedSearchResultItems.ts b/src/renderer/Core/Hooks/useExcludedSearchResultItems.ts index 6ef8a0134..a1d3c8c1e 100644 --- a/src/renderer/Core/Hooks/useExcludedSearchResultItems.ts +++ b/src/renderer/Core/Hooks/useExcludedSearchResultItems.ts @@ -1,21 +1,21 @@ import { useEffect, useState } from "react"; -import { useContextBridge } from "./useContextBridge"; export const useExcludedSearchResultItems = () => { - const { contextBridge } = useContextBridge(); - const [excludedSearchResultItemIds, setExcludedSearchResultItemIds] = useState( - contextBridge.getExcludedSearchResultItemIds(), + window.ContextBridge.getExcludedSearchResultItemIds(), ); useEffect(() => { const excludedSearchResultItemsUpdatedEventHandler = () => - setExcludedSearchResultItemIds(contextBridge.getExcludedSearchResultItemIds()); + setExcludedSearchResultItemIds(window.ContextBridge.getExcludedSearchResultItemIds()); - contextBridge.ipcRenderer.on("excludedSearchResultItemsUpdated", excludedSearchResultItemsUpdatedEventHandler); + window.ContextBridge.ipcRenderer.on( + "excludedSearchResultItemsUpdated", + excludedSearchResultItemsUpdatedEventHandler, + ); return () => { - contextBridge.ipcRenderer.off( + window.ContextBridge.ipcRenderer.off( "excludedSearchResultItemsUpdated", excludedSearchResultItemsUpdatedEventHandler, ); diff --git a/src/renderer/Core/Hooks/useExtensionProps.ts b/src/renderer/Core/Hooks/useExtensionProps.ts index aad2c023d..b487af642 100644 --- a/src/renderer/Core/Hooks/useExtensionProps.ts +++ b/src/renderer/Core/Hooks/useExtensionProps.ts @@ -1,13 +1,11 @@ import type { ExtensionProps } from "@Core/ExtensionProps"; import { useNavigate } from "react-router"; -import { useContextBridge } from "./useContextBridge"; export const useExtensionProps = (): ExtensionProps => { const navigate = useNavigate(); - const { contextBridge } = useContextBridge(); return { - contextBridge, + contextBridge: window.ContextBridge, goBack: () => navigate({ pathname: "/" }), }; }; diff --git a/src/renderer/Core/Hooks/useExtensionSetting.ts b/src/renderer/Core/Hooks/useExtensionSetting.ts index e33d4a407..ad19295cb 100644 --- a/src/renderer/Core/Hooks/useExtensionSetting.ts +++ b/src/renderer/Core/Hooks/useExtensionSetting.ts @@ -1,6 +1,5 @@ import { getExtensionSettingKey } from "@common/Core/Extension"; import { useState } from "react"; -import { useContextBridge } from "./useContextBridge"; export const useExtensionSetting = ({ extensionId, @@ -11,14 +10,12 @@ export const useExtensionSetting = ({ key: string; isSensitive?: boolean; }) => { - const { contextBridge } = useContextBridge(); - const settingKey = getExtensionSettingKey(extensionId, key); const [value, setValue] = useState( - contextBridge.getSettingValue( + window.ContextBridge.getSettingValue( settingKey, - contextBridge.getExtensionSettingDefaultValue(extensionId, key), + window.ContextBridge.getExtensionSettingDefaultValue(extensionId, key), isSensitive, ), ); @@ -26,7 +23,7 @@ export const useExtensionSetting = ({ const updateValue = async (updatedValue: Value) => { setValue(updatedValue); - await contextBridge.updateSettingValue(settingKey, updatedValue, isSensitive); + await window.ContextBridge.updateSettingValue(settingKey, updatedValue, isSensitive); }; return { value, updateValue }; diff --git a/src/renderer/Core/Hooks/useFavorites.ts b/src/renderer/Core/Hooks/useFavorites.ts index 285524e3d..461a045d0 100644 --- a/src/renderer/Core/Hooks/useFavorites.ts +++ b/src/renderer/Core/Hooks/useFavorites.ts @@ -1,18 +1,15 @@ import { useEffect, useState } from "react"; -import { useContextBridge } from "./useContextBridge"; export const useFavorites = () => { - const { contextBridge } = useContextBridge(); - - const [favorites, setFavorites] = useState(contextBridge.getFavorites()); + const [favorites, setFavorites] = useState(window.ContextBridge.getFavorites()); useEffect(() => { - const favoritesUpdatedEventHandler = () => setFavorites(contextBridge.getFavorites()); + const favoritesUpdatedEventHandler = () => setFavorites(window.ContextBridge.getFavorites()); - contextBridge.ipcRenderer.on("favoritesUpdated", favoritesUpdatedEventHandler); + window.ContextBridge.ipcRenderer.on("favoritesUpdated", favoritesUpdatedEventHandler); return () => { - contextBridge.ipcRenderer.off("favoritesUpdated", favoritesUpdatedEventHandler); + window.ContextBridge.ipcRenderer.off("favoritesUpdated", favoritesUpdatedEventHandler); }; }, []); diff --git a/src/renderer/Core/Hooks/useSearchResultItems.ts b/src/renderer/Core/Hooks/useSearchResultItems.ts index bb4db3637..609ce862f 100644 --- a/src/renderer/Core/Hooks/useSearchResultItems.ts +++ b/src/renderer/Core/Hooks/useSearchResultItems.ts @@ -1,21 +1,18 @@ import type { SearchResultItem } from "@common/Core"; import { useEffect, useState } from "react"; -import { useContextBridge } from "./useContextBridge"; export const useSearchResultItems = () => { - const { contextBridge } = useContextBridge(); - const [searchResultItems, setSearchResultItems] = useState( - contextBridge.getSearchResultItems(), + window.ContextBridge.getSearchResultItems(), ); useEffect(() => { - const searchIndexUpdatedEventHandler = () => setSearchResultItems(contextBridge.getSearchResultItems()); + const searchIndexUpdatedEventHandler = () => setSearchResultItems(window.ContextBridge.getSearchResultItems()); - contextBridge.ipcRenderer.on("searchIndexUpdated", searchIndexUpdatedEventHandler); + window.ContextBridge.ipcRenderer.on("searchIndexUpdated", searchIndexUpdatedEventHandler); return () => { - contextBridge.ipcRenderer.off("searchIndexUpdated", searchIndexUpdatedEventHandler); + window.ContextBridge.ipcRenderer.off("searchIndexUpdated", searchIndexUpdatedEventHandler); }; }, []); diff --git a/src/renderer/Core/Hooks/useSetting.ts b/src/renderer/Core/Hooks/useSetting.ts index 6bfc2d4ef..04dfd0cac 100644 --- a/src/renderer/Core/Hooks/useSetting.ts +++ b/src/renderer/Core/Hooks/useSetting.ts @@ -1,5 +1,4 @@ import { useState } from "react"; -import { useContextBridge } from "./useContextBridge"; export const useSetting = ({ key, @@ -10,13 +9,11 @@ export const useSetting = ({ defaultValue: Value; isSensitive?: boolean; }) => { - const { contextBridge } = useContextBridge(); - - const [value, setValue] = useState(contextBridge.getSettingValue(key, defaultValue, isSensitive)); + const [value, setValue] = useState(window.ContextBridge.getSettingValue(key, defaultValue, isSensitive)); const updateValue = async (updatedValue: Value) => { setValue(updatedValue); - await contextBridge.updateSettingValue(key, updatedValue, isSensitive); + await window.ContextBridge.updateSettingValue(key, updatedValue, isSensitive); }; return { value, updateValue }; diff --git a/src/renderer/Core/I18n/useI18n.ts b/src/renderer/Core/I18n/useI18n.ts index 0ca060e69..d9f4e8e00 100644 --- a/src/renderer/Core/I18n/useI18n.ts +++ b/src/renderer/Core/I18n/useI18n.ts @@ -1,17 +1,16 @@ -import type { ContextBridge } from "@common/Core"; import { use } from "i18next"; import { initReactI18next } from "react-i18next"; import { createResources } from "./createResources"; import { getCoreResources } from "./getCoreResources"; import { getExtensionResources } from "./getExtensionResources"; -export const useI18n = ({ contextBridge }: { contextBridge: ContextBridge }) => { +export const useI18n = () => { return use(initReactI18next).init({ resources: createResources([ ...getCoreResources(), - ...getExtensionResources(contextBridge.getExtensionResources()), + ...getExtensionResources(window.ContextBridge.getExtensionResources()), ]), - lng: contextBridge.getSettingValue("general.language", "en-US"), + lng: window.ContextBridge.getSettingValue("general.language", "en-US"), fallbackLng: "en-US", }); }; diff --git a/src/renderer/Core/Search/ActionsMenu/ActionsMenu.tsx b/src/renderer/Core/Search/ActionsMenu/ActionsMenu.tsx index 473d17b80..db84f1bb7 100644 --- a/src/renderer/Core/Search/ActionsMenu/ActionsMenu.tsx +++ b/src/renderer/Core/Search/ActionsMenu/ActionsMenu.tsx @@ -1,5 +1,4 @@ import { KeyboardShortcut } from "@Core/Components"; -import { useContextBridge } from "@Core/Hooks"; import { type SearchResultItem, type SearchResultItemAction } from "@common/Core"; import { Button, @@ -38,7 +37,6 @@ export const ActionsMenu = ({ onOpenChange, keyboardShortcut, }: AdditionalActionsProps) => { - const { contextBridge } = useContextBridge(); const { t } = useTranslation(); const toasterId = useId("copiedToClipboardToasterId"); @@ -46,7 +44,10 @@ export const ActionsMenu = ({ const actions = searchResultItem ? getActions(searchResultItem, favorites) : []; - const showKeyboardShortcuts = contextBridge.getSettingValue("appearance.showKeyboardShortcuts", true); + const showKeyboardShortcuts = window.ContextBridge.getSettingValue( + "appearance.showKeyboardShortcuts", + true, + ); useEffect(() => { const copiedToClipboardHandler = () => @@ -57,10 +58,10 @@ export const ActionsMenu = ({ { intent: "success", position: "bottom" }, ); - contextBridge.ipcRenderer.on("copiedToClipboard", copiedToClipboardHandler); + window.ContextBridge.ipcRenderer.on("copiedToClipboard", copiedToClipboardHandler); return () => { - contextBridge.ipcRenderer.off("copiedToClipboard", copiedToClipboardHandler); + window.ContextBridge.ipcRenderer.off("copiedToClipboard", copiedToClipboardHandler); }; }, []); diff --git a/src/renderer/Core/Search/ConfirmationDialog.tsx b/src/renderer/Core/Search/ConfirmationDialog.tsx index ba635ffc4..5966103b4 100644 --- a/src/renderer/Core/Search/ConfirmationDialog.tsx +++ b/src/renderer/Core/Search/ConfirmationDialog.tsx @@ -9,7 +9,6 @@ import { DialogTitle, } from "@fluentui/react-components"; import { t } from "i18next"; -import { useContextBridge } from "../Hooks"; type ConfirmationDialogProps = { action?: SearchResultItemAction; @@ -17,12 +16,10 @@ type ConfirmationDialogProps = { }; export const ConfirmationDialog = ({ action, closeDialog }: ConfirmationDialogProps) => { - const { contextBridge } = useContextBridge(); - const invokeAction = async () => { if (action) { closeDialog(); - await contextBridge.invokeAction(action); + await window.ContextBridge.invokeAction(action); } }; diff --git a/src/renderer/Core/Search/Search.tsx b/src/renderer/Core/Search/Search.tsx index b49653e86..5af203e50 100644 --- a/src/renderer/Core/Search/Search.tsx +++ b/src/renderer/Core/Search/Search.tsx @@ -8,7 +8,6 @@ import { useTranslation } from "react-i18next"; import { useNavigate } from "react-router"; import { BaseLayout } from "../BaseLayout"; import { Footer } from "../Footer"; -import { useContextBridge } from "../Hooks"; import { ActionsMenu } from "./ActionsMenu"; import { ConfirmationDialog } from "./ConfirmationDialog"; import type { KeyboardEventHandler } from "./KeyboardEventHandler"; @@ -33,7 +32,6 @@ export const Search = ({ favoriteSearchResultItemIds, }: SearchProps) => { const { t } = useTranslation("search"); - const { contextBridge } = useContextBridge(); const { theme } = useContext(ThemeContext); const [additionalActionsMenuIsOpen, setAdditionalActionsMenuIsOpen] = useState(false); @@ -48,25 +46,24 @@ export const Search = ({ invokeAction, invokeSelectedSearchResultItem, } = useSearchViewController({ - contextBridge, searchResultItems, excludedSearchResultItemIds, favoriteSearchResultItemIds, }); - const searchHistory = useSearchHistoryController({ contextBridge }); + const searchHistory = useSearchHistoryController(); const containerRef = useRef(null); const additionalActionsButtonRef = useRef(null); const navigate = useNavigate(); const openSettings = () => navigate({ pathname: "/settings/general" }); - const singleClickBehavior = contextBridge.getSettingValue( + const singleClickBehavior = window.ContextBridge.getSettingValue( "keyboardAndMouse.singleClickBehavior", "selectSearchResultItem", ); - const doubleClickBehavior = contextBridge.getSettingValue( + const doubleClickBehavior = window.ContextBridge.getSettingValue( "keyboardAndMouse.doubleClickBehavior", "invokeSearchResultItem", ); @@ -74,7 +71,7 @@ export const Search = ({ const handleUserInputKeyDownEvent = (keyboardEvent: ReactKeyboardEvent) => { const eventHandlers: KeyboardEventHandler[] = [ { - listener: () => contextBridge.ipcRenderer.send("escapePressed"), + listener: () => window.ContextBridge.ipcRenderer.send("escapePressed"), needsToInvokeListener: (keyboardEvent) => keyboardEvent.key === "Escape", }, { @@ -131,7 +128,10 @@ export const Search = ({ userInput.focus(); }; - const showKeyboardShortcuts = contextBridge.getSettingValue("appearance.showKeyboardShortcuts", true); + const showKeyboardShortcuts = window.ContextBridge.getSettingValue( + "appearance.showKeyboardShortcuts", + true, + ); const toggleAdditionalActionsMenu = (open: boolean) => { setAdditionalActionsMenuIsOpen(open); @@ -148,7 +148,7 @@ export const Search = ({ }[] = [ { validate: (event) => - contextBridge.getOperatingSystem() === "macOS" + window.ContextBridge.getOperatingSystem() === "macOS" ? event.key === "," && event.metaKey : event.key === "," && event.ctrlKey, action: (event) => { @@ -158,7 +158,7 @@ export const Search = ({ }, { validate: (event) => - contextBridge.getOperatingSystem() === "macOS" + window.ContextBridge.getOperatingSystem() === "macOS" ? event.key === "k" && event.metaKey : event.key === "k" && event.ctrlKey, action: (event) => { @@ -192,11 +192,11 @@ export const Search = ({ } }; - contextBridge.ipcRenderer.on("windowFocused", windowFocusedEventHandler); + window.ContextBridge.ipcRenderer.on("windowFocused", windowFocusedEventHandler); window.addEventListener("keydown", keyDownEventHandler); return () => { - contextBridge.ipcRenderer.off("windowFocused", windowFocusedEventHandler); + window.ContextBridge.ipcRenderer.off("windowFocused", windowFocusedEventHandler); window.removeEventListener("keydown", keyDownEventHandler); }; }, []); @@ -229,19 +229,19 @@ export const Search = ({ onKeyDown={handleUserInputKeyDownEvent} onSearchTermUpdated={search} searchTerm={searchTerm.value} - searchBarSize={contextBridge.getSettingValue( + searchBarSize={window.ContextBridge.getSettingValue( "appearance.searchBarSize", "large", )} - searchBarAppearance={contextBridge.getSettingValue( + searchBarAppearance={window.ContextBridge.getSettingValue( "appearance.searchBarAppearance", "auto", )} - searchBarPlaceholderText={contextBridge.getSettingValue( + searchBarPlaceholderText={window.ContextBridge.getSettingValue( "appearance.searchBarPlaceholderText", t("searchBarPlaceholderText"), )} - showIcon={contextBridge.getSettingValue("appearance.showSearchIcon", true)} + showIcon={window.ContextBridge.getSettingValue("appearance.showSearchIcon", true)} contentAfter={ searchHistory.isEnabled() ? ( ) : ( <> @@ -316,7 +316,7 @@ export const Search = ({ {showKeyboardShortcuts && (
)} @@ -344,7 +344,7 @@ export const Search = ({ additionalActionsButtonRef={additionalActionsButtonRef} open={additionalActionsMenuIsOpen} onOpenChange={toggleAdditionalActionsMenu} - keyboardShortcut={contextBridge.getOperatingSystem() === "macOS" ? "⌘+K" : "^+K"} + keyboardShortcut={window.ContextBridge.getOperatingSystem() === "macOS" ? "⌘+K" : "^+K"} /> diff --git a/src/renderer/Core/Search/SearchBar.tsx b/src/renderer/Core/Search/SearchBar.tsx index c7bc53e5f..2d43b7367 100644 --- a/src/renderer/Core/Search/SearchBar.tsx +++ b/src/renderer/Core/Search/SearchBar.tsx @@ -1,4 +1,3 @@ -import { useContextBridge } from "@Core/Hooks"; import { Input } from "@fluentui/react-components"; import { SearchRegular } from "@fluentui/react-icons"; import type { ChangeEvent, KeyboardEvent, ReactElement, RefObject } from "react"; @@ -28,8 +27,6 @@ export const SearchBar = ({ searchBarSize, showIcon, }: SearchBarProps) => { - const { contextBridge } = useContextBridge(); - const onChange = onSearchTermUpdated ? (_: ChangeEvent, { value }: { value: string }) => onSearchTermUpdated(value) : undefined; @@ -40,7 +37,7 @@ export const SearchBar = ({ ref={refObject} appearance={ searchBarAppearance === "auto" - ? contextBridge.themeShouldUseDarkColors() + ? window.ContextBridge.themeShouldUseDarkColors() ? "filled-darker" : "filled-lighter" : searchBarAppearance diff --git a/src/renderer/Core/Search/SearchHistoryController.ts b/src/renderer/Core/Search/SearchHistoryController.ts index d4b4de4d5..fd907ad64 100644 --- a/src/renderer/Core/Search/SearchHistoryController.ts +++ b/src/renderer/Core/Search/SearchHistoryController.ts @@ -1,16 +1,15 @@ import { useSetting } from "@Core/Hooks"; -import type { ContextBridge } from "@common/Core"; import { useState } from "react"; -export const useSearchHistoryController = ({ contextBridge }: { contextBridge: ContextBridge }) => { - const isEnabled = () => contextBridge.getSettingValue("general.searchHistory.enabled", false); +export const useSearchHistoryController = () => { + const isEnabled = () => window.ContextBridge.getSettingValue("general.searchHistory.enabled", false); const { value: searchHistory, updateValue: setSearchHistory } = useSetting({ key: "general.searchHistory.history", defaultValue: [], }); - const limit = contextBridge.getSettingValue("general.searchHistory.limit", 10); + const limit = window.ContextBridge.getSettingValue("general.searchHistory.limit", 10); const [menuIsOpen, setMenuIsOpen] = useState(false); diff --git a/src/renderer/Core/Search/SearchViewController.ts b/src/renderer/Core/Search/SearchViewController.ts index 4822e410d..42a2ea19d 100644 --- a/src/renderer/Core/Search/SearchViewController.ts +++ b/src/renderer/Core/Search/SearchViewController.ts @@ -1,5 +1,5 @@ import { useSetting } from "@Core/Hooks"; -import type { ContextBridge, SearchResultItem, SearchResultItemAction } from "@common/Core"; +import type { SearchResultItem, SearchResultItemAction } from "@common/Core"; import type { SearchEngineId } from "@common/Core/Search"; import { useRef, useState } from "react"; import { getNextSearchResultItemId } from "./Helpers/getNextSearchResultItemId"; @@ -13,7 +13,6 @@ type ViewModel = { }; type SearchViewControllerProps = { - contextBridge: ContextBridge; searchResultItems: SearchResultItem[]; excludedSearchResultItemIds: string[]; favoriteSearchResultItemIds: string[]; @@ -30,7 +29,6 @@ const collectSearchResultItems = (searchResult: Record { if (!action.requiresConfirmation) { - await contextBridge.invokeAction(action); + await window.ContextBridge.invokeAction(action); return; } diff --git a/src/renderer/Core/Settings/Navigation.tsx b/src/renderer/Core/Settings/Navigation.tsx index feab3b2b8..f49caef2d 100644 --- a/src/renderer/Core/Settings/Navigation.tsx +++ b/src/renderer/Core/Settings/Navigation.tsx @@ -1,4 +1,3 @@ -import { useContextBridge } from "@Core/Hooks"; import { getImageUrl } from "@Core/getImageUrl"; import type { ExtensionInfo } from "@common/Core"; import { Tab, TabList } from "@fluentui/react-components"; @@ -13,7 +12,6 @@ type NavigationProps = { export const Navigation = ({ settingsPages, enabledExtensions }: NavigationProps) => { const { t } = useTranslation(); - const { contextBridge } = useContextBridge(); const navigate = useNavigate(); const { pathname } = useLocation(); @@ -61,7 +59,7 @@ export const Navigation = ({ settingsPages, enabledExtensions }: NavigationProps style={{ maxWidth: "100%", maxHeight: "100%" }} src={getImageUrl({ image: e.image, - shouldPreferDarkColors: contextBridge.themeShouldUseDarkColors(), + shouldPreferDarkColors: window.ContextBridge.themeShouldUseDarkColors(), })} /> diff --git a/src/renderer/Core/Settings/Pages/About.tsx b/src/renderer/Core/Settings/Pages/About.tsx index f7ac582fa..46540a319 100644 --- a/src/renderer/Core/Settings/Pages/About.tsx +++ b/src/renderer/Core/Settings/Pages/About.tsx @@ -1,12 +1,9 @@ -import { useContextBridge } from "../../Hooks"; import { Setting } from "../Setting"; import { SettingGroup } from "../SettingGroup"; import { SettingGroupList } from "../SettingGroupList"; export const About = () => { - const { contextBridge } = useContextBridge(); - - const { electronVersion, nodeJsVersion, v8Version, version } = contextBridge.getAboutUeli(); + const { electronVersion, nodeJsVersion, v8Version, version } = window.ContextBridge.getAboutUeli(); return ( diff --git a/src/renderer/Core/Settings/Pages/Appearance/Appearance.tsx b/src/renderer/Core/Settings/Pages/Appearance/Appearance.tsx index 3db993641..4aee056d6 100644 --- a/src/renderer/Core/Settings/Pages/Appearance/Appearance.tsx +++ b/src/renderer/Core/Settings/Pages/Appearance/Appearance.tsx @@ -1,4 +1,4 @@ -import { useContextBridge, useSetting } from "@Core/Hooks"; +import { useSetting } from "@Core/Hooks"; import { getAvailableThemes, getTheme } from "@Core/Theme"; import { darkTheme, lightTheme } from "@Core/Theme/defaultValues"; import { ThemeContext } from "@Core/ThemeContext"; @@ -15,7 +15,6 @@ import { SearchBarSettings } from "./SearchBarSettings"; export const Appearance = () => { const { t } = useTranslation("settingsAppearance"); - const { contextBridge } = useContextBridge(); const { setTheme } = useContext(ThemeContext); const availableThemes = getAvailableThemes(); @@ -43,27 +42,27 @@ export const Appearance = () => { const updateTheme = (themeName: string) => { setThemeName(themeName); - setTheme(getTheme(contextBridge)); + setTheme(getTheme(window.ContextBridge)); }; const resetDarkVariants = () => { setDarkVariants(darkTheme); - setTheme(getTheme(contextBridge)); + setTheme(getTheme(window.ContextBridge)); }; const updateDarkVariants = (shade: keyof BrandVariants, value: string) => { setDarkVariants({ ...darkVariants, ...{ [shade]: value } }); - setTheme(getTheme(contextBridge)); + setTheme(getTheme(window.ContextBridge)); }; const resetLightVariants = () => { setLightVariants(lightTheme); - setTheme(getTheme(contextBridge)); + setTheme(getTheme(window.ContextBridge)); }; const updateLightVariants = (shade: keyof BrandVariants, value: string) => { setLightVariants({ ...lightVariants, ...{ [shade]: value } }); - setTheme(getTheme(contextBridge)); + setTheme(getTheme(window.ContextBridge)); }; return ( diff --git a/src/renderer/Core/Settings/Pages/Debug/Logs.tsx b/src/renderer/Core/Settings/Pages/Debug/Logs.tsx index f91e4a6af..0f0dbad63 100644 --- a/src/renderer/Core/Settings/Pages/Debug/Logs.tsx +++ b/src/renderer/Core/Settings/Pages/Debug/Logs.tsx @@ -1,20 +1,18 @@ -import { useContextBridge } from "@Core/Hooks"; import { ThemeContext } from "@Core/ThemeContext"; import { useContext, useEffect, useState } from "react"; export const Logs = () => { - const { contextBridge } = useContextBridge(); const { theme } = useContext(ThemeContext); - const [logs, setLogs] = useState(contextBridge.getLogs()); + const [logs, setLogs] = useState(window.ContextBridge.getLogs()); useEffect(() => { - const logsUpdatedEventHandler = () => setLogs(contextBridge.getLogs()); + const logsUpdatedEventHandler = () => setLogs(window.ContextBridge.getLogs()); - contextBridge.ipcRenderer.on("logsUpdated", logsUpdatedEventHandler); + window.ContextBridge.ipcRenderer.on("logsUpdated", logsUpdatedEventHandler); return () => { - contextBridge.ipcRenderer.off("logsUpdated", logsUpdatedEventHandler); + window.ContextBridge.ipcRenderer.off("logsUpdated", logsUpdatedEventHandler); }; }); diff --git a/src/renderer/Core/Settings/Pages/Debug/ResetSettings.tsx b/src/renderer/Core/Settings/Pages/Debug/ResetSettings.tsx index 91719a249..257d2ac1f 100644 --- a/src/renderer/Core/Settings/Pages/Debug/ResetSettings.tsx +++ b/src/renderer/Core/Settings/Pages/Debug/ResetSettings.tsx @@ -1,4 +1,3 @@ -import { useContextBridge } from "@Core/Hooks"; import { Button, Dialog, @@ -14,7 +13,6 @@ import { useTranslation } from "react-i18next"; export const ResetSettings = () => { const { t } = useTranslation("settingsDebug"); - const { contextBridge } = useContextBridge(); return ( @@ -36,7 +34,7 @@ export const ResetSettings = () => { - diff --git a/src/renderer/Core/Settings/Pages/Extensions.tsx b/src/renderer/Core/Settings/Pages/Extensions.tsx index 965190ad3..b022d2019 100644 --- a/src/renderer/Core/Settings/Pages/Extensions.tsx +++ b/src/renderer/Core/Settings/Pages/Extensions.tsx @@ -1,4 +1,4 @@ -import { useContextBridge, useSetting } from "@Core/Hooks"; +import { useSetting } from "@Core/Hooks"; import { getImageUrl } from "@Core/getImageUrl"; import { Avatar, @@ -24,7 +24,6 @@ import { useTranslation } from "react-i18next"; export const Extensions = () => { const { t } = useTranslation(); - const { contextBridge } = useContextBridge(); const toasterId = useId("rescanToasterId"); const { dispatchToast } = useToastController(toasterId); @@ -32,7 +31,7 @@ export const Extensions = () => { getAvailableExtensions, extensionDisabled: disableExtension, extensionEnabled: enableExtension, - } = contextBridge; + } = window.ContextBridge; const { value: enabledExtensionIds, updateValue: setEnabledExtensionIds } = useSetting({ key: "extensions.enabledExtensionIds", @@ -53,8 +52,8 @@ export const Extensions = () => { const triggerExtensionRescan = async (event: MouseEvent, extensionId: string) => { event.preventDefault(); - await contextBridge.triggerExtensionRescan(extensionId); - const { name, nameTranslation } = contextBridge.getExtension(extensionId); + await window.ContextBridge.triggerExtensionRescan(extensionId); + const { name, nameTranslation } = window.ContextBridge.getExtension(extensionId); dispatchToast( @@ -104,7 +103,7 @@ export const Extensions = () => { src={getImageUrl({ image, shouldPreferDarkColors: - contextBridge.themeShouldUseDarkColors(), + window.ContextBridge.themeShouldUseDarkColors(), })} /> @@ -122,7 +121,7 @@ export const Extensions = () => { appearance="subtle" onClick={async (e) => { e.preventDefault(); - await contextBridge.openExternal( + await window.ContextBridge.openExternal( `https://github.com/${author.githubUserName}`, ); }} diff --git a/src/renderer/Core/Settings/Pages/Favorites.tsx b/src/renderer/Core/Settings/Pages/Favorites.tsx index d80a42125..5bd616e3a 100644 --- a/src/renderer/Core/Settings/Pages/Favorites.tsx +++ b/src/renderer/Core/Settings/Pages/Favorites.tsx @@ -1,4 +1,4 @@ -import { useContextBridge, useFavorites, useSearchResultItems } from "@Core/Hooks"; +import { useFavorites, useSearchResultItems } from "@Core/Hooks"; import { SettingGroupList } from "@Core/Settings/SettingGroupList"; import { getImageUrl } from "@Core/getImageUrl"; import { Badge, Button, Input, Text, Tooltip } from "@fluentui/react-components"; @@ -7,13 +7,12 @@ import { useTranslation } from "react-i18next"; import { SettingGroup } from "../SettingGroup"; export const Favorites = () => { - const { contextBridge } = useContextBridge(); const { t } = useTranslation("settingsFavorites"); const { searchResultItems } = useSearchResultItems(); const { favorites } = useFavorites(); const removeFavorite = async (id: string) => { - await contextBridge.removeFavorite(id); + await window.ContextBridge.removeFavorite(id); }; const favoriteSearchResultItems = searchResultItems.filter((s) => favorites.includes(s.id)); @@ -36,7 +35,7 @@ export const Favorites = () => { style={{ maxWidth: "100%", maxHeight: "100%" }} src={getImageUrl({ image: s.image, - shouldPreferDarkColors: contextBridge.themeShouldUseDarkColors(), + shouldPreferDarkColors: window.ContextBridge.themeShouldUseDarkColors(), })} /> diff --git a/src/renderer/Core/Settings/Pages/General/Autostart.tsx b/src/renderer/Core/Settings/Pages/General/Autostart.tsx index 61efcc51e..c19acf326 100644 --- a/src/renderer/Core/Settings/Pages/General/Autostart.tsx +++ b/src/renderer/Core/Settings/Pages/General/Autostart.tsx @@ -1,4 +1,3 @@ -import { useContextBridge } from "@Core/Hooks"; import { Setting } from "@Core/Settings/Setting"; import { Switch } from "@fluentui/react-components"; import { useState } from "react"; @@ -6,12 +5,11 @@ import { useTranslation } from "react-i18next"; export const Autostart = () => { const { t } = useTranslation("settingsGeneral"); - const { contextBridge } = useContextBridge(); - const [autostartIsEnabled, setAutostartIsEnabled] = useState(contextBridge.autostartIsEnabled()); + const [autostartIsEnabled, setAutostartIsEnabled] = useState(window.ContextBridge.autostartIsEnabled()); const updateAutostartSettings = (autostartIsEnabled: boolean) => { - contextBridge.autostartSettingsChanged(autostartIsEnabled); + window.ContextBridge.autostartSettingsChanged(autostartIsEnabled); setAutostartIsEnabled(autostartIsEnabled); }; diff --git a/src/renderer/Core/Settings/Pages/General/DockSettings.tsx b/src/renderer/Core/Settings/Pages/General/DockSettings.tsx index a4d5e376e..0030199b5 100644 --- a/src/renderer/Core/Settings/Pages/General/DockSettings.tsx +++ b/src/renderer/Core/Settings/Pages/General/DockSettings.tsx @@ -1,11 +1,10 @@ -import { useContextBridge, useSetting } from "@Core/Hooks"; +import { useSetting } from "@Core/Hooks"; import { Setting } from "@Core/Settings/Setting"; import { Switch } from "@fluentui/react-components"; import { useTranslation } from "react-i18next"; export const DockSettings = () => { const { t } = useTranslation("settingsGeneral"); - const { contextBridge } = useContextBridge(); const { value: showAppIconInDock, updateValue: setShowAppIconInDock } = useSetting({ key: "appearance.showAppIconInDock", @@ -13,7 +12,7 @@ export const DockSettings = () => { }); const updateShowAppIconInDock = async (value: boolean) => { - await contextBridge.updateSettingValue("appearance.showAppIconInDock", value); + await window.ContextBridge.updateSettingValue("appearance.showAppIconInDock", value); setShowAppIconInDock(value); }; diff --git a/src/renderer/Core/Settings/Pages/General/HotKey.tsx b/src/renderer/Core/Settings/Pages/General/HotKey.tsx index b3474980b..56dedebd0 100644 --- a/src/renderer/Core/Settings/Pages/General/HotKey.tsx +++ b/src/renderer/Core/Settings/Pages/General/HotKey.tsx @@ -1,4 +1,4 @@ -import { useContextBridge, useSetting } from "@Core/Hooks"; +import { useSetting } from "@Core/Hooks"; import { Setting } from "@Core/Settings/Setting"; import { isValidHotkey } from "@common/Core/Hotkey"; import { Button, Field, Input, Tooltip } from "@fluentui/react-components"; @@ -9,8 +9,6 @@ import { useTranslation } from "react-i18next"; export const HotKey = () => { const { t } = useTranslation("settingsGeneral"); - const { contextBridge } = useContextBridge(); - const { value: hotkey, updateValue: setHotkey } = useSetting({ key: "general.hotkey", defaultValue: "Alt+Space" }); const [temporaryHotkey, setTemporaryHotkey] = useState(hotkey); @@ -36,7 +34,7 @@ export const HotKey = () => { size="small" icon={} onClick={() => - contextBridge.openExternal( + window.ContextBridge.openExternal( "https://www.electronjs.org/docs/latest/api/accelerator", ) } diff --git a/src/renderer/Core/Settings/Pages/SearchEngine/ExcludedItems.tsx b/src/renderer/Core/Settings/Pages/SearchEngine/ExcludedItems.tsx index 23541e4dd..cccf1543a 100644 --- a/src/renderer/Core/Settings/Pages/SearchEngine/ExcludedItems.tsx +++ b/src/renderer/Core/Settings/Pages/SearchEngine/ExcludedItems.tsx @@ -1,4 +1,4 @@ -import { useContextBridge, useSearchResultItems } from "@Core/Hooks"; +import { useSearchResultItems } from "@Core/Hooks"; import { getImageUrl } from "@Core/getImageUrl"; import { Badge, Button, Input, Text, Tooltip } from "@fluentui/react-components"; import { DismissRegular } from "@fluentui/react-icons"; @@ -7,14 +7,13 @@ import { useTranslation } from "react-i18next"; export const ExcludedItems = () => { const { t } = useTranslation("settingsSearchEngine"); - const { contextBridge } = useContextBridge(); const { searchResultItems } = useSearchResultItems(); - const [excludedIds, setExcludedIds] = useState(contextBridge.getExcludedSearchResultItemIds()); + const [excludedIds, setExcludedIds] = useState(window.ContextBridge.getExcludedSearchResultItemIds()); const removeExcludedSearchResultItem = async (id: string) => { - await contextBridge.removeExcludedSearchResultItem(id); - setExcludedIds(contextBridge.getExcludedSearchResultItemIds()); + await window.ContextBridge.removeExcludedSearchResultItem(id); + setExcludedIds(window.ContextBridge.getExcludedSearchResultItemIds()); }; const excludedSearchResultItems = searchResultItems.filter((f) => excludedIds.includes(f.id)); @@ -33,7 +32,7 @@ export const ExcludedItems = () => { style={{ width: 16, height: 16 }} src={getImageUrl({ image, - shouldPreferDarkColors: contextBridge.themeShouldUseDarkColors(), + shouldPreferDarkColors: window.ContextBridge.themeShouldUseDarkColors(), })} /> } diff --git a/src/renderer/Core/Settings/Pages/SearchEngine/RescanInterval.tsx b/src/renderer/Core/Settings/Pages/SearchEngine/RescanInterval.tsx index 52c1cf82a..35763d8f2 100644 --- a/src/renderer/Core/Settings/Pages/SearchEngine/RescanInterval.tsx +++ b/src/renderer/Core/Settings/Pages/SearchEngine/RescanInterval.tsx @@ -1,4 +1,3 @@ -import { useContextBridge } from "@Core/Hooks"; import { Setting } from "@Core/Settings/Setting"; import { Button, Input, Tooltip } from "@fluentui/react-components"; import { DismissRegular } from "@fluentui/react-icons"; @@ -11,11 +10,10 @@ type RescanIntervalProps = { export const RescanInterval = ({ automaticRescanEnabled }: RescanIntervalProps) => { const { t } = useTranslation("settingsSearchEngine"); - const { contextBridge } = useContextBridge(); const defaultRescanIntervalInSeconds = 300; - const rescanIntervalInSeconds = contextBridge.getSettingValue( + const rescanIntervalInSeconds = window.ContextBridge.getSettingValue( "searchEngine.rescanIntervalInSeconds", defaultRescanIntervalInSeconds, ); @@ -23,7 +21,7 @@ export const RescanInterval = ({ automaticRescanEnabled }: RescanIntervalProps) const [tempRescanIntervalInSeconds, setTempRescanIntervalInSeconds] = useState(rescanIntervalInSeconds); const setRescanIntervalInSeconds = (value: number) => - contextBridge.updateSettingValue("searchEngine.rescanIntervalInSeconds", value); + window.ContextBridge.updateSettingValue("searchEngine.rescanIntervalInSeconds", value); return ( { - const { contextBridge } = useContextBridge(); - - const operatingSystem = contextBridge.getOperatingSystem(); + const operatingSystem = window.ContextBridge.getOperatingSystem(); const { value: backgroundMaterial, updateValue: setBackgroundMaterial } = useSetting({ key: "window.backgroundMaterial", diff --git a/src/renderer/Core/Settings/Pages/Window/WorkspaceVisibility.tsx b/src/renderer/Core/Settings/Pages/Window/WorkspaceVisibility.tsx index 8c83aad8b..9de7fe1de 100644 --- a/src/renderer/Core/Settings/Pages/Window/WorkspaceVisibility.tsx +++ b/src/renderer/Core/Settings/Pages/Window/WorkspaceVisibility.tsx @@ -1,19 +1,17 @@ -import { useContextBridge } from "@Core/Hooks"; import { Setting } from "@Core/Settings/Setting"; import { Switch } from "@fluentui/react-components"; import { useState } from "react"; import { useTranslation } from "react-i18next"; export const WorkspaceVisibility = () => { - const { contextBridge } = useContextBridge(); const { t } = useTranslation("settingsWindow"); const [visibleOnAllWorkspaces, setVisibleOnAllWorkspaces] = useState( - contextBridge.getSettingValue("window.visibleOnAllWorkspaces", false), + window.ContextBridge.getSettingValue("window.visibleOnAllWorkspaces", false), ); const updateVisibleOnAllWorkspaces = async (value: boolean) => { - await contextBridge.updateSettingValue("window.visibleOnAllWorkspaces", value); + await window.ContextBridge.updateSettingValue("window.visibleOnAllWorkspaces", value); setVisibleOnAllWorkspaces(value); }; diff --git a/src/renderer/Core/Settings/Settings.tsx b/src/renderer/Core/Settings/Settings.tsx index 23b5a9030..8d070e77c 100644 --- a/src/renderer/Core/Settings/Settings.tsx +++ b/src/renderer/Core/Settings/Settings.tsx @@ -1,4 +1,3 @@ -import { useContextBridge } from "@Core/Hooks"; import type { KeyboardEvent } from "react"; import { Route, Routes, useNavigate } from "react-router"; import { ExtensionSettings } from "./ExtensionSettings"; @@ -7,7 +6,6 @@ import { settingsPages } from "./Pages"; import { SettingsHeader } from "./SettingsHeader"; export const Settings = () => { - const { contextBridge } = useContextBridge(); const navigate = useNavigate(); const closeSettings = () => navigate({ pathname: "/" }); @@ -53,7 +51,7 @@ export const Settings = () => { > diff --git a/src/renderer/Core/useAppCssProperties.ts b/src/renderer/Core/useAppCssProperties.ts index a18e99c8e..aa0a2930c 100644 --- a/src/renderer/Core/useAppCssProperties.ts +++ b/src/renderer/Core/useAppCssProperties.ts @@ -1,6 +1,5 @@ import type { ContextBridge, OperatingSystem } from "@common/Core"; import { useEffect, useState, type CSSProperties } from "react"; -import { useContextBridge } from "./Hooks"; const getMacOsCssProperties = (contextBridge: ContextBridge): CSSProperties => { return contextBridge.getSettingValue("window.vibrancy", "None") === "None" @@ -25,16 +24,14 @@ const getWindowsCssProperties = (contextBridge: ContextBridge): CSSProperties => }; export const useAppCssProperties = () => { - const { contextBridge } = useContextBridge(); - - const operatingSystem = contextBridge.getOperatingSystem(); + const operatingSystem = window.ContextBridge.getOperatingSystem(); const extendGlobalStyles = (cssProperties: CSSProperties) => ({ height: "100vh", ...cssProperties }); const initialProperties: Record = { Linux: extendGlobalStyles({}), - macOS: extendGlobalStyles(getMacOsCssProperties(contextBridge)), - Windows: extendGlobalStyles(getWindowsCssProperties(contextBridge)), + macOS: extendGlobalStyles(getMacOsCssProperties(window.ContextBridge)), + Windows: extendGlobalStyles(getWindowsCssProperties(window.ContextBridge)), }; const [appCssProperties, setAppCssProperties] = useState(initialProperties[operatingSystem]); @@ -42,8 +39,8 @@ export const useAppCssProperties = () => { useEffect(() => { const eventHandlers: Record void> = { Linux: () => null, - macOS: () => setAppCssProperties(extendGlobalStyles(getMacOsCssProperties(contextBridge))), - Windows: () => setAppCssProperties(extendGlobalStyles(getWindowsCssProperties(contextBridge))), + macOS: () => setAppCssProperties(extendGlobalStyles(getMacOsCssProperties(window.ContextBridge))), + Windows: () => setAppCssProperties(extendGlobalStyles(getWindowsCssProperties(window.ContextBridge))), }; const channels: Record = { @@ -58,13 +55,13 @@ export const useAppCssProperties = () => { const registerEventListeners = () => { for (const channel of channels[operatingSystem]) { - contextBridge.ipcRenderer.on(channel, eventHandlers[operatingSystem]); + window.ContextBridge.ipcRenderer.on(channel, eventHandlers[operatingSystem]); } }; const unregisterEventListeners = () => { for (const channel of channels[operatingSystem]) { - contextBridge.ipcRenderer.off(channel, eventHandlers[operatingSystem]); + window.ContextBridge.ipcRenderer.off(channel, eventHandlers[operatingSystem]); } }; diff --git a/src/renderer/Extensions/ApplicationSearch/ApplicationSearchSettings.tsx b/src/renderer/Extensions/ApplicationSearch/ApplicationSearchSettings.tsx index b423e7781..c367d60c5 100644 --- a/src/renderer/Extensions/ApplicationSearch/ApplicationSearchSettings.tsx +++ b/src/renderer/Extensions/ApplicationSearch/ApplicationSearchSettings.tsx @@ -1,4 +1,3 @@ -import { useContextBridge } from "@Core/Hooks"; import type { OperatingSystem } from "@common/Core"; import type { ReactElement } from "react"; import { LinuxSettings } from "./Linux"; @@ -6,15 +5,11 @@ import { MacOsSettings } from "./MacOs"; import { WindowsSettings } from "./Windows"; export const ApplicationSearchSettings = () => { - const { contextBridge } = useContextBridge(); - - const operatingSystem = contextBridge.getOperatingSystem(); - const settings: Record = { Linux: , macOS: , Windows: , }; - return settings[operatingSystem]; + return settings[window.ContextBridge.getOperatingSystem()]; }; diff --git a/src/renderer/Extensions/ApplicationSearch/Linux/LinuxSettings.tsx b/src/renderer/Extensions/ApplicationSearch/Linux/LinuxSettings.tsx index 89c1ce27b..220d5ac0e 100644 --- a/src/renderer/Extensions/ApplicationSearch/Linux/LinuxSettings.tsx +++ b/src/renderer/Extensions/ApplicationSearch/Linux/LinuxSettings.tsx @@ -1,4 +1,4 @@ -import { useContextBridge, useExtensionSetting } from "@Core/Hooks"; +import { useExtensionSetting } from "@Core/Hooks"; import { SettingGroup } from "@Core/Settings/SettingGroup"; import { SettingGroupList } from "@Core/Settings/SettingGroupList"; import { Button, Input, Tooltip } from "@fluentui/react-components"; @@ -6,8 +6,6 @@ import { AddRegular, DismissRegular, FolderRegular } from "@fluentui/react-icons import { useState } from "react"; export const LinuxSettings = () => { - const { contextBridge } = useContextBridge(); - const extensionId = "ApplicationSearch"; const [newFolder, setNewFolder] = useState(""); @@ -29,7 +27,7 @@ export const LinuxSettings = () => { }; const chooseFolder = async () => { - const result = await contextBridge.showOpenDialog({ properties: ["openDirectory"] }); + const result = await window.ContextBridge.showOpenDialog({ properties: ["openDirectory"] }); if (!result.canceled && result.filePaths.length) { setNewFolder(result.filePaths[0]); } diff --git a/src/renderer/Extensions/ApplicationSearch/MacOs/MacOsSettings.tsx b/src/renderer/Extensions/ApplicationSearch/MacOs/MacOsSettings.tsx index 6abc5485c..bfcab0d28 100644 --- a/src/renderer/Extensions/ApplicationSearch/MacOs/MacOsSettings.tsx +++ b/src/renderer/Extensions/ApplicationSearch/MacOs/MacOsSettings.tsx @@ -1,4 +1,4 @@ -import { useContextBridge, useExtensionSetting } from "@Core/Hooks"; +import { useExtensionSetting } from "@Core/Hooks"; import { Setting } from "@Core/Settings/Setting"; import { SettingGroup } from "@Core/Settings/SettingGroup"; import { SettingGroupList } from "@Core/Settings/SettingGroupList"; @@ -8,8 +8,6 @@ import { useState } from "react"; import { useTranslation } from "react-i18next"; export const MacOsSettings = () => { - const { contextBridge } = useContextBridge(); - const extensionId = "ApplicationSearch"; const [newFolder, setNewFolder] = useState(""); @@ -38,7 +36,7 @@ export const MacOsSettings = () => { }; const chooseFolder = async () => { - const result = await contextBridge.showOpenDialog({ properties: ["openDirectory"] }); + const result = await window.ContextBridge.showOpenDialog({ properties: ["openDirectory"] }); if (!result.canceled && result.filePaths.length) { setNewFolder(result.filePaths[0]); } diff --git a/src/renderer/Extensions/ApplicationSearch/Windows/Folders.tsx b/src/renderer/Extensions/ApplicationSearch/Windows/Folders.tsx index 869d84f8a..8840d6d5e 100644 --- a/src/renderer/Extensions/ApplicationSearch/Windows/Folders.tsx +++ b/src/renderer/Extensions/ApplicationSearch/Windows/Folders.tsx @@ -1,11 +1,9 @@ -import { useContextBridge, useExtensionSetting } from "@Core/Hooks"; +import { useExtensionSetting } from "@Core/Hooks"; import { Button, Input, Tooltip } from "@fluentui/react-components"; import { AddRegular, DismissRegular, FolderRegular } from "@fluentui/react-icons"; import { useState } from "react"; export const Folders = () => { - const { contextBridge } = useContextBridge(); - const { value: folders, updateValue: setFolders } = useExtensionSetting({ extensionId: "ApplicationSearch", key: "windowsFolders", @@ -23,7 +21,7 @@ export const Folders = () => { }; const chooseFolder = async () => { - const result = await contextBridge.showOpenDialog({ properties: ["openDirectory"] }); + const result = await window.ContextBridge.showOpenDialog({ properties: ["openDirectory"] }); if (!result.canceled && result.filePaths.length) { setNewFolder(result.filePaths[0]); } diff --git a/src/renderer/Extensions/Base64Conversion/Converter.tsx b/src/renderer/Extensions/Base64Conversion/Converter.tsx index 7d6838cf1..61a5d3720 100644 --- a/src/renderer/Extensions/Base64Conversion/Converter.tsx +++ b/src/renderer/Extensions/Base64Conversion/Converter.tsx @@ -1,5 +1,4 @@ import type { InvocationArgument } from "@common/Extensions/Base64Conversion"; -import { useContextBridge } from "@Core/Hooks"; import { Textarea } from "@fluentui/react-components"; import { useEffect, useState } from "react"; @@ -11,13 +10,12 @@ type ConverterProps = { export const Converter = ({ setConvertedText, encodePlaceholder, decodePlaceholder }: ConverterProps) => { const extensionId = "Base64Conversion"; - const { contextBridge } = useContextBridge(); const [input, setInput] = useState({ payload: "", action: "encode" }); const [conversionResult, setConversionResult] = useState(""); const convertText = async (payload: string, action: "encode" | "decode") => { try { - return await contextBridge.invokeExtension(extensionId, { + return await window.ContextBridge.invokeExtension(extensionId, { payload, action, }); diff --git a/src/renderer/Extensions/BrowserBookmarks/BrowserBookmarksSettings.tsx b/src/renderer/Extensions/BrowserBookmarks/BrowserBookmarksSettings.tsx index 31d11f91f..cbf8b5025 100644 --- a/src/renderer/Extensions/BrowserBookmarks/BrowserBookmarksSettings.tsx +++ b/src/renderer/Extensions/BrowserBookmarks/BrowserBookmarksSettings.tsx @@ -1,4 +1,4 @@ -import { useContextBridge, useExtensionSetting } from "@Core/Hooks"; +import { useExtensionSetting } from "@Core/Hooks"; import { Setting } from "@Core/Settings/Setting"; import { SettingGroup } from "@Core/Settings/SettingGroup"; import { SettingGroupList } from "@Core/Settings/SettingGroupList"; @@ -8,7 +8,6 @@ import { useTranslation } from "react-i18next"; export const BrowserBookmarksSettings = () => { const { t } = useTranslation("extension[BrowserBookmarks]"); - const { contextBridge } = useContextBridge(); const extensionId = "BrowserBookmarks"; @@ -56,7 +55,7 @@ export const BrowserBookmarksSettings = () => { {browserName} {browserName} diff --git a/src/renderer/Extensions/FileSearch/FileSearchSettings.tsx b/src/renderer/Extensions/FileSearch/FileSearchSettings.tsx index e24a51f6a..65dd4c100 100644 --- a/src/renderer/Extensions/FileSearch/FileSearchSettings.tsx +++ b/src/renderer/Extensions/FileSearch/FileSearchSettings.tsx @@ -1,4 +1,4 @@ -import { useContextBridge, useExtensionSetting } from "@Core/Hooks"; +import { useExtensionSetting } from "@Core/Hooks"; import { Setting } from "@Core/Settings/Setting"; import { SettingGroup } from "@Core/Settings/SettingGroup"; import { SettingGroupList } from "@Core/Settings/SettingGroupList"; @@ -8,7 +8,6 @@ import { useTranslation } from "react-i18next"; export const FileSearchSettings = () => { const { t } = useTranslation("extension[FileSearch]"); - const { contextBridge } = useContextBridge(); const { value: maxSearchResultCount, updateValue: setMaxSearchResultCount } = useExtensionSetting({ extensionId: "FileSearch", @@ -21,7 +20,7 @@ export const FileSearchSettings = () => { }); const chooseFile = async () => { - const result = await contextBridge.showOpenDialog({ properties: ["openFile"] }); + const result = await window.ContextBridge.showOpenDialog({ properties: ["openFile"] }); if (!result.canceled && result.filePaths.length > 0) { setEsFilePath(result.filePaths[0]); } @@ -40,10 +39,10 @@ export const FileSearchSettings = () => { /> } /> - {contextBridge.getOperatingSystem() === "Windows" && ( + {window.ContextBridge.getOperatingSystem() === "Windows" && ( { const { t } = useTranslation("extension[SimpleFileSearch]"); - const { contextBridge } = useContextBridge(); - const [isDialogOpen, setIsDialogOpen] = useState(false); const [temporaryFolderSetting, setTemporaryFolderSetting] = useState(initialFolderSetting); @@ -56,14 +53,18 @@ export const EditFolder = ({ initialFolderSetting, onSave }: EditFolderProps) => }; const openFileDialog = async () => { - const result = await contextBridge.showOpenDialog({ properties: ["openDirectory"] }); + const result = await window.ContextBridge.showOpenDialog({ properties: ["openDirectory"] }); if (!result.canceled && result.filePaths.length) { setPath(result.filePaths[0]); } }; const setPath = (path: string) => { - setTemporaryFolderSetting({ ...temporaryFolderSetting, path, isValidPath: contextBridge.fileExists(path) }); + setTemporaryFolderSetting({ + ...temporaryFolderSetting, + path, + isValidPath: window.ContextBridge.fileExists(path), + }); }; const setRecursive = (recursive: boolean) => setTemporaryFolderSetting({ ...temporaryFolderSetting, recursive }); diff --git a/src/renderer/Extensions/TerminalLauncher/TerminalLauncherSettings.tsx b/src/renderer/Extensions/TerminalLauncher/TerminalLauncherSettings.tsx index 27a883bea..c8937cda3 100644 --- a/src/renderer/Extensions/TerminalLauncher/TerminalLauncherSettings.tsx +++ b/src/renderer/Extensions/TerminalLauncher/TerminalLauncherSettings.tsx @@ -1,4 +1,4 @@ -import { useContextBridge, useExtensionSetting } from "@Core/Hooks"; +import { useExtensionSetting } from "@Core/Hooks"; import { Setting } from "@Core/Settings/Setting"; import { SettingGroup } from "@Core/Settings/SettingGroup"; import { SettingGroupList } from "@Core/Settings/SettingGroupList"; @@ -6,7 +6,6 @@ import { Dropdown, Input, Option } from "@fluentui/react-components"; import { useTranslation } from "react-i18next"; export const TerminalLauncherSettings = () => { - const { contextBridge } = useContextBridge(); const { t } = useTranslation("extension[TerminalLauncher]"); const extensionId = "TerminalLauncher"; @@ -18,7 +17,7 @@ export const TerminalLauncherSettings = () => { key: "terminalIds", }); - const availableTerminals = contextBridge.getAvailableTerminals(); + const availableTerminals = window.ContextBridge.getAvailableTerminals(); return ( diff --git a/src/renderer/Extensions/WebSearch/WebSearchSettings.tsx b/src/renderer/Extensions/WebSearch/WebSearchSettings.tsx index 6e40ab2be..51f9f5894 100644 --- a/src/renderer/Extensions/WebSearch/WebSearchSettings.tsx +++ b/src/renderer/Extensions/WebSearch/WebSearchSettings.tsx @@ -1,4 +1,4 @@ -import { useContextBridge, useExtensionSetting } from "@Core/Hooks"; +import { useExtensionSetting } from "@Core/Hooks"; import { Setting } from "@Core/Settings/Setting"; import { SettingGroup } from "@Core/Settings/SettingGroup"; import { SettingGroupList } from "@Core/Settings/SettingGroupList"; @@ -6,7 +6,6 @@ import { Dropdown, Option, Switch } from "@fluentui/react-components"; import { useTranslation } from "react-i18next"; export const WebSearchSettings = () => { - const { contextBridge } = useContextBridge(); const extensionId = "WebSearch"; const { t } = useTranslation("extension[WebSearch]"); @@ -49,7 +48,7 @@ export const WebSearchSettings = () => { {searchEngine} {searchEngine} diff --git a/src/renderer/Extensions/Workflow/NewActionOpenFile.tsx b/src/renderer/Extensions/Workflow/NewActionOpenFile.tsx index 4adab62ef..51011c7ec 100644 --- a/src/renderer/Extensions/Workflow/NewActionOpenFile.tsx +++ b/src/renderer/Extensions/Workflow/NewActionOpenFile.tsx @@ -1,4 +1,3 @@ -import { useContextBridge } from "@Core/Hooks"; import type { OpenFileActionArgs } from "@common/Extensions/Workflow"; import { Button, Field, Input } from "@fluentui/react-components"; import { FolderRegular } from "@fluentui/react-icons"; @@ -6,7 +5,6 @@ import { useTranslation } from "react-i18next"; import type { NewActionTypeProps } from "./NewActionTypeProps"; export const NewActionOpenFile = ({ args, setArgs }: NewActionTypeProps) => { - const { contextBridge } = useContextBridge(); const { t } = useTranslation("extension[Workflow]"); const { filePath } = args as OpenFileActionArgs; @@ -14,7 +12,7 @@ export const NewActionOpenFile = ({ args, setArgs }: NewActionTypeProps) => { const setFilePath = (filePath: string) => setArgs({ filePath }); const selectFile = async () => { - const result = await contextBridge.showOpenDialog({ properties: ["openFile"] }); + const result = await window.ContextBridge.showOpenDialog({ properties: ["openFile"] }); if (!result.canceled && result.filePaths.length > 0) { setFilePath(result.filePaths[0]); } diff --git a/src/renderer/Extensions/Workflow/NewActionOpenTerminal.tsx b/src/renderer/Extensions/Workflow/NewActionOpenTerminal.tsx index 3278a5902..a20de9eaa 100644 --- a/src/renderer/Extensions/Workflow/NewActionOpenTerminal.tsx +++ b/src/renderer/Extensions/Workflow/NewActionOpenTerminal.tsx @@ -1,11 +1,9 @@ -import { useContextBridge } from "@Core/Hooks"; import type { OpenTerminalActionArgs } from "@common/Extensions/Workflow"; import { Dropdown, Field, Input, Option } from "@fluentui/react-components"; import { useTranslation } from "react-i18next"; import type { NewActionTypeProps } from "./NewActionTypeProps"; export const NewActionOpenTerminal = ({ args, setArgs }: NewActionTypeProps) => { - const { contextBridge } = useContextBridge(); const { t } = useTranslation("extension[Workflow]"); const { terminalId, command } = args as OpenTerminalActionArgs; @@ -14,7 +12,7 @@ export const NewActionOpenTerminal = ({ args, setArgs }: NewActionTypeProps) => const setCommand = (newCommand: string) => setArgs({ terminalId, command: newCommand }); - const defaultTerminalId = contextBridge.getAvailableTerminals()[0]?.id; + const defaultTerminalId = window.ContextBridge.getAvailableTerminals()[0]?.id; return ( <> @@ -27,7 +25,7 @@ export const NewActionOpenTerminal = ({ args, setArgs }: NewActionTypeProps) => disabled={!terminalId} size="small" > - {contextBridge.getAvailableTerminals().map(({ id, name, assetFilePath }) => ( + {window.ContextBridge.getAvailableTerminals().map(({ id, name, assetFilePath }) => (