Skip to content

Commit 306ac70

Browse files
committed
First commit
1 parent 4a2cbae commit 306ac70

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+13493
-2
lines changed

.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.DS_Store
2+
node_modules
3+
.svelte-kit
4+
package
5+
dist
6+
out

README.md

+49-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,49 @@
1-
# memento-sveltekit-electron-typescript
2-
Template for create a desktop app with SvelteKit, Electron and TypeScript (with electron-updater, electron-reload and electron-builder)
1+
# MEMENTO SvelteKit Electron TypeScript
2+
Template to create a desktop app with SvelteKit, Electron and TypeScript (with electron-updater, electron-reload and electron-builder)
3+
4+
**This project is still under development: the `todos` section doesn't work!**
5+
6+
## Get Started
7+
8+
This is a project template for [Svelte](https://svelte.dev) and [Electron](https://www.electronjs.org/) apps. It lives at https://github.com/el3um4s/memento-sveltekit-electron-typescript.
9+
10+
To create a new project based on this template using [degit](https://github.com/Rich-Harris/degit):
11+
12+
```bash
13+
npx degit el3um4s/memento-sveltekit-electron-typescript
14+
cd svelte-app
15+
```
16+
17+
Then install the dependencies with
18+
19+
```bash
20+
npm install
21+
```
22+
23+
*Note that you will need to have [Node.js](https://nodejs.org) installed.*
24+
25+
## Command
26+
27+
For development purpose:
28+
29+
- `npm run nodemon`: auto restart Electron on change
30+
- `npm run svelte:build`: build Svelte code (and copy in `dist/www`
31+
32+
You can configure settings in `index.ts`. Change `developerOptions`:
33+
34+
- `isInProduction`: true if is in production
35+
- `serveSvelteDev`: true when you want to watch svelte
36+
- `buildSvelteDiv`: true when you want to build svelte
37+
- `watchSvelteBuild`: true when you want to watch build svelte
38+
39+
For publish purpose:
40+
41+
- `npm run out:win`: create an exe file for Windows
42+
- `npm run publish:win`: publish the app on GitHub
43+
44+
## Notes
45+
46+
I'm blogging about the development process in these posts:
47+
48+
- [Svelte, Electron & TypeScript](https://www.patreon.com/posts/svelte-electron-52952074)
49+
- [Electron and TypeScript: how to use ipcMain and ipcRenderer](https://www.patreon.com/posts/electron-and-how-53505039)

dev-app-update.yml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
provider: github
2+
owner: el3um4s
3+
repo: memento-sveltekit-electron-typescript

electron/index.ts

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import { app, BrowserWindow } from "electron";
2+
import path from "path";
3+
import serve from "electron-serve";
4+
import { exec } from "child_process";
5+
6+
const developerOptions = {
7+
isInProduction: false, // true if is in production
8+
serveSvelteDev: false, // true when you want to watch svelte
9+
buildSvelteDiv: false, // true when you want to build svelte
10+
watchSvelteBuild: false, // true when you want to watch build svelte
11+
};
12+
13+
if (! developerOptions.isInProduction){
14+
developerOptions.isInProduction = process.env.NODE_ENV === "production" || !/[\\/]electron/.exec(process.execPath); // !process.execPath.match(/[\\/]electron/);
15+
}
16+
let loadURL:any = null;
17+
18+
if (!developerOptions.isInProduction && developerOptions.serveSvelteDev) {
19+
console.log("npm run svelte:dev");
20+
exec("npm run svelte:dev");
21+
console.log("electron-reload svelte dev");
22+
require("electron-reload")(path.join(__dirname, "..", "svelte"));
23+
}
24+
25+
if (!developerOptions.isInProduction && developerOptions.buildSvelteDiv) {
26+
console.log("npm run svelte:build");
27+
exec("npm run svelte:build");
28+
}
29+
30+
if (!developerOptions.isInProduction && developerOptions.watchSvelteBuild) {
31+
console.log("electron-reload www");
32+
require("electron-reload")(path.join(__dirname, "www"));
33+
}
34+
35+
36+
if (developerOptions.isInProduction || !developerOptions.serveSvelteDev) {
37+
console.log("serve dist/www");
38+
loadURL = serve({ directory: "dist/www" });
39+
}
40+
41+
let mainWindow = null;
42+
43+
const createWindow = async () => {
44+
mainWindow = new BrowserWindow({
45+
width: 854,
46+
height: 480,
47+
webPreferences: {
48+
nodeIntegration: true,
49+
contextIsolation: true,
50+
enableRemoteModule: true,
51+
},
52+
});
53+
54+
if (developerOptions.serveSvelteDev) {
55+
mainWindow.loadURL("http://localhost:3000/");
56+
} else if (loadURL) {
57+
await loadURL(mainWindow);
58+
}
59+
};
60+
61+
app.on("ready", async () => {
62+
app.name = "Svelte Template";
63+
await createWindow();
64+
});
65+
66+
app.on("window-all-closed", () => {
67+
if (process.platform !== "darwin") {
68+
app.quit();
69+
}
70+
});

icon.ico

13 KB
Binary file not shown.

license.txt

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 Samuele de Tomasi
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

nodemon.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"watch": ["electron/"],
3+
"ext": "js, json, ts, css, png, jpeg, jpg, ico",
4+
"exec": "npm run start"
5+
}

0 commit comments

Comments
 (0)