Skip to content

Commit

Permalink
feat(view): add option to show in imperial units
Browse files Browse the repository at this point in the history
  • Loading branch information
MauriceNino committed Jun 15, 2022
1 parent ba84d34 commit d4b1f69
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions .github/CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ in the [INSTALL.md](./INSTALL.md).
| `DASHDOT_PORT` | The port where the express backend is running (the backend serves the frontend, so it is the same port for both) | number | `3001` |
| `DASHDOT_WIDGET_LIST` | Change the order of the elements in the list, to change the position on the page, or remove an item from the list, to remove it from the page (The available options are: `os`, `cpu`, `storage`, `ram`, `network`) | string | `os,cpu,storage,ram,network` |
| `DASHDOT_ACCEPT_OOKLA_EULA` | Use the newer and more accurate `speedtest` tool from Ookla, instead of the old `speedtest-cli` for your speedtests. When passing this flag, you accept Ooklas [EULA](https://www.speedtest.net/about/eula), [TERMS](https://www.speedtest.net/about/terms) and [PRIVACY](https://www.speedtest.net/about/privacy) | boolean | `false` |
| `DASHDOT_USE_IMPERIAL` | Shows any units in the imperial system, instead of the default metric | boolean | `false` |

<!-- markdownlint-enable -->

Expand Down
1 change: 1 addition & 0 deletions apps/api/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const CONFIG: Config = {
penv('WIDGET_LIST') ?? 'os,cpu,storage,ram,network'
) as any[],
accept_ookla_eula: penv('ACCEPT_OOKLA_EULA') === 'true',
use_imperial: penv('USE_IMPERIAL') === 'true',

disable_host: penv('DISABLE_HOST') === 'true',
os_label_list: lst(penv('OS_LABEL_LIST') ?? 'os,arch,up_since') as any[],
Expand Down
3 changes: 3 additions & 0 deletions apps/view/src/utils/calculations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,6 @@ export const bytePrettyPrint = (byte: number): string => {
? `${(byte / 1024).toFixed(1)} KB`
: `${byte.toFixed(1)} B`;
};

export const celsiusToFahrenheit = (celsius: number): number =>
(celsius * 9) / 5 + 32;
7 changes: 4 additions & 3 deletions apps/view/src/widgets/cpu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { HardwareInfoContainer } from '../components/hardware-info-container';
import { ThemedText } from '../components/text';
import { WidgetSwitch } from '../components/widget-switch';
import { useSetting } from '../services/settings';
import { celsiusToFahrenheit } from '../utils/calculations';
import { toInfoTable } from '../utils/format';

const containerVariants = {
Expand Down Expand Up @@ -197,10 +198,10 @@ export const CpuWidget: FC<CpuWidgetProps> = ({ load, data, config }) => {
{config.enable_cpu_temps && !multiCore && chart.length > 1 && (
<TempContainer>
{`Ø: ${
(multiCore
? latestLoad[chartI].temp
(config.use_imperial
? celsiusToFahrenheit(averageTemp).toFixed(1)
: averageTemp.toFixed(1)) || '?'
} °C`}
} ${config.use_imperial ? '°F' : '°C'}`}
</TempContainer>
)}

Expand Down
1 change: 1 addition & 0 deletions libs/common/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export type Config = {
port: number;
widget_list: ('os' | 'cpu' | 'storage' | 'ram' | 'network')[];
accept_ookla_eula: boolean;
use_imperial: boolean;

// OS Widget
disable_host: boolean;
Expand Down

0 comments on commit d4b1f69

Please sign in to comment.