Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasff committed Apr 13, 2022
0 parents commit 961a8a5
Show file tree
Hide file tree
Showing 16 changed files with 536 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
root = true

[*]
indent_style = tab
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.yml]
indent_style = space
indent_size = 2
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto eol=lf
20 changes: 20 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: CI
on:
- push
- pull_request
jobs:
test:
name: Node.js ${{ matrix.node-version }}
runs-on: macos-latest
strategy:
fail-fast: false
matrix:
node-version:
- 14
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npm test
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
yarn.lock
/dist
Binary file added build/background.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added build/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added build/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
'use strict';
const Store = require('electron-store');

module.exports = new Store({
defaults: {
favoriteAnimal: '🦄'
}
});
41 changes: 41 additions & 0 deletions index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
html,
body {
padding: 0;
margin: 0;
background: transparent;
}

/* Use OS default fonts */
body {
font-family:
system-ui,
-apple-system,
'Segoe UI',
Roboto,
Helvetica,
Arial,
sans-serif,
'Apple Color Emoji',
'Segoe UI Emoji';
text-rendering: optimizeLegibility;
font-feature-settings: 'liga', 'clig', 'kern';
}

header {
position: absolute;
width: 500px;
height: 250px;
top: 50%;
left: 50%;
margin-top: -125px;
margin-left: -250px;
text-align: center;
}

header h1 {
font-size: 60px;
font-weight: 200;
margin: 0;
padding: 0;
opacity: 0.7;
}
18 changes: 18 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Electron boilerplate</title>
<link rel="stylesheet" href="index.css">
</head>
<body>
<div class="container">
<header>
<h1>Electron boilerplate</h1>
<p></p>
</header>
<section class="main"></section>
<footer></footer>
</div>
</body>
</html>
90 changes: 90 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
'use strict';
const path = require('path');
const {app, BrowserWindow, Menu} = require('electron');
/// const {autoUpdater} = require('electron-updater');
const {is} = require('electron-util');
const unhandled = require('electron-unhandled');
const debug = require('electron-debug');
const contextMenu = require('electron-context-menu');
const config = require('./config.js');
const menu = require('./menu.js');

unhandled();
debug();
contextMenu();

// Note: Must match `build.appId` in package.json
app.setAppUserModelId('com.company.AppName');

// Uncomment this before publishing your first version.
// It's commented out as it throws an error if there are no published versions.
// if (!is.development) {
// const FOUR_HOURS = 1000 * 60 * 60 * 4;
// setInterval(() => {
// autoUpdater.checkForUpdates();
// }, FOUR_HOURS);
//
// autoUpdater.checkForUpdates();
// }

// Prevent window from being garbage collected
let mainWindow;

const createMainWindow = async () => {
const win = new BrowserWindow({
title: app.name,
show: false,
width: 600,
height: 400
});

win.on('ready-to-show', () => {
win.show();
});

win.on('closed', () => {
// Dereference the window
// For multiple windows store them in an array
mainWindow = undefined;
});

await win.loadFile(path.join(__dirname, 'index.html'));

return win;
};

// Prevent multiple instances of the app
if (!app.requestSingleInstanceLock()) {
app.quit();
}

app.on('second-instance', () => {
if (mainWindow) {
if (mainWindow.isMinimized()) {
mainWindow.restore();
}

mainWindow.show();
}
});

app.on('window-all-closed', () => {
if (!is.macos) {
app.quit();
}
});

app.on('activate', async () => {
if (!mainWindow) {
mainWindow = await createMainWindow();
}
});

(async () => {
await app.whenReady();
Menu.setApplicationMenu(menu);
mainWindow = await createMainWindow();

const favoriteAnimal = config.get('favoriteAnimal');
mainWindow.webContents.executeJavaScript(`document.querySelector('header p').textContent = 'Your favorite animal is ${favoriteAnimal}'`);
})();
9 changes: 9 additions & 0 deletions license
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
MIT License

Copyright (c) <%= name %> <<%= email %>> (<%= website %>)

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:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

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.
179 changes: 179 additions & 0 deletions menu.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
'use strict';
const path = require('path');
const {app, Menu, shell} = require('electron');
const {
is,
appMenu,
aboutMenuItem,
openUrlMenuItem,
openNewGitHubIssue,
debugInfo
} = require('electron-util');
const config = require('./config.js');

const showPreferences = () => {
// Show the app's preferences here
};

const helpSubmenu = [
openUrlMenuItem({
label: 'Website',
url: 'https://github.com/sindresorhus/electron-boilerplate'
}),
openUrlMenuItem({
label: 'Source Code',
url: 'https://github.com/sindresorhus/electron-boilerplate'
}),
{
label: 'Report an Issue…',
click() {
const body = `
<!-- Please succinctly describe your issue and steps to reproduce it. -->
---
${debugInfo()}`;

openNewGitHubIssue({
user: 'sindresorhus',
repo: 'electron-boilerplate',
body
});
}
}
];

if (!is.macos) {
helpSubmenu.push(
{
type: 'separator'
},
aboutMenuItem({
icon: path.join(__dirname, 'static', 'icon.png'),
text: 'Created by Your Name'
})
);
}

const debugSubmenu = [
{
label: 'Show Settings',
click() {
config.openInEditor();
}
},
{
label: 'Show App Data',
click() {
shell.openItem(app.getPath('userData'));
}
},
{
type: 'separator'
},
{
label: 'Delete Settings',
click() {
config.clear();
app.relaunch();
app.quit();
}
},
{
label: 'Delete App Data',
click() {
shell.moveItemToTrash(app.getPath('userData'));
app.relaunch();
app.quit();
}
}
];

const macosTemplate = [
appMenu([
{
label: 'Preferences…',
accelerator: 'Command+,',
click() {
showPreferences();
}
}
]),
{
role: 'fileMenu',
submenu: [
{
label: 'Custom'
},
{
type: 'separator'
},
{
role: 'close'
}
]
},
{
role: 'editMenu'
},
{
role: 'viewMenu'
},
{
role: 'windowMenu'
},
{
role: 'help',
submenu: helpSubmenu
}
];

// Linux and Windows
const otherTemplate = [
{
role: 'fileMenu',
submenu: [
{
label: 'Custom'
},
{
type: 'separator'
},
{
label: 'Settings',
accelerator: 'Control+,',
click() {
showPreferences();
}
},
{
type: 'separator'
},
{
role: 'quit'
}
]
},
{
role: 'editMenu'
},
{
role: 'viewMenu'
},
{
role: 'help',
submenu: helpSubmenu
}
];

const template = is.macos ? macosTemplate : otherTemplate;

if (is.development) {
template.push({
label: 'Debug',
submenu: debugSubmenu
});
}

module.exports = Menu.buildFromTemplate(template);
Loading

0 comments on commit 961a8a5

Please sign in to comment.