thombruce / tnt

Thom's Nuxt Template
https://tnt.thombruce.com/
MIT License
1 stars 0 forks source link

[Feature]: Document Electron Setup #73

Open thombruce opened 2 months ago

thombruce commented 2 months ago

Feature request

From terminal:

yarn add @thombruce/tnt-electron

In nuxt.config:

export default defineNuxtConfig({
  extends: [
    '@thombruce/tnt-electron'
  ]
})

In package.json:

{
  "main": "dist-electron/main.js",
  "scripts": {
    "electron:build": "ELECTRON=true nuxt build",
    "electron:dev": "ELECTRON=true nuxt dev"
  }
}

Optionally (recommended) in .gitignore:

dist-electron

That's all there is to it. So long as the ELECTRON environment variable is passed along with the build script (which we added to package.json above) our app now launches in Electron.

This all just needs to be added to the docs.


Note that this isn't yet a totally functional Electron setup... We don't persist any data or configuration (the app will always launch in light mode, for instance), we don't build for different platforms or describe how to do so, and we only provide a basic electron/main.ts (though the idea is that the user would overwrite ours with their own for more sophisticated needs).

It's all just a start, but it's a good start, and from here we will attempt to provide as much by default as we can... starting, I think, with persisting the light/dark state or appropriately reading it from system (because shouldn't it be appearing dark on my system anyway?).

Code of Conduct

thombruce commented 2 months ago

Note that the most basic functional setup for a new project essentially looks like this: 040fd08dabff331c80e8a60d5d672077dd45ebfc

You've got the optional .gitignore additions there, and you've got these necessary parts:

From there, we can start building and running it as though it were a regular Nuxt/TNT app (because it is one).

As of now, things like the darkMode setting are not persisting but... I'm pretty sure this is simply because the Electron application has a different dev URL every time it is launched. If I can configure that, I think we immediately achieve basic localStorage-based persistence.

Though do note that it seems not to respect system colour mode setting either.