Skip to content

Commit

Permalink
Why don't you just update all libs & deps
Browse files Browse the repository at this point in the history
  • Loading branch information
YeonV committed Dec 5, 2024
1 parent 5e41fba commit 95a4fb5
Show file tree
Hide file tree
Showing 41 changed files with 808 additions and 523 deletions.
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"engines": {
"node": ">=20"
},
"type": "module",
"dependencies": {
"@dnd-kit/core": "^6.2.0",
"@dnd-kit/modifiers": "^8.0.0",
Expand Down Expand Up @@ -43,10 +44,9 @@
"conf": "^13.0.1",
"crypto": "^1.0.1",
"deep-object-diff": "^1.1.9",
"electron-devtools-installer": "^3.2.0",
"electron-is-dev": "2",
"electron-is-dev": "3.0.1",
"electron-squirrel-startup": "^1.0.0",
"electron-store": "8.2.0",
"electron-store": "10.0.0",
"eslint-config-react-app": "7.0.1",
"eslint-config-standard": "^17.1.0",
"eslint-plugin-prettier": "^5.2.1",
Expand Down Expand Up @@ -201,7 +201,7 @@
"@types/styled-components": "^5.1.34",
"concurrently": "^9.1.0",
"cross-env": "^7.0.3",
"electron": "^27.1.2",
"electron": "^33.2.1",
"electron-builder": "^25.1.8",
"eslint": "8.57",
"eslint-config-prettier": "^9.1.0",
Expand Down Expand Up @@ -285,4 +285,4 @@
]
}
}
}
}
77 changes: 0 additions & 77 deletions public/app/core.js

This file was deleted.

12 changes: 0 additions & 12 deletions public/app/devtools.js

This file was deleted.

22 changes: 9 additions & 13 deletions public/app/handlers.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
const { app, shell, BrowserWindow, nativeTheme } = require('electron')
const path = require('path')
const { generateMfaQr, handleVerifyOTP } = require('./otp.js')
const { coreParams, isCC, defaultCoreParams, store } = require('./core.js')
const { startInstance, stopInstance, sendStatus } = require('./instances.js')
import { app, shell, BrowserWindow, nativeTheme } from 'electron'
import path from 'path'
import { generateMfaQr, handleVerifyOTP } from './otp.js'
import { startInstance, stopInstance, sendStatus } from './instances.js'
import coreParams from './utils/coreParams.mjs'
import defaultCoreParams from './utils/defaultCoreParams.mjs'
import store from './utils/store.mjs'
import isCC from './utils/isCC.mjs'

