Creating extensions #2296
Unanswered
dex4er
asked this question in
Developers
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
HOWTO: Creating an Extension for the Freelens Application
This guide explains how to create a new extension for the Freelens application using the
freelens-example-extensionrepository as a template.Prerequisites
repository or
an original site.
1. Fork or Clone the Example Extension
Create a new project based on the example extension:
git clone https://github.com/freelensapp/freelens-example-extension.git my-freelens-extension cd my-freelens-extension2. Rename and Update Metadata
my-freelens-extension) as desired.package.json:"name","description","author", etc."repository"and"homepage"if public."main": Entry point for the main process (should be"out/main/index.js")."renderer": Entry point for the renderer/UI (should be"out/renderer/index.js")."engines": Must include a"freelens"field specifying the compatible version and"node"matching the main app, for example:"devDependencies". Extensions cannot load Node.js modules at runtime.Modules listed in
externalizeDepsPluginandpluginExternalin your Vite config are provided by the Freelens main app.devDependenciesand their versions must match the main app.3. Directory and Runtime Conventions
main/andcommon/directories:*.tsfiles are allowed.renderer/(andrenderersubdirectories incommon/):*.tsxfiles.fs,os, custom node-only libraries).4. Bundling Assets with Your Extension
Extensions are technically classes loaded by the Electron main application and its renderer (Node.js and browser contexts).
All assets needed by your extension (icons, images, style files, markdown, YAML, and text files) must be bundled into the built
main/index.jsandrenderer/index.jsfiles.How to bundle assets:
Why?
5. CSS Naming and Usage
To avoid CSS class name conflicts with the main application or other extensions:
Example:
*.module.scssor*.module.css.:global(ClassName)syntax in your SCSS file.6. APIs and Stores Registration
If your extension defines new API endpoints or data stores, do not explicitly register them in your extension code.
7. Use Linters and Formatters
Using linters and code formatters is recommended to ensure code quality and consistency.
--alloption is added to the command.8. Validate Dependencies with Knip
It is recommended to validate your dependencies using the Knip tool to detect unused or missing dependencies:
devDependenciesare accurate and that your extension does not include unnecessary code.9. Handling Build Outputs and Debugging
The build process produces separate files for each module (preserved modules) in the
out/directory, making debugging easier.When preparing your extension for release, you should produce a single bundled file for the main process and one for the renderer.
VITE_PRESERVE_MODULES="false"before building.index.jsfile for each file referenced inpackage.json.10. GitHub Actions & Renovate Bot Configuration
freelensapporganization or want to reuse their automation:11. Error Handling & Debugging
Extensions that throw errors during initialization will not work correctly.
It is crucial to verify that your extension does not emit any error messages immediately after enabling it.
Where to check for errors:
Best practice:
12. Project Structure Overview
src/– Your extension source code (withmain/,renderer/,common/as subdirectories as appropriate)out/– Output directory for built (bundled) codeintegration/– Integration tests for your extensionpackage.json– Project metadata, scripts, and devDependencies13. Install Dependencies
Install all dependencies using pnpm:
14. Implement Your Extension Logic
src/main/for backend logic, insrc/renderer/for UI, and share logic insrc/common/as needed.main/and non-renderercommon/modules.renderer/andcommon/renderer/.15. Build the Extension
pnpm build
16. Run Integration Tests (Optional)
Integration tests are located in the
integration/directory. You can copy them to Freelens main application source to run as extensions can use them directly.17. Test Locally in Freelens
18. Package and Distribute (Optional)
README.mdincludes usage and installation instructions.19. Maintain and Update
References
Support
If you need help:
Happy coding!
Beta Was this translation helpful? Give feedback.
All reactions