Skip to content
This repository has been archived by the owner on Nov 23, 2023. It is now read-only.

Feature/keybindings #143

Merged
merged 11 commits into from
Sep 5, 2023
14 changes: 14 additions & 0 deletions .github/codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
coverage:
status:
project:
default:
# basic
target: 0%
threshold: 10%
# advanced settings
branches:
- master
- dev
if_ci_failed: error #success, failure, error, ignore
informational: false
only_pulls: false
1 change: 0 additions & 1 deletion .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ jobs:
with:
files: coverage/lcov.info
token: ${{ secrets.CODECOV_TOKEN }}

end:
name: End State ✅✅✅
runs-on: ubuntu-latest
Expand Down
20 changes: 17 additions & 3 deletions src/electron/lib/api/apis/UtilApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import settings, { getSecret } from "../../../utils/settings";
import { type UUID } from "../../../../shared/utils/UniqueEntity";
import { getSecrets, setSecret, clearSecret } from "../../../utils/settings";
import type { Setting, UserSettingsCategory, QueryResponse } from "../../../../shared/types";
import { app } from "electron";

// Exposes basic system information
export class UtilApi implements ElectronMainApi<UtilApi> {
Expand Down Expand Up @@ -42,10 +43,9 @@ export class UtilApi implements ElectronMainApi<UtilApi> {
for (const setting of newSettings) {
if (setting.secret) {
setSecret(setting.id, setting.value.toString());
} else {
settings.set(setting.value.toString(), setting.value);
}
} else settings.set(setting.id, setting.value);
}

return { status: "success" };
}

Expand All @@ -68,6 +68,20 @@ export class UtilApi implements ElectronMainApi<UtilApi> {
},
],
},
{
CenturionLC marked this conversation as resolved.
Show resolved Hide resolved
id: "keybind_settings",
title: "Keybindings",
settings: [
{
id: "Keybindings",
title: "Keybindings",
subtitle: "Customize your keybindings",
type: "preferences",
secret: false,
value: settings.get("Keybindings"),
},
],
},
];

return { status: "success", data: userSettings };
Expand Down
1 change: 1 addition & 0 deletions src/electron/utils/settings.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import ElectronStore from "electron-store";
import { safeStorage } from "electron";
import logger from "./logger";
import type { Preferences } from "../../shared/types";

interface Settings {
check: boolean;
Expand Down
30 changes: 28 additions & 2 deletions src/frontend/ui/base/Settings.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import SecureInput from "../../ui/utils/SecureInput.svelte";
import { toastStore } from "./../../lib/stores/ToastStore";
import { settingsStore } from "../../lib/stores/SettingsStore";
import ShortcutSettings from "../../ui/tiles/ShortcutSettings.svelte";

let selectedCategoryId = "";
let selectedCategory: UserSettingsCategory | undefined;
Expand All @@ -17,9 +18,11 @@
categories = res.data;
selectedCategoryId = categories.length ? categories[0].id : "";
}
// console.log(categories)
});

