Skip to content

Conversation

@louis-jan
Copy link
Contributor

@louis-jan louis-jan commented Nov 13, 2023

Problem

  • It's difficult to comprehend the primary lifecycle of Electron when dealing with a very long main.ts file, which encompasses the entire code base for the app's backend
  • To enhance scalability, we need to refactor managers and handlers into smaller, more manageable chunks that can be accessed from anywhere. Relying on local variables within main.ts will significantly increase maintenance efforts in the future

Changes

└── electron
   ├── handlers
     ├── app.ts
     ├── download.ts
     ├── fs.ts
     ├── plugin.ts
     ├── theme.ts
     └── update.ts
   ├── managers
     ├── download.ts
     ├── module.ts
     ├── plugin.ts
     └── window.ts
   ├── main.ts
   └── preload.ts

Our managers are Singleton classes designed to manage instances created throughout the entire app lifecycle, such as windows, download requests, imported modules, and registered plugins.

Instead of declaring a multitude of variables in main.ts, we've transitioned them to these managed managers. This allows for their utilization in other classes, such as IPC handlers.

Handlers are specifically for IPCs/events handling. They listen to various events (like filesystem changes, downloads, etc.) and provide logical handling.

Notes:

  • server is removed - will be added in a dev branch

@dan-menlo
Copy link
Contributor

dan-menlo commented Nov 13, 2023

@louis-jan This is a very clear explanation and we should work this into the "Architecture" docs for Jan.

cc @hieu-jan (in a few days)

@louis-jan louis-jan force-pushed the chore/refactor-main-electron branch 2 times, most recently from 42a454c to c71a2db Compare November 13, 2023 14:14
@louis-jan louis-jan force-pushed the chore/refactor-main-electron branch from 838d591 to 6fcc790 Compare November 13, 2023 15:50
@freelerobot
Copy link
Contributor

This is super elegant thank you @louis-jan
What is the difference in definition for a handler vs a manager? Could you maybe comment a bit more on the naming rationale

@louis-jan louis-jan force-pushed the chore/refactor-main-electron branch from 6fcc790 to 0e688b4 Compare November 14, 2023 02:54
@louis-jan
Copy link
Contributor Author

Yes, I'm currently drafting a more comprehensive comment on this, @0xSage.

Our managers are Singleton classes designed to manage instances created throughout the entire app lifecycle, such as windows, download requests, imported modules, and registered plugins.

Instead of declaring a multitude of variables in main.ts, we've transitioned them to these managed managers. This allows for their utilization in other classes, such as IPC handlers.

Handlers are specifically for IPCs/events handling. They listen to various events (like filesystem changes, downloads, etc.) and provide logical handling.

@louis-jan louis-jan merged commit 7715cd1 into main Nov 14, 2023
@louis-jan louis-jan deleted the chore/refactor-main-electron branch November 14, 2023 05:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

No open projects
Archived in project

Development

Successfully merging this pull request may close these issues.

5 participants