Skip to content

Commit

Permalink
feat: bigger config rows; leave on short and long press; micro configs
Browse files Browse the repository at this point in the history
  • Loading branch information
koriwi committed Aug 17, 2022
1 parent 04b6deb commit 080b389
Show file tree
Hide file tree
Showing 25 changed files with 193 additions and 118 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ npm-debug.log*
yarn-debug.log*
yarn-error.log*

.eslintcache
.eslintcache

.vscode/arduino.json
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"name": "freedeck-configurator",
"version": "2.7.15",
"configFileVersion": "1.2.0",
"configFileVersion": "1.3.0",
"minFWVersion": "2.7.0",
"private": true,
"homepage": "./",
"type": "commonjs",
Expand Down
13 changes: 9 additions & 4 deletions src/containers/DeveloperSettings.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { invoke } from "@tauri-apps/api";
import React, { useContext } from "react";
import {invoke} from "@tauri-apps/api"

import { FDButton } from "../lib/components/Button";
import { Label } from "../lib/components/LabelValue";
import { Row } from "../lib/components/Row";
Expand All @@ -19,10 +20,10 @@ export const DeveloperSettings: React.FC = () => {
<TextInput onChange={(val) => serialApi?.writeToScreen(val)} />
</Row>
<Row>
<Label>Get current page:</Label>
<Label>Get has json:</Label>
<FDButton
onClick={() =>
serialApi?.getCurrentPage().then((a) =>
serialApi?.getHasJson().then((a) =>
appDispatch.openAlert({
text: a.toString(),
title: "Debug message",
Expand All @@ -44,7 +45,11 @@ export const DeveloperSettings: React.FC = () => {
<Row>
<Label>call get_current_window</Label>
<FDButton
onClick={() => invoke<string>("get_current_window").then(value => appDispatch.openAlert({text: value, title: "debug"}))}
onClick={() =>
invoke<string>("get_current_window").then((value) =>
appDispatch.openAlert({ text: value, title: "debug" })
)
}
>
invoke
</FDButton>
Expand Down
10 changes: 10 additions & 0 deletions src/containers/Device.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Divider } from "../lib/components/Divider";
import { Label, Value } from "../lib/components/LabelValue";
import { Row } from "../lib/components/Row";
import { FDSelect } from "../lib/components/SelectInput";
import { FDSwitch } from "../lib/components/Switch";
import { TitleBox } from "../lib/components/Title";
import { AppStateContext } from "../states/appState";
import {
Expand Down Expand Up @@ -96,6 +97,15 @@ export const Device: React.FC<{}> = () => {
/>
</div>
</Row>
<Row>
<Label hint="Disable this to massively reduce save times but you will not be able to 'load from freedeck'">
Save JSON:
</Label>
<FDSwitch
onChange={(val) => configDispatch.setSaveJson(val)}
value={configState.saveJson}
/>
</Row>
</TitleBox>

<Divider />
Expand Down
39 changes: 19 additions & 20 deletions src/containers/DisplayButton/ButtonSettings/Action.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,26 +107,25 @@ export const Action: React.FC<{
setValues={(values) => setValues(values)}
/>
)}
{buttonSettings.mode !== EAction.text &&
buttonSettings.mode !== EAction.changePage &&
primary && (
<LeavePage
primary={primary}
value={
configState.pages.byId[pageId].displayButtons[buttonIndex]
.button.leavePage
}
pages={configState.pages}
setValue={(value) =>
configDispatch.setLeavePage({
buttonIndex,
pageId,
targetPageId: value.pageId,
enabled: value.enabled,
})
}
/>
)}
{buttonSettings.mode !== EAction.changePage && (
<LeavePage
primary={primary}
value={
configState.pages.byId[pageId].displayButtons[buttonIndex]
.button[primary ? "primary" : "secondary"].leavePage
}
pages={configState.pages}
setValue={(value) =>
configDispatch.setLeavePage({
buttonIndex,
pageId,
targetPageId: value.pageId,
enabled: value.enabled,
primary: primary,
})
}
/>
)}
</>
</TitleBox>
</div>
Expand Down
8 changes: 2 additions & 6 deletions src/containers/DisplayButton/ButtonSettings/Hotkeys.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { FDButton } from "../../../lib/components/Button";
import { Label } from "../../../lib/components/LabelValue";
import { Row } from "../../../lib/components/Row";
import { FDSelect } from "../../../lib/components/SelectInput";
import { ROW_SIZE } from "../../../lib/configFile/consts";
import { useTranslateKeyboardLayout } from "../../../lib/localisation/keyboard";

const HotkeyKeys: React.FC<{
Expand Down Expand Up @@ -43,7 +44,7 @@ export const Hotkeys: React.FC<{
setValues: (values: ButtonSetting["values"]) => void;
}> = ({ setValues, values }) => {
const setKeys = (newValues: number[]) =>
newValues.length < 7 &&
newValues.length <= ROW_SIZE / 2 - 3 &&
setValues({
...values,
[EAction.hotkeys]: newValues,
Expand All @@ -54,11 +55,6 @@ export const Hotkeys: React.FC<{
(key) => keys[key]?.js === e.nativeEvent.code
);
if (!key) return;
if (
!!values[EAction.hotkeys].find((k) => k === keys[key]?.hid) &&
keys[key]!.hid >= 0xe0
)
return;
//ignore backspace
if (keys[key]!.hid === 42 && values[EAction.hotkeys].length > 0) {
setKeys([
Expand Down
8 changes: 4 additions & 4 deletions src/containers/DisplayButton/ButtonSettings/LeavePage.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import React from "react";

import { Button, Pages } from "../../../generated";
import { ButtonSetting, Pages } from "../../../generated";
import { Label } from "../../../lib/components/LabelValue";
import { Row } from "../../../lib/components/Row";
import { FDSelect } from "../../../lib/components/SelectInput";
import { FDSwitch } from "../../../lib/components/Switch";
import { getPageName } from "../../../lib/misc/util";

export const LeavePage: React.FC<{
value: Button["leavePage"];
value: ButtonSetting["leavePage"];
pages: Pages;
primary: boolean;
setValue: (value: Button["leavePage"]) => void;
setValue: (value: ButtonSetting["leavePage"]) => void;
}> = ({ value, pages, setValue, primary }) => {
const startPage = pages.sorted[0];
return (
<>
{pages.sorted.length && primary ? (
{pages.sorted.length ? (
<>
<Row>
<Label>Change Page after press</Label>
Expand Down
16 changes: 7 additions & 9 deletions src/containers/DisplayButton/ButtonSettings/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,13 @@ export const ButtonSettingsContainer: React.FC<{
/>
</div>
<div className="relative flex flex-col">
{!button.leavePage.enabled && (
<Action
primary={false}
title="Long press"
pageId={pageId}
buttonIndex={displayIndex}
buttonSettings={button.secondary}
/>
)}
<Action
primary={false}
title="Long press"
pageId={pageId}
buttonIndex={displayIndex}
buttonSettings={button.secondary}
/>
</div>
</div>
{(button.primary.mode === "hotkeys" ||
Expand Down
34 changes: 28 additions & 6 deletions src/containers/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { createConfigBuffer } from "../lib/configFile/createBuffer";
import { loadConfigFile } from "../lib/configFile/loadConfigFile";
import { download } from "../lib/file/download";
import { isMacOS } from "../lib/misc/util";
import { AppStateContext } from "../states/appState";
import { AppDispatchContext, AppStateContext } from "../states/appState";
import {
ConfigDispatchContext,
ConfigStateContext,
Expand All @@ -26,6 +26,8 @@ import { LoginLogoutButtons } from "./LoginButton";

export const Header: React.FC<{}> = () => {
const configState = useContext(ConfigStateContext);
const { hasJson } = useContext(AppStateContext);
const { setHasJson, openAlert } = useContext(AppDispatchContext);
const { pages } = configState;
const { setState } = useContext(ConfigDispatchContext);
const { serialApi, ctrlDown, availablePorts, connectedPortIndex } =
Expand All @@ -35,7 +37,7 @@ export const Header: React.FC<{}> = () => {
const loadConfigRef = useRef<HTMLInputElement | null>(null);
const saveConfigFile = () => {
if (Object.keys(pages.byId).length === 0) return;
const completeBuffer = createConfigBuffer(configState);
const completeBuffer = createConfigBuffer(configState, true);

completeBuffer && download(completeBuffer);
};
Expand Down Expand Up @@ -85,12 +87,24 @@ export const Header: React.FC<{}> = () => {
<FDButton
prefix={<UploadIcon className={iconSize} />}
size={3}
disabled={!hasJson}
title={
hasJson
? "Load config over serial"
: "Cannot load config. FreeDeck stores no JSON. Change it in Settings -> Device"
}
onClick={() =>
serialApi!
.readConfigFromSerial((rec, size) =>
setProgress(rec / size)
)
.then((data) => loadConfigFile(data, setState))
.catch((e) =>
openAlert({
title: "Attention: Error",
text: e.message,
})
)
}
>
Load from FreeDeck
Expand All @@ -99,10 +113,18 @@ export const Header: React.FC<{}> = () => {
prefix={<SaveIcon className={iconSize} />}
size={3}
onClick={async () =>
serialApi!.writeConfigOverSerial(
createConfigBuffer(configState),
(rec, size) => setProgress(rec / size)
)
serialApi!
.writeConfigOverSerial(
createConfigBuffer(configState, false),
(rec, size) => setProgress(rec / size)
)
.then(() => setHasJson(configState.saveJson))
.catch((e) =>
openAlert({
title: "Attention: Error",
text: e.message,
})
)
}
>
Save to FreeDeck
Expand Down
3 changes: 2 additions & 1 deletion src/definitions/defaultPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { EAction, EImageMode, ETextPosition } from "./modes";

const createDefaultButton: () => Button = () => {
const button: Button = {
leavePage: { enabled: false },
primary: {
mode: EAction.noop,
values: {
Expand All @@ -20,6 +19,7 @@ const createDefaultButton: () => Button = () => {
[EAction.special_keys]: 0,
[EAction.text]: "",
},
leavePage: { enabled: false },
},
secondary: {
mode: EAction.noop,
Expand All @@ -30,6 +30,7 @@ const createDefaultButton: () => Button = () => {
[EAction.special_keys]: 0,
[EAction.text]: "",
},
leavePage: { enabled: false },
},
};
return button;
Expand Down
2 changes: 1 addition & 1 deletion src/generated/button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
*/

export interface Button {
leavePage: LeavePage;
primary: ButtonSetting;
secondary: ButtonSetting;
}

export interface ButtonSetting {
leavePage: LeavePage;
mode: 'changePage' | 'hotkeys' | 'noop' | 'settings' | 'special_keys' | 'text';
values: ButtonValues;
}
Expand Down
1 change: 1 addition & 0 deletions src/generated/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export interface Config {
oledSpeed: number;
pages: Pages;
preChargePeriod: number;
saveJson: boolean;
screenSaverTimeout: number;
width: number;
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const FDButton = ({

return (
<div
onClick={onClick}
onClick={disabled ? () => {} : onClick}
title={title}
className={`cursor-pointer inline-flex items-center text-lg font-normal tracking-wider rounded-md select-none min-w-0 ${sizeClasses} ${typeClasses} ${className}`}
>
Expand Down
1 change: 1 addition & 0 deletions src/lib/configFile/consts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const ROW_SIZE = 128;
Loading

0 comments on commit 080b389

Please sign in to comment.