Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: main electron with managers and handlers #610

Merged
merged 2 commits into from
Nov 14, 2023

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-homebrew
Copy link
Contributor

dan-homebrew 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
@0xSage
Copy link
Contributor

0xSage commented Nov 14, 2023

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
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
3 checks passed
@louis-jan louis-jan deleted the chore/refactor-main-electron branch November 14, 2023 05:08
@louis-jan louis-jan added enhancement New feature or request type: chore Maintenance, integration, packaging related and removed enhancement New feature or request labels Nov 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: chore Maintenance, integration, packaging related
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

4 participants