const handlers = async (wind, subprocesses, event, parameters) => {
export const handlers = async (wind, subprocesses, event, parameters) => {
console.log('ALL PARAMS', parameters)

try {
Expand Down Expand Up @@ -91,12 +94,6 @@ const handlers = async (wind, subprocesses, event, parameters) => {
break
case 'open-config':
console.log('Open Config')
// wind.webContents.send('fromMain', ['currentdir', path.join(path.dirname(__dirname), isDev ? 'extraResources' : '../extraResources')]);

// Windows:
// shell.showItemInFolder(
// path.join(app.getPath('appData'), '.ledfx', 'config.json')
// )

if (parameters.instance && parameters.instance !== 'instance1') {
shell.showItemInFolder(
Expand Down Expand Up @@ -141,4 +138,3 @@ const handlers = async (wind, subprocesses, event, parameters) => {
}
}

module.exports = { handlers }
23 changes: 8 additions & 15 deletions public/app/instances.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const { startCore, coreParams } = require('./core')
import coreParams from './utils/coreParams.mjs'
import startCore from './utils/startCore.mjs'

const poll = async (wind, subprocesses, name, p) => {
export const poll = async (wind, subprocesses, name, p) => {
console.log('Polling core', name, 'on port', p)
if (!p) return
try {
Expand All @@ -14,15 +15,15 @@ const poll = async (wind, subprocesses, name, p) => {
}
}

function stopInstance(wind, name, subprocesses) {
export function stopInstance(wind, name, subprocesses) {
if (subprocesses[name]) {
subprocesses[name].running = false
sendStatus(wind, subprocesses, false, name)
subprocesses[name].kill()
}
}

function startInstance(wind, name, subprocesses, port) {
export function startInstance(wind, name, subprocesses, port) {
try {
let subpy = startCore(wind, process.platform, name, port)
if (subpy !== null) {
Expand Down Expand Up @@ -58,7 +59,7 @@ function startInstance(wind, name, subprocesses, port) {
}
}

function sendStatus(wind, subprocesses, connected = false, n) {
export function sendStatus(wind, subprocesses, connected = false, n) {
let status = {}
let platformParams = coreParams[process.platform]
// Check if `wind` is an instance of `BrowserWindow`
Expand Down Expand Up @@ -97,13 +98,13 @@ function sendStatus(wind, subprocesses, connected = false, n) {
if (wind && wind.webContents && !wind.isDestroyed() && status) wind.webContents.send('fromMain', ['status', status])
}

function kills(subprocess) {
export function kills(subprocess) {
if (subprocess !== null) {
subprocess.kill('SIGINT')
}
}

function closeAllSubs(wind, subpy, subprocesses) {
export function closeAllSubs(wind, subpy, subprocesses) {
if (wind && wind.webContents && !wind.isDestroyed()) wind.webContents.send('fromMain', 'shutdown')
if (subpy !== null) kills(subpy)
if (subprocesses && Object.keys(subprocesses).length > 0) {
Expand All @@ -113,11 +114,3 @@ function closeAllSubs(wind, subpy, subprocesses) {
}
}

module.exports = {
poll,
stopInstance,
startInstance,
sendStatus,
kills,
closeAllSubs
}
27 changes: 27 additions & 0 deletions public/app/media.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const { execFile } = require('child_process');
const path = require('path');

const exePath = path.join(__dirname, 'path_to_dist_folder', 'media.exe');

execFile(exePath, (error, stdout, stderr) => {
if (error) {
console.error(`Error: ${error.message}`);
return;
}
if (stderr) {
console.error(`Stderr: ${stderr}`);
return;
}
try {
const mediaInfo = JSON.parse(stdout);
if (mediaInfo.error) {
console.log(mediaInfo.error);
} else {
console.log(`Title: ${mediaInfo.title}`);
console.log(`Artist: ${mediaInfo.artist}`);
console.log(`Album: ${mediaInfo.album}`);
}
} catch (parseError) {
console.error(`JSON Parse Error: ${parseError.message}`);
}
});
21 changes: 10 additions & 11 deletions public/app/otp.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const crypto = require('crypto')
const qrcode = require('qrcode');
const base32Decode = require('base32-decode')
const base32Encode = require('base32-encode');
const { store } = require('./core');
import crypto from 'crypto'
import qrcode from 'qrcode'
import base32Decode from 'base32-decode'
import base32Encode from 'base32-encode'
import store from './utils/store.mjs'


function generateHOTP(secret, counter) {
export function generateHOTP(secret, counter) {
const decodedSecret = base32Decode(secret, 'RFC4648');

const buffer = Buffer.alloc(8);
Expand All @@ -31,12 +31,12 @@ function generateHOTP(secret, counter) {
return `${code % 10 ** 6}`.padStart(6, '0');
}

function generateTOTP(secret, window = 0) {
export function generateTOTP(secret, window = 0) {
const counter = Math.floor(Date.now() / 30000);
return generateHOTP(secret, counter + window);
}

function verifyTOTP(token, secret, window = 1) {
export function verifyTOTP(token, secret, window = 1) {
for (let errorWindow = -window; errorWindow <= +window; errorWindow++) {
const totp = generateTOTP(secret, errorWindow);
if (token === totp) {
Expand All @@ -46,7 +46,7 @@ function verifyTOTP(token, secret, window = 1) {
return false;
}

function generateMfaQr(event, parameters) {
export function generateMfaQr(event, parameters) {
const user = store.get('user') || {
username: 'FreeUser',
mfaEnabled: false,
Expand Down Expand Up @@ -77,7 +77,7 @@ function generateMfaQr(event, parameters) {

return;
}
function handleVerifyOTP(wind, event, parameters) {
export function handleVerifyOTP(wind, event, parameters) {
const user = store.get('user') || {
username: 'FreeUser',
mfaEnabled: false,
Expand All @@ -97,4 +97,3 @@ function handleVerifyOTP(wind, event, parameters) {
return;
}

module.exports = { generateHOTP, generateTOTP, verifyTOTP, handleVerifyOTP, generateMfaQr };
19 changes: 11 additions & 8 deletions public/app/protocol.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
const { app, BrowserWindow } = require('electron')
const path = require('path')
import { app } from 'electron'
import path from 'path'

export const setupProtocol = () => {
(async () => {
const isSquirrelStartup = await import('electron-squirrel-startup');
if (isSquirrelStartup.default) {
app.quit()
}
})()

const setupProtocol = () => {
if (require('electron-squirrel-startup')) {
app.quit()
}
if (process.defaultApp) {
if (process.argv.length >= 2) {
app.setAsDefaultProtocolClient('ledfx', process.execPath, [
Expand All @@ -16,7 +20,7 @@ const setupProtocol = () => {
}
}

const handleProtocol = (getWind, gotTheLock, ready) => {
export const handleProtocol = (getWind, gotTheLock, ready) => {
if (process.platform === 'win32') {
if (!gotTheLock) {
app.quit()
Expand All @@ -42,4 +46,3 @@ const handleProtocol = (getWind, gotTheLock, ready) => {
}
}

module.exports = { setupProtocol, handleProtocol }
12 changes: 7 additions & 5 deletions public/app/toast.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
const fs = require('fs');
const path = require('path');
const { Notification } = require('electron');
import fs from 'fs'
import path from 'path'
import { Notification } from 'electron'
import { fileURLToPath } from 'node:url'

const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
const NOTIFICATION_TITLE = 'LedFx Client - by Blade';
const NOTIFICATION_BODY = 'Testing Notification from the Main process';

Expand All @@ -11,7 +14,7 @@ function getConfig() {
return JSON.parse(configData);
}

function showNotification(title = NOTIFICATION_TITLE, body = NOTIFICATION_BODY) {
export function showNotification(title = NOTIFICATION_TITLE, body = NOTIFICATION_BODY) {
const config = getConfig();
const updateUrl = config.updateUrl;

Expand All @@ -30,4 +33,3 @@ function showNotification(title = NOTIFICATION_TITLE, body = NOTIFICATION_BODY)
}).show();
}

module.exports = { showNotification };
7 changes: 7 additions & 0 deletions public/app/utils/coreFile.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const coreFile = {
darwin: 'LedFx_core.app/Contents/MacOS/LedFx_v2',
linux: 'LedFx',
win32: 'LedFx/LedFx.exe'
}

export default coreFile
6 changes: 6 additions & 0 deletions public/app/utils/coreParams.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import defaultCoreParams from './defaultCoreParams.mjs'
import store from './store.mjs'

const coreParams = store.get('coreParams', defaultCoreParams)

export default coreParams
Loading

0 comments on commit 95a4fb5

Please sign in to comment.