async function saveSettings(settings: Setting[]) {
// console.log(settings)
const res = await window.apis.utilApi.saveUserSettings(settings);

if (res.status === "success") {
Expand Down Expand Up @@ -107,12 +110,35 @@
>
Save
</div>
<!-- {:else}
{:else if selectedCategory?.id === "keybind_settings"}
{#each selectedCategory.settings as item (item.id)}
<div>
<label for="{item.id}" class="pb-3">
<div class="text-normal font-semibold text-zinc-300">{item.title}</div>
<div class="font-ligt text-sm text-zinc-500">{item.subtitle}</div>
</label>
{#if item.type === "preferences"}
<ShortcutSettings bind:settings="{item.value}" />
{/if}
</div>
{/each}
<div
class="mt-12 flex h-10 w-20 cursor-pointer items-center justify-center rounded-md border border-zinc-600 bg-zinc-800/[0.7] text-gray-300 transition duration-300 ease-in-out hover:text-zinc-500"
on:click="{() => {
if (selectedCategory) {
saveSettings(selectedCategory?.settings);
}
}}"
on:keydown="{null}"
>
Save
</div>
{:else}
<div
class="flex h-full w-full items-center justify-center text-xl font-semibold text-zinc-400"
>
<div class="coming-soon flex h-48 w-64 items-center justify-center">Coming Soon</div>
</div> -->
</div>
{/if}
</div>
</div>
Expand Down
28 changes: 22 additions & 6 deletions src/frontend/ui/tiles/ShortcutSettings.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,26 @@
type ShortcutAction,
ShortcutCombo,
} from "@frontend/lib/stores/ShortcutStore";
import { get } from "svelte/store";

function updateShortcut(action: string, index: number, event: KeyboardEvent) {
export let settings: { [key: string]: string[] } = {};
let shortcuts: { [key: string]: string[] } = get(shortcutsRegistry.shortcuts);

$: {
if (Object.keys(settings).length === 0) {
settings = shortcuts;
} else shortcutsRegistry.shortcuts.set(settings);
}

export function updateShortcut(action: string, index: number, event: KeyboardEvent) {
console.log(action, event);
const combo: ShortcutCombo | null = ShortcutCombo.fromEvent(event);
if (!combo) return;

shortcutsRegistry.updateActionShortcut(action as ShortcutAction, index, combo);
}

function addShortcut(action: string, event: KeyboardEvent) {
export function addShortcut(action: string, event: KeyboardEvent) {
const combo: ShortcutCombo | null = ShortcutCombo.fromEvent(event);
if (!combo) return;

Expand All @@ -24,8 +34,8 @@
</script>

<div class="content">
<b>Keyboard Shortcuts Settings</b>
<h6>Configure your shortcut preferences here</h6>
<b style="color: aliceblue;">Keyboard Shortcuts Settings</b>
<h6 style="color: aliceblue">Configure your shortcut preferences here</h6>
<table class="shortcutsTable">
{#each Object.entries($shortcutsRegistry) as [action, shortcuts]}
<tr>
Expand Down Expand Up @@ -58,18 +68,24 @@
<style>
.content {
width: 100%;
height: 100%;
height: 75%;
padding: 1em;
}
.shortcutsTable {
margin-top: 2em;
background-color: rgba(82, 82, 91, 0.705);
opacity: 0.8;
border-spacing: 10px;
}
.shortcutsTable tr {
border: 1px solid #32324b;
border: 2px solid #32324b;
border-radius: 1px;
border-spacing: 5px;
}
.shortcutsTable td {
padding-right: 0.5em;
text-align: center;
color: rgba(240, 248, 255, 0.952);
}
.shortcutsTable button {
border: none;
Expand Down
9 changes: 7 additions & 2 deletions src/shared/types/setting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export interface UserSetting {
title: string;
subtitle?: string;
secret?: boolean;
type: "dropdown" | "password" | "text" | "toggle";
type: "dropdown" | "password" | "text" | "toggle" | "preferences";
}

export interface InputSetting extends UserSetting {
Expand All @@ -30,4 +30,9 @@ export interface ToggleSetting extends UserSetting {
value: boolean;
}

export type Setting = DropdownSetting | InputSetting | ToggleSetting;
export interface Preferences extends UserSetting {
type: "preferences";
value: { [key: string]: string[] };
}

export type Setting = DropdownSetting | InputSetting | ToggleSetting | Preferences;
7 changes: 7 additions & 0 deletions tests/unit-tests/electron/lib/ai/AiManager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,5 +162,12 @@ describe("Test AI Manager", () => {
expect(result).toBe("");
});

// test("Test handle api error response", () => {

// const result = aiManager["handleApiErrorResponse"]("test","OpenAI");
// expect(result).toBeDefined();
// expect(result).toBe("test");
// });


});
Loading