Skip to content

Commit

Permalink
feat: add rounded corners (#307)
Browse files Browse the repository at this point in the history
* feat: add rounded corners

* Update src/renderer/app/index.tsx

Co-authored-by: Nicolas St-Amour <[email protected]>

* fix: remove OS-specific rounded corner defaults

---------

Co-authored-by: Nicolas St-Amour <[email protected]>
  • Loading branch information
marriaga158 and stamoun authored Jan 20, 2024
1 parent 78d2a9f commit 862a498
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const MAX_BAR_THICKNESS = 20;
export const MIN_FONT_SIZE = 6;
export const MAX_FONT_SIZE = 32;
export const TRACK_INFO_GAP = { X: 10, Y: 10 };
export const MAX_CORNER_RADIUS = 20;

export const MIN_SKIP_SONG_DELAY = 5;
export const MAX_SKIP_SONG_DELAY = 60;
Expand Down
2 changes: 1 addition & 1 deletion src/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ const MAIN_WINDOW_OPTIONS: BrowserWindowConstructorOptions = {
nodeIntegration: true,
contextIsolation: false,
},
backgroundColor: '#000000',
backgroundColor: 'rgba(0,0,0,0)',
roundedCorners: false,
};

Expand Down
2 changes: 2 additions & 0 deletions src/models/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export interface Settings {
trackInfoBackgroundColor: string;
trackInfoBackgroundOpacity: number;
showFreemiumWarning: boolean;
cornerRadius: number;
}

export const DEFAULT_SETTINGS: Settings = {
Expand Down Expand Up @@ -64,4 +65,5 @@ export const DEFAULT_SETTINGS: Settings = {
trackInfoBackgroundColor: '#000000',
trackInfoBackgroundOpacity: 50,
showFreemiumWarning: true,
cornerRadius: 0,
};
8 changes: 6 additions & 2 deletions src/renderer/app/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable no-console */
import { Display, ipcRenderer } from 'electron';
import React, { FunctionComponent, useCallback, useEffect, useState } from 'react';
import React, { FunctionComponent, useCallback, useEffect, useMemo, useState } from 'react';
import styled from 'styled-components';

import { IpcMessage, WindowName } from '../../constants';
Expand Down Expand Up @@ -79,6 +79,7 @@ export const App: FunctionComponent = () => {
const { state, dispatch } = useSettings();
const { state: currentlyPlaying, dispatch: currentlyPlayingDispatch } = useCurrentlyPlaying();
const { accessToken, refreshToken, visualizationId, visualizationType } = state || DEFAULT_SETTINGS;
const { cornerRadius } = useMemo(() => state, [state]);

const updateTokens = useCallback(
async (data: AuthData) => {
Expand Down Expand Up @@ -274,7 +275,10 @@ export const App: FunctionComponent = () => {
);

return (
<VisibleUi id="visible-ui" className="click-on">
<VisibleUi
id="visible-ui"
className="click-on"
style={cornerRadius ? { borderRadius: `${cornerRadius}%`, overflow: 'hidden' } : {}}>
{shouldShowSettings && (
<WindowPortal onUnload={() => setShouldShowSettings(false)} name={WindowName.Settings}>
<SettingsWindow
Expand Down
17 changes: 16 additions & 1 deletion src/renderer/windows/settings/window-settings.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { FunctionComponent } from 'react';
import { useFormContext } from 'react-hook-form';

import { MAX_BAR_THICKNESS } from '../../../constants';
import { MAX_BAR_THICKNESS, MAX_CORNER_RADIUS } from '../../../constants';
import { DEFAULT_SETTINGS, Settings } from '../../../models/settings';
import {
ColorInput,
Expand All @@ -20,6 +20,7 @@ export const WindowSettings: FunctionComponent = () => {
const { register, watch } = useFormContext<Settings>();

const barThicknessWatch = watch('barThickness');
const cornerRadiusWatch = watch('cornerRadius');

return (
<FormGroup>
Expand Down Expand Up @@ -72,6 +73,20 @@ export const WindowSettings: FunctionComponent = () => {
<ColorInput {...register('barColor')} />
</Label>
</Row>
<Row>
<Label>
Border Radius
<Slider
type="range"
min={0}
max={MAX_CORNER_RADIUS}
step={1}
defaultValue={DEFAULT_SETTINGS.cornerRadius}
{...register('cornerRadius', { required: true, valueAsNumber: true })}
/>
<RangeValue>{cornerRadiusWatch}</RangeValue>
</Label>
</Row>
</FieldSet>
</FormGroup>
);
Expand Down

0 comments on commit 862a498

Please sign in to comment.