Skip to content

Commit

Permalink
feature(cli-support): Toggle ueli using command line (#1213)
Browse files Browse the repository at this point in the history
* Changed main and SingleInstanceLock

* Fixed test

* Fixed Core Dependency bootstrap order

* Fixed linting

* Cleaned up code

* Directly implement second-instance event

* Package all js files for dynamic import

* Added warning for wayland in settings

* Moved warning to translation

* Updated documentation link

* Moved getEnvironmentVariable event to correct module

* Removed toggle setting

* Restored main

* Restored electron builder

* Merge conflict

* Prettier

* Update type

Co-authored-by: Oliver Schwendener <[email protected]>

* Added missing translations and improved UI

* Show and focus instead of toggle

---------

Co-authored-by: Oliver Schwendener <[email protected]>
Co-authored-by: Oliver Schwendener <[email protected]>
  • Loading branch information
3 people authored Dec 12, 2024
1 parent 547d380 commit 0344fe7
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/common/Core/ContextBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export type ContextBridge = {
getAvailableExtensions: () => ExtensionInfo[];
getAvailableTerminals: () => Terminal[];
getEnabledExtensions: () => ExtensionInfo[];
getEnvironmentVariable: (environmentVariable: string) => string | undefined;
getExtension: (extensionId: string) => ExtensionInfo;
getExtensionResources: <T extends Translations>() => { extensionId: string; resources: Resources<T> }[];
getExcludedSearchResultItemIds: () => string[];
Expand Down
6 changes: 5 additions & 1 deletion src/main/Core/BrowserWindow/BrowserWindowModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { EventSubscriber } from "@Core/EventSubscriber";
import type { SettingsManager } from "@Core/SettingsManager";
import type { UeliCommand, UeliCommandInvokedEvent } from "@Core/UeliCommand";
import type { OperatingSystem, SearchResultItemAction } from "@common/Core";
import type { BrowserWindow, IpcMain } from "electron";
import type { App, BrowserWindow, IpcMain } from "electron";
import { join } from "path";
import { NavigateToActionHandler } from "./ActionHandler";
import { AppIconFilePathResolver } from "./AppIconFilePathResolver";
Expand Down Expand Up @@ -83,6 +83,7 @@ export class BrowserWindowModule {
browserWindowToggler,
settingsManager,
ipcMain,
app,
);

dependencyRegistry
Expand Down Expand Up @@ -113,6 +114,7 @@ export class BrowserWindowModule {
browserWindowToggler: BrowserWindowToggler,
settingsManager: SettingsManager,
ipcMain: IpcMain,
app: App,
) {
const shouldHideWindowAfterInvocation = (action: SearchResultItemAction) =>
action.hideWindowAfterInvocation &&
Expand Down Expand Up @@ -164,6 +166,8 @@ export class BrowserWindowModule {

ipcMain.on("escapePressed", () => shouldHideWindowOnEscapePressed() && browserWindowToggler.hide());

app.on("second-instance", () => browserWindowToggler.showAndFocus());

BrowserWindowModule.registerUeliCommandEvents(browserWindow, eventSubscriber, browserWindowToggler);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@ import { EnvironmentVariableProvider } from "./EnvironmentVariableProvider";

export class EnvironmentVariableProviderModule {
public static bootstrap(dependencyRegistry: DependencyRegistry<Dependencies>): void {
dependencyRegistry.register(
"EnvironmentVariableProvider",
new EnvironmentVariableProvider(<Record<string, string>>process.env),
);
const ipcMain = dependencyRegistry.get("IpcMain");

const environmentVariableProvider = new EnvironmentVariableProvider(<Record<string, string>>process.env);

dependencyRegistry.register("EnvironmentVariableProvider", environmentVariableProvider);

ipcMain.on("getEnvironmentVariable", (event, { environmentVariable }) => {
event.returnValue = environmentVariableProvider.get(environmentVariable);
});
}
}
2 changes: 2 additions & 0 deletions src/preload/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ const contextBridgeImplementation: ContextBridge = {
getAvailableExtensions: () => ipcRenderer.sendSync("getAvailableExtensions"),
getAvailableTerminals: () => ipcRenderer.sendSync("getAvailableTerminals"),
getEnabledExtensions: () => ipcRenderer.sendSync("getEnabledExtensions"),
getEnvironmentVariable: (environmentVariable) =>
ipcRenderer.sendSync("getEnvironmentVariable", { environmentVariable }),
getExtension: (extensionId) => ipcRenderer.sendSync("getExtension", { extensionId }),
getExtensionResources: () => ipcRenderer.sendSync("getExtensionResources"),
getExcludedSearchResultItemIds: () => ipcRenderer.sendSync("getExcludedSearchResultItemIds"),
Expand Down
4 changes: 4 additions & 0 deletions src/renderer/Core/I18n/getCoreResources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ export const getCoreResources = (): { namespace: string; resources: Resources<Tr
searchHistoryEnabledDescription: "The search history lets you see your previous searches",
searchHistoryLimit: "Search History Limit",
searchHistoryLimitHint: "Limits the maximum number of search history items",
waylandWarning: "Hotkeys may not work.",
waylandWarningMoreInfo: "More info",
showAppIconInDock: "Show app icon in dock",
webBrowser: "Web Browser",
useDefaultWebBrowser: "Use system's default web browser",
Expand All @@ -81,6 +83,8 @@ export const getCoreResources = (): { namespace: string; resources: Resources<Tr
searchHistoryEnabledDescription: "Der Suchverlauf zeigt dir deine vorherigen Suchen",
searchHistoryLimit: "Suchverlauf Limit",
searchHistoryLimitHint: "Begrenzt die maximale Anzahl an Suchverlaufseinträgen",
waylandWarning: "Tastenkombinationen funktionieren möglicherweise nicht.",
waylandWarningMoreInfo: "Mehr Informationen",
showAppIconInDock: "App-Symbol im Dock anzeigen",
webBrowser: "Web Browser",
useDefaultWebBrowser: "Systemstandard Webbrowser verwenden",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { SettingGroup } from "@Core/Settings/SettingGroup";
import { useTranslation } from "react-i18next";
import { HotKeyBinding } from "./HotkeyBinding";
import { HotkeyEnabled } from "./HotkeyEnabled";
import { WaylandWarning } from "./WaylandWarning";

export const HotkeySettings = () => {
const { t } = useTranslation("settingsGeneral");
Expand All @@ -12,8 +13,11 @@ export const HotkeySettings = () => {
defaultValue: true,
});

const waylandDetected = window.ContextBridge.getEnvironmentVariable("XDG_SESSION_TYPE") === "wayland";

return (
<SettingGroup title={t("hotkey")}>
{waylandDetected && <WaylandWarning />}
<HotkeyEnabled hotkeyEnabled={hotkeyEnabled} setHotkeyEnabled={setHotkeyEnabled} />
<HotKeyBinding hotkeyEnabled={hotkeyEnabled} />
</SettingGroup>
Expand Down
25 changes: 25 additions & 0 deletions src/renderer/Core/Settings/Pages/General/HotKey/WaylandWarning.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Button, MessageBar, MessageBarActions, MessageBarBody, Tooltip } from "@fluentui/react-components";
import { InfoRegular } from "@fluentui/react-icons";
import { useTranslation } from "react-i18next";

export const WaylandWarning = () => {
const { t } = useTranslation("settingsGeneral");

return (
<MessageBar intent="warning">
<MessageBarBody>{t("waylandWarning")}</MessageBarBody>
<MessageBarActions>
<Tooltip content={t("waylandWarningMoreInfo")} relationship="label" withArrow>
<Button
appearance="subtle"
size="small"
icon={<InfoRegular />}
onClick={() =>
window.ContextBridge.openExternal("https://github.com/oliverschwendener/ueli/wiki#linux")
}
/>
</Tooltip>
</MessageBarActions>
</MessageBar>
);
};

0 comments on commit 0344fe7

Please sign in to comment.