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

feat: communicate existence of openaiapikey #93

Merged
merged 2 commits into from Mar 19, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/client/apps/story/index.tsx
Expand Up @@ -112,7 +112,7 @@ export function Story() {

useEffect(() => {
window.ipc.send("hasOpenAiApiKey");
const unsubscribe = window.ipc.on("openAiApiKey", (hasKey: boolean) => {
const unsubscribe = window.ipc.on("hasOpenAiApiKey", (hasKey: boolean) => {
setHasOpenAiApiKey(hasKey);
});
return () => {
Expand Down
2 changes: 1 addition & 1 deletion src/electron/future/ipc/keys.ts
Expand Up @@ -3,5 +3,5 @@ import { ipcMain } from "electron";
import { keyStore } from "@/stores";

ipcMain.on("hasOpenAiApiKey", event => {
event.sender.send("openAiApiKey", Boolean(keyStore.get("openAiApiKey")));
event.sender.send("hasOpenAiApiKey", Boolean(keyStore.get("openAiApiKey")));
});
2 changes: 2 additions & 0 deletions src/electron/future/ipc/listeners.ts
Expand Up @@ -6,6 +6,7 @@ import { ipcMain } from "electron";
import { buildKey } from "#/build-key";
import { ID } from "#/enums";
import { keyStore, userStore } from "@/stores";
import { sendToAllWindows } from "@/stores/watchers";
import { clone, lfs } from "@/utils/git";
import { getCaptainData } from "@/utils/path-helpers";
import { readFilesRecursively } from "@/utils/read-files-recursively";
Expand All @@ -16,6 +17,7 @@ ipcMain.on(buildKey([ID.USER], { suffix: ":language" }), (_event, language) => {

ipcMain.on(buildKey([ID.KEYS], { suffix: ":set-openAiApiKey" }), (_event, openAiApiKey) => {
keyStore.set("openAiApiKey", openAiApiKey);
sendToAllWindows("hasOpenAiApiKey", Boolean(keyStore.get("openAiApiKey")));
});

ipcMain.on(buildKey([ID.KEYS], { suffix: ":get-openAiApiKey" }), event => {
Expand Down
4 changes: 2 additions & 2 deletions src/electron/future/stores/watchers.ts
Expand Up @@ -4,14 +4,14 @@ import { BrowserWindow } from "electron";

import { downloadsStore, inventoryStore, userStore } from "@/stores";

function sendToFocusedWindow<T>(key: string, value: T) {
export function sendToFocusedWindow<T>(key: string, value: T) {
const window_ = BrowserWindow.getFocusedWindow();
if (window_) {
window_.webContents.send(key, value);
}
}

function sendToAllWindows<T>(key: string, value: T) {
export function sendToAllWindows<T>(key: string, value: T) {
const windows_ = BrowserWindow.getAllWindows();
for (const window_ of windows_) {
window_.webContents.send(key, value);
Expand Down