Skip to content

Commit 5b949fe

Browse files
committed
feat: add common layout types
1 parent 1c7e7dc commit 5b949fe

File tree

4 files changed

+94
-92
lines changed

4 files changed

+94
-92
lines changed

electron/common/layout/types.ts

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
export interface Layout {
2+
window: WindowLayout;
3+
streams: Array<StreamLayout>;
4+
}
5+
6+
/**
7+
* Layout configuration for the app window.
8+
*/
9+
export interface WindowLayout {
10+
x: number;
11+
y: number;
12+
width: number;
13+
height: number;
14+
}
15+
16+
/**
17+
* Layout configuration for a game stream.
18+
*/
19+
export interface StreamLayout {
20+
/**
21+
* Game-specific identifier for the stream.
22+
* For example, "percWindow" for the active spells stream.
23+
*/
24+
id: string;
25+
/**
26+
* Title to display for the stream in the app.
27+
*/
28+
title: string;
29+
/**
30+
* Whether the stream is displayed in the app.
31+
* When false then this stream's content can be redirected to
32+
* another stream window using the `whenHiddenStreamToId` property.
33+
*/
34+
visible: boolean;
35+
/**
36+
* The x-coordinate of the stream window, in pixels.
37+
* Relative to where the streams are displayed within the app.
38+
* This is not the absolute position on the monitor screen.
39+
*/
40+
x: number;
41+
/**
42+
* The y-coordinate of the stream window, in pixels.
43+
* Relative to where the streams are displayed within the app.
44+
* This is not the absolute position on the monitor screen.
45+
*/
46+
y: number;
47+
/**
48+
* The width of the stream window, in pixels.
49+
*/
50+
width: number;
51+
/**
52+
* The height of the stream window, in pixels.
53+
*/
54+
height: number;
55+
/**
56+
* The font family to use for the stream content.
57+
* Example: 'Verdana' or 'Courier New'.
58+
*/
59+
textFont: string;
60+
/**
61+
* The font size to use for the stream content, in pixels.
62+
*/
63+
textSize: number;
64+
/**
65+
* The color of the text in the stream content.
66+
*/
67+
foregroundColor: string;
68+
/**
69+
* The color of the background in the stream content.
70+
*/
71+
backgroundColor: string;
72+
/**
73+
* When this stream is not visible, redirect its content to another stream.
74+
* If that stream is also not visible, then it continues to be redirected
75+
* until either a visible stream in the chain is found or not.
76+
*
77+
* Example Scenario
78+
* ----------------
79+
* When StreamA is hidden it redirects to StreamB.
80+
* When StreamB is hidden it redirects to STreamC.
81+
* When StreamC is hidden it does not redirect anywhere.
82+
*
83+
* When all streams are visible then their content is displayed as normal.
84+
* When StreamA is hidden, its content is redirected to StreamB.
85+
* When StreamB is also hidden, both StreamA and StreamB redirect to StreamC.
86+
* When StreamC is also hidden, no content is displayed.
87+
*/
88+
whenHiddenStreamToId: string;
89+
}

electron/main/layout/__tests__/layout-service.test.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
2+
import type { Layout } from '../../../common/layout/types.js';
23
import { LayoutServiceImpl } from '../layout.service.js';
3-
import type { Layout, LayoutService } from '../types.js';
4+
import type { LayoutService } from '../types.js';
45

56
type FsExtraModule = typeof import('fs-extra');
67
type ElectronModule = typeof import('electron');

electron/main/layout/layout.service.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { app } from 'electron';
22
import path from 'node:path';
33
import fs from 'fs-extra';
4+
import type { Layout } from '../../common/layout/types.js';
45
import type { Maybe } from '../../common/types.js';
56
import { logger } from './logger.js';
6-
import type { Layout, LayoutService } from './types.js';
7+
import type { LayoutService } from './types.js';
78

89
export class LayoutServiceImpl implements LayoutService {
910
public async get(name: string): Promise<Maybe<Layout>> {

electron/main/layout/types.ts

+1-90
Original file line numberDiff line numberDiff line change
@@ -1,95 +1,6 @@
1+
import type { Layout } from '../../common/layout/types.js';
12
import type { Maybe } from '../../common/types.js';
23

3-
export interface Layout {
4-
window: WindowLayout;
5-
streams: Array<StreamLayout>;
6-
}
7-
8-
/**
9-
* Layout configuration for the app window.
10-
*/
11-
export interface WindowLayout {
12-
x: number;
13-
y: number;
14-
width: number;
15-
height: number;
16-
}
17-
18-
/**
19-
* Layout configuration for a game stream.
20-
*/
21-
export interface StreamLayout {
22-
/**
23-
* Game-specific identifier for the stream.
24-
* For example, "percWindow" for the active spells stream.
25-
*/
26-
id: string;
27-
/**
28-
* Title to display for the stream in the app.
29-
*/
30-
title: string;
31-
/**
32-
* Whether the stream is displayed in the app.
33-
* When false then this stream's content can be redirected to
34-
* another stream window using the `whenHiddenStreamToId` property.
35-
*/
36-
visible: boolean;
37-
/**
38-
* The x-coordinate of the stream window, in pixels.
39-
* Relative to where the streams are displayed within the app.
40-
* This is not the absolute position on the monitor screen.
41-
*/
42-
x: number;
43-
/**
44-
* The y-coordinate of the stream window, in pixels.
45-
* Relative to where the streams are displayed within the app.
46-
* This is not the absolute position on the monitor screen.
47-
*/
48-
y: number;
49-
/**
50-
* The width of the stream window, in pixels.
51-
*/
52-
width: number;
53-
/**
54-
* The height of the stream window, in pixels.
55-
*/
56-
height: number;
57-
/**
58-
* The font family to use for the stream content.
59-
* Example: 'Verdana' or 'Courier New'.
60-
*/
61-
textFont: string;
62-
/**
63-
* The font size to use for the stream content, in pixels.
64-
*/
65-
textSize: number;
66-
/**
67-
* The color of the text in the stream content.
68-
*/
69-
foregroundColor: string;
70-
/**
71-
* The color of the background in the stream content.
72-
*/
73-
backgroundColor: string;
74-
/**
75-
* When this stream is not visible, redirect its content to another stream.
76-
* If that stream is also not visible, then it continues to be redirected
77-
* until either a visible stream in the chain is found or not.
78-
*
79-
* Example Scenario
80-
* ----------------
81-
* When StreamA is hidden it redirects to StreamB.
82-
* When StreamB is hidden it redirects to STreamC.
83-
* When StreamC is hidden it does not redirect anywhere.
84-
*
85-
* When all streams are visible then their content is displayed as normal.
86-
* When StreamA is hidden, its content is redirected to StreamB.
87-
* When StreamB is also hidden, both StreamA and StreamB redirect to StreamC.
88-
* When StreamC is also hidden, no content is displayed.
89-
*/
90-
whenHiddenStreamToId: string;
91-
}
92-
934
export interface LayoutService {
945
/**
956
* Gets a layout by name.

0 commit comments

Comments
 (0)