Skip to content

Commit

Permalink
feat: added focus indication to windows
Browse files Browse the repository at this point in the history
  • Loading branch information
Tormak9970 committed Apr 10, 2023
1 parent e2f1fba commit efa8fb9
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 25 deletions.
2 changes: 0 additions & 2 deletions src/Stores.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ export enum GridTypes {
ICON="Icon"
}

export const focusedWindow = sharedStore("main", "focusedWindow");

export const needsSGDBAPIKey = sharedStore(true, "needsSGDBAPIKey");
export const needsSteamKey = sharedStore(true, "needsSteamKey");

Expand Down
4 changes: 2 additions & 2 deletions src/lib/controllers/AppController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,9 @@ export class AppController {
const res = await http.fetch<any>(`http://api.steampowered.com/IPlayerService/GetOwnedGames/v0001/?key=${get(steamKey)}&steamid=${bUserId}&format=json&include_appinfo=true&include_played_free_games=true`);

if (res.ok) {
return Object.entries(res.data.response).map(([appid, game]: [any, any]) => {
return res.data.response.games.map((game: any) => {
return {
"appid": appid,
"appid": game.appid,
"name": game.name
}
}).sort((gameA: SteamGame, gameB: SteamGame) => gameA.name.localeCompare(gameB.name));
Expand Down
7 changes: 2 additions & 5 deletions src/lib/controllers/WindowController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@

import { WebviewWindow } from "@tauri-apps/api/window";
import { LogController } from "./LogController";
import { focusedWindow } from "../../Stores";

/**
* Controller class for managing app windows.
*/
export class WindowController {
private static mainWindow = WebviewWindow.getByLabel('main');
private static settingsWindow = WebviewWindow.getByLabel('settings');
static mainWindow = WebviewWindow.getByLabel('main');
static settingsWindow = WebviewWindow.getByLabel('settings');

/**
* Closes the window with the provided label.
Expand All @@ -47,7 +46,6 @@ export class WindowController {
LogController.log("Opening settings window.");
await this.settingsWindow.show();
await this.settingsWindow.setFocus();
focusedWindow.set("settings");
}

/**
Expand All @@ -57,6 +55,5 @@ export class WindowController {
static async closeSettingsWindow(): Promise<void> {
LogController.log("Closing settings window.");
await this.settingsWindow.hide();
focusedWindow.set("main");
}
}
22 changes: 16 additions & 6 deletions src/windows/main/Main.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,19 @@
import Grids from "../../components/core/grids/Grids.svelte";
import { AppController } from "../../lib/controllers/AppController";
import { exit } from "@tauri-apps/api/process";
import { activeUserId, focusedWindow, isOnline } from "../../Stores";
import { activeUserId, isOnline } from "../../Stores";
import { ToastController } from "../../lib/controllers/ToastController";
import { appWindow } from "@tauri-apps/api/window";
import { WindowController } from "../../lib/controllers/WindowController";
let mainFocusUnsub: any;
let isFocused = false;
onMount(async () => {
mainFocusUnsub = await WindowController.mainWindow.onFocusChanged(({ payload: focused }) => {
isFocused = focused;
});
await AppController.setup();
if (navigator.onLine) {
Expand All @@ -34,15 +42,15 @@
onDestroy(async () => {
await AppController.destroy();
if (mainFocusUnsub) mainFocusUnsub();
});
</script>

<svelte:window on:click={() => $focusedWindow = "main"} />

<div class="wrap">
<SvelteToast target="top" options={{ initial: 0, intro: { y: -64 } }} />
</div>
<main class:dim={$focusedWindow != "main"}>
<main class:dim={!isFocused}>
<Titlebar title="Steam Art Manager" />
<div class="content">
<Splitpanes>
Expand Down Expand Up @@ -70,6 +78,8 @@
align-items: center;
color: var(--font-color);
transition: opacity 0.1s ease-in-out;
}
.wrap {
Expand Down Expand Up @@ -102,6 +112,6 @@
}
.dim {
/* opacity: 0.7; */
opacity: 0.7;
}
</style>
35 changes: 25 additions & 10 deletions src/windows/settings/Settings.svelte
Original file line number Diff line number Diff line change
@@ -1,27 +1,34 @@
<script lang="ts">
import { open } from "@tauri-apps/api/shell"
import { onMount } from "svelte";
import { focusedWindow, steamGridDBKey, steamKey } from "../../Stores";
import { onDestroy, onMount } from "svelte";
import { needsSGDBAPIKey, needsSteamKey, steamGridDBKey, steamKey } from "../../Stores";
import Titlebar from "../../components/Titlebar.svelte";
import Button from "../../components/interactables/Button.svelte";
import HorizontalSpacer from "../../components/spacers/HorizontalSpacer.svelte";
import TextInput from "../../components/interactables/TextInput.svelte";
import VerticalSpacer from "../../components/spacers/VerticalSpacer.svelte";
import { LogController } from "../../lib/controllers/LogController";
import { SettingsManager } from "../../lib/utils/SettingsManager";
import { WindowController } from "../../lib/controllers/WindowController";
let settingsFocusUnsub;
let canSave = false;
let isFocused = false;
let steamGridKey = "";
let steamAPIKey = "";
async function saveSettings() {
LogController.log("Saving settings...");
$steamGridDBKey = steamGridKey;
$steamGridDBKey = steamGridKey !== "" ? steamGridKey : $steamGridDBKey;
if ($steamGridDBKey !== "" && $needsSGDBAPIKey) $needsSGDBAPIKey = false;
await SettingsManager.updateSetting("steamGridDbApiKey", steamGridKey);
$steamKey = steamAPIKey;
$steamKey = steamAPIKey !== "" ? steamAPIKey : $steamKey;
if ($steamKey !== "" && $needsSteamKey) $needsSteamKey = false;
await SettingsManager.updateSetting("steamApiKey", steamAPIKey);
LogController.log("Saved settings.");
Expand Down Expand Up @@ -68,17 +75,23 @@
}
}
onMount(() => {
onMount(async () => {
steamGridKey = $steamGridDBKey;
steamAPIKey = $steamKey;
SettingsManager.setSettingsPath();
settingsFocusUnsub = await WindowController.settingsWindow.onFocusChanged(({ payload: focused }) => {
isFocused = focused;
});
await SettingsManager.setSettingsPath();
});
</script>
<svelte:window on:click={() => $focusedWindow = "settings"} />
onDestroy(() => {
if (settingsFocusUnsub) settingsFocusUnsub();
});
</script>

<div id="settings" class:dim={$focusedWindow != "settings"}>
<div id="settings" class:dim={!isFocused}>
<Titlebar title="Settings" />
<div class="content">
<VerticalSpacer />
Expand Down Expand Up @@ -138,6 +151,8 @@
align-items: center;
color: var(--font-color);
transition: opacity 0.1s ease-in-out;
}
.content {
Expand Down Expand Up @@ -188,6 +203,6 @@
}
.dim {
/* opacity: 0.7; */
opacity: 0.7;
}
</style>

0 comments on commit efa8fb9

Please sign in to comment.