Skip to content

Commit 878065d

Browse files
committedOct 4, 2019
Initial commit
0 parents  commit 878065d

16 files changed

+532
-0
lines changed
 

‎.editorconfig

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
root = true
2+
3+
[*]
4+
indent_style = tab
5+
end_of_line = lf
6+
charset = utf-8
7+
trim_trailing_whitespace = true
8+
insert_final_newline = true
9+
10+
[*.yml]
11+
indent_style = space
12+
indent_size = 2

‎.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=auto eol=lf

‎.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
yarn.lock
3+
/dist

‎.travis.yml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
os: osx
2+
osx_image: xcode10.2
3+
language: node_js
4+
node_js: '12'
5+
script:
6+
- npm test
7+
- npm run dist

‎build/background.png

914 Bytes
Loading

‎build/background@2x.png

2.02 KB
Loading

‎build/icon.png

310 KB
Loading

‎config.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
'use strict';
2+
const Store = require('electron-store');
3+
4+
module.exports = new Store({
5+
defaults: {
6+
favoriteAnimal: '🦄'
7+
}
8+
});

‎index.css

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
html,
2+
body {
3+
padding: 0;
4+
margin: 0;
5+
background: transparent;
6+
}
7+
8+
/* Use OS default fonts */
9+
body {
10+
font-family: -apple-system,
11+
BlinkMacSystemFont,
12+
'Segoe UI',
13+
Roboto,
14+
Oxygen-Sans,
15+
Ubuntu,
16+
Cantarell,
17+
'Helvetica Neue',
18+
sans-serif,
19+
'Apple Color Emoji',
20+
'Segoe UI Emoji',
21+
'Segoe UI Symbol';
22+
text-rendering: optimizeLegibility;
23+
font-feature-settings: 'liga', 'clig', 'kern';
24+
}
25+
26+
header {
27+
position: absolute;
28+
width: 500px;
29+
height: 250px;
30+
top: 50%;
31+
left: 50%;
32+
margin-top: -125px;
33+
margin-left: -250px;
34+
text-align: center;
35+
}
36+
37+
header h1 {
38+
font-size: 60px;
39+
font-weight: 200;
40+
margin: 0;
41+
padding: 0;
42+
opacity: 0.7;
43+
}

‎index.html

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<title>Electron boilerplate</title>
6+
<link rel="stylesheet" href="index.css">
7+
</head>
8+
<body>
9+
<div class="container">
10+
<header>
11+
<h1>Electron boilerplate</h1>
12+
<p></p>
13+
</header>
14+
<section class="main"></section>
15+
<footer></footer>
16+
</div>
17+
</body>
18+
</html>

‎index.js

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
'use strict';
2+
const path = require('path');
3+
const {app, BrowserWindow, Menu} = require('electron');
4+
/// const {autoUpdater} = require('electron-updater');
5+
const {is} = require('electron-util');
6+
const unhandled = require('electron-unhandled');
7+
const debug = require('electron-debug');
8+
const contextMenu = require('electron-context-menu');
9+
const config = require('./config');
10+
const menu = require('./menu');
11+
12+
unhandled();
13+
debug();
14+
contextMenu();
15+
16+
// Note: Must match `build.appId` in package.json
17+
app.setAppUserModelId('com.company.AppName');
18+
19+
// Uncomment this before publishing your first version.
20+
// It's commented out as it throws an error if there are no published versions.
21+
// if (!is.development) {
22+
// const FOUR_HOURS = 1000 * 60 * 60 * 4;
23+
// setInterval(() => {
24+
// autoUpdater.checkForUpdates();
25+
// }, FOUR_HOURS);
26+
//
27+
// autoUpdater.checkForUpdates();
28+
// }
29+
30+
// Prevent window from being garbage collected
31+
let mainWindow;
32+
33+
const createMainWindow = async () => {
34+
const win = new BrowserWindow({
35+
title: app.getName(),
36+
show: false,
37+
width: 600,
38+
height: 400
39+
});
40+
41+
win.on('ready-to-show', () => {
42+
win.show();
43+
});
44+
45+
win.on('closed', () => {
46+
// Dereference the window
47+
// For multiple windows store them in an array
48+
mainWindow = undefined;
49+
});
50+
51+
await win.loadFile(path.join(__dirname, 'index.html'));
52+
53+
return win;
54+
};
55+
56+
// Prevent multiple instances of the app
57+
if (!app.requestSingleInstanceLock()) {
58+
app.quit();
59+
}
60+
61+
app.on('second-instance', () => {
62+
if (mainWindow) {
63+
if (mainWindow.isMinimized()) {
64+
mainWindow.restore();
65+
}
66+
67+
mainWindow.show();
68+
}
69+
});
70+
71+
app.on('window-all-closed', () => {
72+
if (!is.macos) {
73+
app.quit();
74+
}
75+
});
76+
77+
app.on('activate', async () => {
78+
if (!mainWindow) {
79+
mainWindow = await createMainWindow();
80+
}
81+
});
82+
83+
(async () => {
84+
await app.whenReady();
85+
Menu.setApplicationMenu(menu);
86+
mainWindow = await createMainWindow();
87+
88+
const favoriteAnimal = config.get('favoriteAnimal');
89+
mainWindow.webContents.executeJavaScript(`document.querySelector('header p').textContent = 'Your favorite animal is ${favoriteAnimal}'`);
90+
})();

