Skip to content
This repository was archived by the owner on Feb 9, 2026. It is now read-only.

Commit 20303e2

Browse files
feat: Enhance event handling with new READY_TO_PATCH event and related hooks
1 parent d8e727d commit 20303e2

File tree

12 files changed

+57
-28
lines changed

12 files changed

+57
-28
lines changed

forge.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const {FusesPlugin} = require('@electron-forge/plugin-fuses');
2-
const {FuseV1Options, FuseVersion} = require('@electron/fuses');
1+
const { FusesPlugin } = require('@electron-forge/plugin-fuses');
2+
const { FuseV1Options, FuseVersion } = require('@electron/fuses');
33

44
module.exports = {
55
packagerConfig: {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "yandexmusicmodpatcher",
33
"productName": "YandexMusicModPatcher",
4-
"version": "0.3.0",
4+
"version": "0.4.0",
55
"description": "Patcher for YandexMusicModClient",
66
"main": ".webpack/main",
77
"scripts": {

src/app/components/App.jsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import LogCard from './layout/LogCard.jsx';
77
import SettingsPage from "./pages/Settings.jsx";
88
import ModalsContainer from "./layout/modals/ModalsContainer.jsx";
99
import { StateProvider } from "./StateContext.jsx";
10-
import { useSendReady } from "./Events.jsx";
10+
import { useOnIsInstallPossibleResponse, useSendReady, useSendReadyToPatch } from "./Events.jsx";
1111

1212

1313
function App() {
@@ -17,6 +17,13 @@ function App() {
1717

1818
useEffect(() => {
1919
useSendReady({});
20+
const OffIsInstallPossibleResponse = useOnIsInstallPossibleResponse(() =>{
21+
useSendReadyToPatch();
22+
})
23+
24+
return () => {
25+
OffIsInstallPossibleResponse();
26+
}
2027
}, []);
2128

2229
return (

src/app/components/Events.jsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ export function useSendDeleteLegacyYmApp() {
5151
return window.desktopEvents.send(Events.DELETE_LEGACY_YM_APP);
5252
}
5353

54+
export function useSendReadyToPatch() {
55+
return window.desktopEvents.send(Events.READY_TO_PATCH);
56+
}
57+
5458
export function useOnPatchProgress(callback) {
5559
return window.desktopEvents.on(Events.PATCH_PROGRESS, (event, args) => {
5660
callback(event, args)

src/main/events.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,9 @@ export const handleApplicationEvents = (window) => {
159159
electron.ipcMain.on(Events.READY, (event, args) => {
160160
console.log('Received READY', args);
161161
sendStateInitiated(undefined, State.state);
162+
})
163+
electron.ipcMain.on(Events.READY_TO_PATCH, (event, args) => {
164+
console.log('Received READY_TO_PATCH', args);
162165
State.get('onReadyEventsQueue').forEach((event) => {
163166
event();
164167
})

src/main/modules/deeplinkCommands/index.js

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
11
import { promises as fsp } from 'fs';
22
import fs from 'fs';
3+
import patch from './patch';
34

45

56
export default class deeplinkCommands {
67

78
static async loadCommands() {
8-
let commands = [];
9+
let commands = [{ name: 'patch', run: patch }];
910

10-
// Получаем список всех папок в src/main/deeplinkCommands/
11-
const dirPath = __dirname;
12-
const entries = await fsp.readdir(dirPath, { withFileTypes: true });
13-
for (const entry of entries) {
14-
if (entry.isDirectory()) {
15-
const indexPath = `${dirPath}/${entry.name}/index.js`;
16-
if (fs.existsSync(indexPath)) {
17-
const command = await import(indexPath);
18-
commands.push(command.default || command.run || command);
19-
}
20-
}
21-
}
11+
// TODO Разобраться с вебпаком чтобы main не бандлился а копировался.
12+
// // Получаем список всех папок в src/main/deeplinkCommands/
13+
// const dirPath = __dirname;
14+
// const entries = await fsp.readdir(dirPath, { withFileTypes: true });
15+
// for (const entry of entries) {
16+
// if (entry.isDirectory()) {
17+
// const indexPath = `${dirPath}/${entry.name}/index.js`;
18+
// if (fs.existsSync(indexPath)) {
19+
// const command = await import(indexPath);
20+
// commands.push({ name: entry.name, run: command.default || command.run || command});
21+
// }
22+
// }
23+
// }
2224

2325
return commands;
2426
}

src/main/modules/deeplinkCommands/patch/index.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,20 @@ import { getState } from '../../state.js';
66
const State = getState();
77

88
export default function run(...args) {
9-
const patchType = PatchTypes[args?.[0]] ?? PatchTypes.DEFAULT;
10-
State.onReadyEventsQueue.push(()=> {
11-
ipcMain.emit(Events.PATCH, {
9+
const params = args?.[0];
10+
const window = args?.[1];
11+
const patchType = Object.values(PatchTypes).includes(params?.[0]) ? params?.[0] : PatchTypes.DEFAULT;
12+
if (!window) {
13+
State.state.onReadyEventsQueue.push(() => {
14+
ipcMain.emit(Events.PATCH, undefined, {
15+
patchType: patchType,
16+
fromAsarSrc: args?.[0]?.[1] ? decodeURI(args?.[0]?.[1]) : undefined
17+
})
18+
});
19+
} else {
20+
ipcMain.emit(Events.PATCH, undefined, {
1221
patchType: patchType,
13-
fromAsarSrc: args?.[1] ? decodeURI(args?.[1]) : undefined
22+
fromAsarSrc: args?.[0]?.[1] ? decodeURI(args?.[0]?.[1]) : undefined
1423
})
15-
});
24+
}
1625
}

src/main/modules/handleDeeplinks.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ import electron from 'electron';
33
import config from '../config.js';
44

55

6+
67
const transformUrl = (url) => {
7-
return url.replace(`${config.deeplinkProtocol}://`, "/").split('/');
8+
return url.replace(`${config.deeplinkProtocol}://`, "").split('/');
89
};
910

1011
const deeplinkCommandsHandler = await new deeplinkCommands();
@@ -13,7 +14,7 @@ export const checkIsDeeplink = (value) => {
1314
const deeplinkRegexp = new RegExp(`${config.deeplinkProtocol}:\/\/.*`);
1415
return deeplinkRegexp.test(value);
1516
};
16-
export const navigateToDeeplink = (url, window) => {
17+
export const navigateToDeeplink = (url, window=undefined) => {
1718
if (!url) {
1819
return;
1920
}
@@ -22,7 +23,7 @@ export const navigateToDeeplink = (url, window) => {
2223

2324
if (args) {
2425
const commandName = args.shift();
25-
deeplinkCommandsHandler.runCommand(commandName, args);
26+
deeplinkCommandsHandler.runCommand(commandName, args, window);
2627
}
2728

2829
};

src/main/modules/singleInstance.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import electron from "electron";
2-
import { handleDeeplink } from "./handleDeeplinks.js";
2+
import { checkIsDeeplink, navigateToDeeplink } from "./handleDeeplinks.js";
33
const isFirstInstance = electron.app.requestSingleInstanceLock();
44
export const checkForSingleInstance = () => {
55
if (isFirstInstance) {
@@ -11,9 +11,9 @@ export const checkForSingleInstance = () => {
1111
}
1212
window.focus();
1313
const lastCommandLineArg = commandLine.pop();
14-
if (lastCommandLineArg && handleDeeplink.checkIsDeeplink(lastCommandLineArg)
14+
if (lastCommandLineArg && checkIsDeeplink(lastCommandLineArg)
1515
) {
16-
handleDeeplink.navigateToDeeplink(window, lastCommandLineArg);
16+
navigateToDeeplink(lastCommandLineArg, window);
1717
}
1818
}
1919
});

src/main/types/Events.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const Events = {
2121
STATE_UPDATED: 'STATE_UPDATED',
2222
STATE_INITIATED: 'STATE_INITIATED',
2323
LOG_ENTRY_CREATE: 'LOG_ENTRY_CREATE',
24+
READY_TO_PATCH: 'READY_TO_PATCH',
2425
};
2526

2627
export default Events

0 commit comments

Comments
 (0)