Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Christoffer Engman committed Oct 7, 2023
1 parent 1d7a213 commit fd1f069
Show file tree
Hide file tree
Showing 19 changed files with 100 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ i18n
supportedLngs: whitelist.langs
});

window.api.i18nextElectronBackend.onLanguageChange((args) => {
i18n.changeLanguage(args.lng, (error, _t) => {
window.api.i18nextElectronBackend.onLanguageChange((args: any) => {
i18n.changeLanguage(args.lng, (error: any, _t: any) => {
if (error) {
console.error(error);
}
});
});

module.exports = i18n;
// module.exports = i18n;
export default i18n
24 changes: 15 additions & 9 deletions app/src/components/Pad.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
// @ts-nocheck
import { Paper, styled } from '@material-ui/core'
import { Paper, rgbToHex, styled } from '@material-ui/core'
import { CHANNELS } from 'Constants/ipc'
import { changeColor, setPressed } from 'Redux/components/pad/padActions'
import { ColorOff, randomRGB } from 'Utils/color'
import React, { useEffect, useState } from 'react'
import { useDispatch, useSelector } from 'react-redux'
import { ColorOff, randomRGB, rgbToHex } from '../utils/color'
import { changeColor, setPressed } from '../redux/components/pad/padActions'
import { CHANNELS } from '../constants/ipc'

const Pad = ({ x, y }) => {
type Props = { x: number, y: number }

const Pad = ({ x, y }: Props) => {
const button = parseInt(`${y}${x}`)

const dispatch = useDispatch()
const [isMouseOver, setMouseOver] = useState(false)
const { isPressed, color } = useSelector((state) => state.pad.buttons[button])
const { isPressed, color } = useSelector((state: any) => state.pad.buttons[button])

useEffect(() => {
console.log("MOUNTED => ", button)
return () => console.log("DISMOUNTED!!!!")
}, [])

useEffect(
() => window.api.send(CHANNELS.LP.PAD_COLOR, { button, color }),
Expand All @@ -21,8 +27,8 @@ const Pad = ({ x, y }) => {
useEffect(() => {
console.log('INVOKE PRESSED =>', button, 'STATE: ', isPressed)
if (isPressed) dispatch(changeColor(button, randomRGB()))
if (!isPressed)
dispatch(changeColor(button, ColorOff))
// if (!isPressed)
// dispatch(changeColor(button, ColorOff))
// setTimeout(() => dispatch(changeColor(button, ColorOff)), 1000)
}, [isPressed])

Expand Down
8 changes: 3 additions & 5 deletions app/src/components/Receiver.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { useDispatch } from 'react-redux'
import { randomRGB } from '../utils/color'
import { changeColor, setPressed } from '../redux/components/pad/padActions'
import { BUTTON_DOWN } from 'Constants/events'
import { setPressed } from 'Redux/components/pad/padActions'
import React, { useEffect } from 'react'
import { CHANNELS } from '../constants/ipc'
import { BUTTON_DOWN } from '../constants/events'
import { useDispatch } from 'react-redux'

const Receiver = () => {
const dispatch = useDispatch()
Expand Down
3 changes: 1 addition & 2 deletions app/src/components/Test.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
// @ts-nocheck
import React from "react"
import { useSelector } from "react-redux"

const TestComponent = () => {
const buttons = useSelector((state) => state.pad.buttons)
const buttons = useSelector((state: any) => state.pad.buttons)

return (
<>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import React from 'react'

type Props = { id: any }

class SubItem extends React.Component {
constructor(props) {
constructor(props: Props) {
super(props)
}

Expand All @@ -14,7 +16,7 @@ class SubItem extends React.Component {
// of id "alert" is selected
window.api.contextMenu.onReceive(
'softAlert',
function (args) {
function (args: any) {
console.log(
`This alert was brought to you by secure-electron-context-menu by ${args.attributes.name}`
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
const ROUTES = {
"HOME": "/",
"LAUNCHPAD": "/launchpad"
}

export default ROUTES
20 changes: 10 additions & 10 deletions app/src/core/nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
} from 'secure-electron-license-keys'

class Nav extends React.Component {
constructor(props) {
constructor(props: any) {
super(props)

this.state = {
Expand Down Expand Up @@ -36,7 +36,7 @@ class Nav extends React.Component {
// validated by the main process
const _ = this

window.api.licenseKeys.onReceive(validateLicenseResponse, function (data) {
window.api.licenseKeys.onReceive(validateLicenseResponse, function (data: any) {
// If the license key/data is valid
if (data.success) {
// Here you would compare data.appVersion to
Expand All @@ -59,13 +59,13 @@ class Nav extends React.Component {
})
}

toggleMenu(_event) {
toggleMenu(_event: any) {
this.setState({
mobileMenuActive: !this.state.mobileMenuActive,
})
}

toggleLicenseModal(_event) {
toggleLicenseModal(_event: any) {
const previous = this.state.licenseModalActive

// Only send license request if the modal
Expand All @@ -82,7 +82,7 @@ class Nav extends React.Component {
// Using a custom method to navigate because we
// need to close the mobile menu if we navigate to
// another page
navigate(url) {
navigate(url: any) {
this.setState(
{
mobileMenuActive: false,
Expand Down Expand Up @@ -198,17 +198,17 @@ class Nav extends React.Component {
Home
</a>

<a
{/* <a
className="navbar-item"
onClick={() => this.navigate(ROUTES.ABOUT)}>
About
</a>
</a> */}

<div className="navbar-item has-dropdown is-hoverable">
<a className="navbar-link">Sample pages</a>

<div className="navbar-dropdown">
<a
{/* <a
className="navbar-item"
onClick={() => this.navigate(ROUTES.MOTD)}>
Using the Electron store
Expand All @@ -232,7 +232,7 @@ class Nav extends React.Component {
className="navbar-item"
onClick={() => this.navigate(ROUTES.IMAGE)}>
Sample image loaded
</a>
</a> */}
</div>
</div>
</div>
Expand All @@ -254,7 +254,7 @@ class Nav extends React.Component {
}
}

function WithNavigate(props) {
function WithNavigate(props: any) {
const navigate = useNavigate()
return <Nav {...props} navigate={navigate} />
}
Expand Down
3 changes: 1 addition & 2 deletions app/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
// @ts-nocheck
import React, { Suspense } from 'react'
import { createRoot } from 'react-dom/client'
import i18n from 'I18n/i18n.config'
import { I18nextProvider } from 'react-i18next'
import Root from 'Core/root'
import { store, history } from 'Redux/store/store'
import 'bulma/css/bulma.css'
import Receiver from './components/Receiver'
import Receiver from 'Components/Receiver'

const container = document.getElementById('target')
const root = createRoot(container)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react'
import SubItem from 'Components/subitem/subitem'

class ContextMenu extends React.Component {
constructor(props) {
constructor(props: any) {
super(props)

this.state = {
Expand Down
4 changes: 1 addition & 3 deletions app/src/pages/home/home.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { Link } from 'react-router-dom'
import React from 'react'
import { Button } from '@material-ui/core'
import Test from '../../components/Test'
import { Link } from 'react-router-dom'

const Home = () => {
return (
Expand Down
15 changes: 7 additions & 8 deletions app/src/pages/launchpad/launchpad.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
// @ts-nocheck
import { Grid } from '@material-ui/core'
import { changeColor, setPressed } from 'Redux/components/pad/padSlice'
import Pad from 'Components/Pad'
import Test from 'Components/Test'
import { CHANNELS } from 'Constants/ipc'
import React from 'react'
import { useDispatch } from 'react-redux'
import Pad from '../../components/Pad'
import Test from '../../components/Test'
import { CHANNELS } from '../../constants/ipc'
import { randomRGB } from '../../utils/color'


const createGrid = () => {
const rows = []
Expand All @@ -22,7 +19,9 @@ const createGrid = () => {
return rows
}

const Launchpad = (props) => {
type Props = any

const Launchpad = (props: Props) => {
// @ts-ignore
window.api.send(CHANNELS.LP.CLEAR)

Expand Down
9 changes: 4 additions & 5 deletions app/src/redux/components/pad/padReducer.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// @ts-nocheck
import { createSlice } from '@reduxjs/toolkit'
import { getAllButtons } from '../../../utils'
import { ColorOff } from '../../../utils/color'
import { ColorOff } from 'Utils/color'
import { getAllButtons } from 'Utils/index'
import { NAME } from './padTypes'

const padReducer = createSlice({
Expand All @@ -17,11 +16,11 @@ const padReducer = createSlice({
isPressed: false,
},
reducers: {
changeColor(state, action) {
changeColor(state: any, action) {
const { button, color } = action.payload
state.buttons[button].color = color
},
setPressed(state, action) {
setPressed(state: any, action) {
const { button, pressed } = action.payload
state.buttons[button].isPressed = pressed
console.log(state, action)
Expand Down
2 changes: 1 addition & 1 deletion app/src/redux/store/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { configureStore, getDefaultMiddleware } from '@reduxjs/toolkit'
import { createHashHistory } from 'history'
import { createReduxHistoryContext } from 'redux-first-history'
import logger from 'redux-logger'
import padReducer from '../components/pad/padReducer'
import padReducer from 'Redux/components/pad/padReducer'

const { routerMiddleware, createReduxHistory, routerReducer } =
createReduxHistoryContext({
Expand Down
10 changes: 10 additions & 0 deletions app/src/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export {}

declare global {
interface Window {
api: {
send: (channel: string, data: any) => void
[key: string]: any
}
}
}
4 changes: 4 additions & 0 deletions app/src/types/secure-electron-license-keys.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
declare module 'secure-electron-license-keys' {
export const validateLicenseRequest = 'ValidateLicense-Request'
export const validateLicenseResponse = 'ValidateLicense-Response'
}
19 changes: 19 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
"@babel/preset-typescript": "^7.18.6",
"@doyensec/electronegativity": "^1.9.1",
"@google-cloud/translate": "^7.0.0",
"@types/loadable__component": "^5.13.5",
"@types/react": "^18.0.15",
"@types/react-dom": "^18.0.6",
"@types/redux-logger": "^3.0.10",
Expand Down
2 changes: 1 addition & 1 deletion playground.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { randomRGB } from './app/src/utils/color';
// @ts-nocheck
import { getAllButtons } from './app/src/utils/index';

const buttons = getAllButtons()

const data = getAllButtons()
Expand Down
11 changes: 10 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,16 @@
/* Module Resolution Options */
"moduleResolution": "node",
"forceConsistentCasingInFileNames": true,
"esModuleInterop": true
"esModuleInterop": true,
"paths": {
"Core/*": ["./app/src/core/*"],
"Redux/*": ["./app/src/redux/*"],
"I18n/*": ["./app/localization/*"],
"Components/*": ["./app/src/components/*"],
"Constants/*": ["./app/src/constants/*"],
"Pages/*": ["./app/src/pages/*"],
"Utils/*": ["./app/src/utils/*"]
}
},
"include": [
"app/src"
Expand Down

0 comments on commit fd1f069

Please sign in to comment.