‎license

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

‎menu.js

+179
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
'use strict';
2+
const path = require('path');
3+
const {app, Menu, shell} = require('electron');
4+
const {
5+
is,
6+
appMenu,
7+
aboutMenuItem,
8+
openUrlMenuItem,
9+
openNewGitHubIssue,
10+
debugInfo
11+
} = require('electron-util');
12+
const config = require('./config');
13+
14+
const showPreferences = () => {
15+
// Show the app's preferences here
16+
};
17+
18+
const helpSubmenu = [
19+
openUrlMenuItem({
20+
label: 'Website',
21+
url: 'https://github.com/sindresorhus/electron-boilerplate'
22+
}),
23+
openUrlMenuItem({
24+
label: 'Source Code',
25+
url: 'https://github.com/sindresorhus/electron-boilerplate'
26+
}),
27+
{
28+
label: 'Report an Issue…',
29+
click() {
30+
const body = `
31+
<!-- Please succinctly describe your issue and steps to reproduce it. -->
32+
33+
34+
---
35+
36+
${debugInfo()}`;
37+
38+
openNewGitHubIssue({
39+
user: 'sindresorhus',
40+
repo: 'electron-boilerplate',
41+
body
42+
});
43+
}
44+
}
45+
];
46+
47+
if (!is.macos) {
48+
helpSubmenu.push(
49+
{
50+
type: 'separator'
51+
},
52+
aboutMenuItem({
53+
icon: path.join(__dirname, 'static', 'icon.png'),
54+
text: 'Created by Your Name'
55+
})
56+
);
57+
}
58+
59+
const debugSubmenu = [
60+
{
61+
label: 'Show Settings',
62+
click() {
63+
config.openInEditor();
64+
}
65+
},
66+
{
67+
label: 'Show App Data',
68+
click() {
69+
shell.openItem(app.getPath('userData'));
70+
}
71+
},
72+
{
73+
type: 'separator'
74+
},
75+
{
76+
label: 'Delete Settings',
77+
click() {
78+
config.clear();
79+
app.relaunch();
80+
app.quit();
81+
}
82+
},
83+
{
84+
label: 'Delete App Data',
85+
click() {
86+
shell.moveItemToTrash(app.getPath('userData'));
87+
app.relaunch();
88+
app.quit();
89+
}
90+
}
91+
];
92+
93+
const macosTemplate = [
94+
appMenu([
95+
{
96+
label: 'Preferences…',
97+
accelerator: 'Command+,',
98+
click() {
99+
showPreferences();
100+
}
101+
}
102+
]),
103+
{
104+
role: 'fileMenu',
105+
submenu: [
106+
{
107+
label: 'Custom'
108+
},
109+
{
110+
type: 'separator'
111+
},
112+
{
113+
role: 'close'
114+
}
115+
]
116+
},
117+
{
118+
role: 'editMenu'
119+
},
120+
{
121+
role: 'viewMenu'
122+
},
123+
{
124+
role: 'windowMenu'
125+
},
126+
{
127+
role: 'help',
128+
submenu: helpSubmenu
129+
}
130+
];
131+
132+
// Linux and Windows
133+
const otherTemplate = [
134+
{
135+
role: 'fileMenu',
136+
submenu: [
137+
{
138+
label: 'Custom'
139+
},
140+
{
141+
type: 'separator'
142+
},
143+
{
144+
label: 'Settings',
145+
accelerator: 'Control+,',
146+
click() {
147+
showPreferences();
148+
}
149+
},
150+
{
151+
type: 'separator'
152+
},
153+
{
154+
role: 'quit'
155+
}
156+
]
157+
},
158+
{
159+
role: 'editMenu'
160+
},
161+
{
162+
role: 'viewMenu'
163+
},
164+
{
165+
role: 'help',
166+
submenu: helpSubmenu
167+
}
168+
];
169+
170+
const template = process.platform === 'darwin' ? macosTemplate : otherTemplate;
171+
172+
if (is.development) {
173+
template.push({
174+
label: 'Debug',
175+
submenu: debugSubmenu
176+
});
177+
}
178+
179+
module.exports = Menu.buildFromTemplate(template);

