Skip to content

Commit

Permalink
EXAMPLE: send notice from backend w/ icon
Browse files Browse the repository at this point in the history
  • Loading branch information
Tnixc committed Nov 18, 2024
1 parent 20910fe commit a572266
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 5 deletions.
9 changes: 9 additions & 0 deletions src/main/lib/window/resizer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { orDefault } from "@shared/lib/rust-types/Optional";
import { Storage } from "@main/lib/storage/Storage";
import { BrowserWindow } from "electron";
import { Router } from "@main/lib/route-pass/Router";

/**
* Save window dimensions so that it can be opened the same size it was closed
Expand All @@ -13,6 +14,14 @@ export default function trackBounds(window: BrowserWindow): void {
const bounds = window.getBounds();
settings.write("window.width", bounds.width);
settings.write("window.height", bounds.height);

// Send a notice about the window resize
Router.dispatch(window, "notify", {
variant: "neutral",
title: "Window Resized",
description: `New dimensions: ${bounds.width}x${bounds.height}`,
icon: "maximize-icon"
});
});

window.on("unmaximize", () => {
Expand Down
22 changes: 19 additions & 3 deletions src/renderer/src/components/notice/NoticeContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { TokenNamespace } from "@shared/lib/tungsten/token";
import Notice, { IconNoticeType } from "./Notice";
import { For, createSignal } from "solid-js";
import { createStore } from "solid-js/store";

import { MaximizeIcon, XIcon } from "lucide-solid";
import { NoticeTypeIconMap } from "@shared/types/common.types";
const [notices, setNotices] = createStore<IconNoticeType[]>([]);
const namespace = new TokenNamespace();
const [isPaused, setIsPaused] = createSignal(false);
Expand Down Expand Up @@ -32,8 +33,23 @@ function hideNotice(id: string | undefined): Result<void, string> {

export { notices, isPaused, setIsPaused };

window.api.listen("notify", (n) => {
addNotice(n);
window.api.listen("notify", (n: NoticeTypeIconMap) => {
const noticeParams: IconNoticeType = {
id: n.id,
variant: n.variant,
title: n.title,
description: n.description,
};

switch (n.icon) {
case "maximize-icon":
noticeParams.icon = <MaximizeIcon size={20} />;
break;
case "X-icon":
noticeParams.icon = <XIcon size={20} />;
}

addNotice(noticeParams);
});

const NoticeContainer = () => {
Expand Down
5 changes: 5 additions & 0 deletions src/shared/types/common.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,3 +243,8 @@ export type NoticeType = {
title?: string;
description?: string;
};

export type NoticeTypeIconMap = NoticeType & {
icon?: "maximize-icon" | "X-icon";
};

4 changes: 2 additions & 2 deletions src/shared/types/router.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import type {
Song,
SongsQueryPayload,
LoadingSceneUpdate,
NoticeType,
NoticeTypeIconMap,
Scenes,
} from "./common.types";
import type { SearchQuery } from "./search-parser.types";
Expand Down Expand Up @@ -93,5 +93,5 @@ export type ListenAPI = {

"window::maximizeChange": (maximized: boolean) => void;

notify: (notice: NoticeType) => void;
notify: (notice: NoticeTypeIconMap) => void;
};

0 comments on commit a572266

Please sign in to comment.