Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewruzzi committed Feb 28, 2021
0 parents commit 3db5d39
Show file tree
Hide file tree
Showing 16 changed files with 23,730 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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
yarn.lock
/dist
.DS_Store
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: {
backgroundUrl: 'https://example.com/'
}
});
43 changes: 43 additions & 0 deletions index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
html,
body {
padding: 0;
margin: 0;
background: transparent;
}

/* Use OS default fonts */
body {
font-family: -apple-system,
BlinkMacSystemFont,
'Segoe UI',
Roboto,
Oxygen-Sans,
Ubuntu,
Cantarell,
'Helvetica Neue',
sans-serif,
'Apple Color Emoji',
'Segoe UI Emoji',
'Segoe UI Symbol';
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 Desktop Background</title>
<link rel="stylesheet" href="index.css">
</head>
<body>
<div class="container">
<header>
<h1>Electron Desktop Background</h1>
<p></p>
</header>
<section class="main"></section>
<footer></footer>
</div>
</body>
</html>
92 changes: 92 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
'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');
const menu = require('./menu');
const packageJson = require('./package.json');
const createTray = require('./tray');
const tray = null;
unhandled();
// Debug();
contextMenu();

//app.setAppUserModelId(packageJson.build.appId);

// 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,
frame: false,
type: 'desktop'
});

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'));
await win.maximize();
await win.loadURL(config.get('backgroundUrl'));
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', () => {
if (!mainWindow) {
mainWindow = createMainWindow();
}
});

(async () => {
await app.whenReady();
Menu.setApplicationMenu(menu);
mainWindow = await createMainWindow();
createTray(mainWindow);
})();
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');

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

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

openNewGitHubIssue({
user: 'mattruzzi',
repo: 'electron-desktop-background',
body
});
}
}
];

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

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 = process.platform === 'darwin' ? macosTemplate : otherTemplate;

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

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

0 comments on commit 3db5d39

Please sign in to comment.