‎package.json

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
{
2+
"name": "app-name",
3+
"productName": "App Name",
4+
"version": "0.0.0",
5+
"description": "The best app ever",
6+
"license": "MIT",
7+
"repository": "sindresorhus/electron-boilerplate",
8+
"author": {
9+
"name": "Your Name",
10+
"email": "user@gmail.com",
11+
"url": "https://sindresorhus.com"
12+
},
13+
"scripts": {
14+
"postinstall": "electron-builder install-app-deps",
15+
"lint": "xo",
16+
"test": "npm run lint",
17+
"start": "electron .",
18+
"pack": "electron-builder --dir",
19+
"dist": "electron-builder --macos --linux --windows",
20+
"release": "np"
21+
},
22+
"dependencies": {
23+
"electron-context-menu": "^0.15.0",
24+
"electron-debug": "^3.0.0",
25+
"electron-store": "^4.0.0",
26+
"electron-unhandled": "^3.0.0",
27+
"electron-updater": "^4.0.6",
28+
"electron-util": "^0.12.0"
29+
},
30+
"devDependencies": {
31+
"electron": "^6.0.7",
32+
"electron-builder": "^21.2.0",
33+
"np": "^5.0.3",
34+
"xo": "^0.24.0"
35+
},
36+
"xo": {
37+
"envs": [
38+
"node",
39+
"browser"
40+
]
41+
},
42+
"np": {
43+
"publish": false,
44+
"releaseDraft": false
45+
},
46+
"build": {
47+
"appId": "com.company.AppName",
48+
"mac": {
49+
"category": "public.app-category.social-networking",
50+
"darkModeSupport": true
51+
},
52+
"dmg": {
53+
"iconSize": 160,
54+
"contents": [
55+
{
56+
"x": 180,
57+
"y": 170
58+
},
59+
{
60+
"x": 480,
61+
"y": 170,
62+
"type": "link",
63+
"path": "/Applications"
64+
}
65+
]
66+
},
67+
"linux": {
68+
"target": [
69+
"AppImage",
70+
"deb"
71+
],
72+
"category": "Network;Chat"
73+
}
74+
}
75+
}

‎readme.md

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# electron-boilerplate
2+
3+
> Boilerplate to kickstart creating an app with [Electron](https://github.com/electron/electron)
4+
5+
See [awesome-electron](https://github.com/sindresorhus/awesome-electron) for more useful Electron resources.
6+
7+
See [Caprine](https://github.com/sindresorhus/caprine) for a production app based on this boilerplate.
8+
9+
10+
## Features
11+
12+
- [`electron-builder`](https://www.electron.build) fully set up to create cross-platform builds
13+
- [Builds the app on Travis](https://www.electron.build/multi-platform-build.html)
14+
- [Silent auto-updates](https://www.electron.build/auto-update.html)
15+
- App menu that adheres to the system user interface guidelines
16+
- [Config handling](https://github.com/sindresorhus/electron-store)
17+
- [Context menu](https://github.com/sindresorhus/electron-context-menu)
18+
- [User-friendly handling of unhandled errors](https://github.com/sindresorhus/electron-unhandled)
19+
- Easily publish new versions to GitHub Releases
20+
- And much more!
21+
22+
23+
## Getting started
24+
25+
**Click the "Use this template" button.**
26+
27+
Alternatively, create a new directory and then run:
28+
29+
```
30+
$ curl -fsSL https://github.com/sindresorhus/electron-boilerplate/archive/master.tar.gz | tar -xz --strip-components 1
31+
```
32+
33+
There's also a [Yeoman generator](https://github.com/sindresorhus/generator-electron).
34+
35+
36+
---
37+
38+
**Remove everything from here and above**
39+
40+
---
41+
42+
43+
# App Name
44+
45+
> The best app ever
46+
47+
48+
## Install
49+
50+
*macOS 10.10+, Linux, and Windows 7+ are supported (64-bit only).*
51+
52+
**macOS**
53+
54+
[**Download**](https://github.com/user/repo/releases/latest) the `.dmg` file.
55+
56+
**Linux**
57+
58+
[**Download**](https://github.com/user/repo/releases/latest) the `.AppImage` or `.deb` file.
59+
60+
*The AppImage needs to be [made executable](http://discourse.appimage.org/t/how-to-make-an-appimage-executable/80) after download.*
61+
62+
**Windows**
63+
64+
[**Download**](https://github.com/user/repo/releases/latest) the `.exe` file.
65+
66+
67+
---
68+
69+
70+
## Dev
71+
72+
Built with [Electron](https://electronjs.org).
73+
74+
### Run
75+
76+
```
77+
$ npm install
78+
$ npm start
79+
```
80+
81+
### Publish
82+
83+
```
84+
$ npm run release
85+
```
86+
87+
After Travis finishes building your app, open the release draft it created and click "Publish".

‎static/Icon.png

310 KB
Loading

0 commit comments

Comments
 (0)
Please sign in to comment.