Skip to content

Commit

Permalink
Add tons of electron building things
Browse files Browse the repository at this point in the history
  • Loading branch information
cassidoo committed Jan 26, 2020
1 parent 5939212 commit 347b3a8
Show file tree
Hide file tree
Showing 10 changed files with 1,395 additions and 188 deletions.
1 change: 1 addition & 0 deletions .rescriptsrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = [require.resolve("./.webpack.config.js")];
4 changes: 4 additions & 0 deletions .webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = config => {
config.target = "electron-renderer";
return config;
};
3 changes: 0 additions & 3 deletions bootstrapper.js

This file was deleted.

15 changes: 0 additions & 15 deletions index.html

This file was deleted.

130 changes: 0 additions & 130 deletions main.js

This file was deleted.

47 changes: 40 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,47 @@
{
"name": "todometer2",
"version": "0.1.0",
"private": true,
"name": "todometer",
"description": "A meter-based to-do list",
"version": "2.0.0",
"author": {
"name": "Cassidy Williams",
"email": "[email protected]",
"url": "https://cassidoo.co"
},
"build": {
"appId": "com.electron.todometer",
"productName": "todometer",
"copyright": "Copyright © 2020 @cassidoo",
"mac": {
"category": "public.app-category.utilities"
},
"files": [
"build/**/*",
"node_modules/**/*"
],
"directories": {
"buildResources": "src/assets"
}
},
"main": "public/electron.js",
"dependencies": {
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.3.2",
"@testing-library/user-event": "^7.1.2",
"electron-is-dev": "^1.1.0",
"moment": "^2.24.0",
"node-sass": "^4.13.1",
"react": "^16.12.0",
"react-dom": "^16.12.0",
"react-scripts": "3.3.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
"start": "rescripts start",
"build": "rescripts build",
"test": "rescripts test",
"electron-dev": "concurrently \"BROWSER=none yarn start\" \"wait-on http://localhost:3000 && electron .\"",
"postinstall": "electron-builder install-app-deps",
"preelectron-pack": "yarn build",
"electron-pack": "electron-builder build -mw"
},
"eslintConfig": {
"extends": "react-app"
Expand All @@ -32,5 +57,13 @@
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"@rescripts/cli": "^0.0.13",
"@rescripts/rescript-env": "^0.0.11",
"concurrently": "^5.0.2",
"electron": "^7.1.10",
"electron-builder": "^22.3.2",
"wait-on": "^4.0.0"
}
}
151 changes: 151 additions & 0 deletions public/electron.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
// import { app, BrowserWindow, Menu, dialog, powerMonitor, shell } from "electron";
const {
app,
BrowserWindow,
Menu,
dialog,
powerMonitor,
shell
} = require("electron");

const moment = require("moment");
const path = require("path");
// const setupEvents = require("../installers/setupEvents");
const { version } = require("../package.json");
const isDev = require("electron-is-dev");

let mainWindow = {
show: () => {
console.log("show");
}
}; // temp object while app loads
let willQuit = false;

function createWindow() {
mainWindow = new BrowserWindow({
width: 800,
minWidth: 320,
height: 600,
fullscreenable: true,
backgroundColor: "#403F4D",
icon: path.join(__dirname, "/src/assets/png/128x128.png"),
webPreferences: {
nodeIntegration: true
}
});

mainWindow.loadURL(
isDev
? "http://localhost:3000"
: `file://${path.join(__dirname, "../build/index.html")}`
);
}

function manageRefresh() {
const time = moment("24:00:00", "hh:mm:ss").diff(moment(), "seconds");
setTimeout(midnightTask, time * 1000);

function midnightTask() {
mainWindow.reload();
}
}

function menuSetup() {
const menuTemplate = [
{
label: "todometer",
submenu: [
{
label: "About",
click: () => {
dialog.showMessageBox(mainWindow, {
type: "info",
title: "About",
message: "todometer is built by @cassidoo",
detail:
"You can find her on GitHub and Twitter as @cassidoo, or on her website cassidoo.co.",
icon: path.join(__dirname, "assets/png/64x64.png")
});
}
},
{
label: "Contribute (v" + version + ")",
click: () => {
shell.openExternal("https://github.com/cassidoo/todometer");
}
},
{
type: "separator"
},
{
/* For debugging */
label: "Dev tools",
click: () => {
mainWindow.webContents.openDevTools();
}
},
{
label: "Quit",
accelerator: "CommandOrControl+Q",
click: () => {
app.quit();
}
}
]
},
{
label: "Edit",
submenu: [
{ role: "undo" },
{ role: "redo" },
{ role: "cut" },
{ role: "copy" },
{ role: "paste" },
{ role: "delete" },
{ role: "selectall" }
]
},
{
label: "View",
submenu: [
{ role: "reload" },
{ role: "togglefullscreen" },
{ role: "minimize" },
{ role: "hide" },
{ role: "close" }
]
}
];
const menu = Menu.buildFromTemplate(menuTemplate);
Menu.setApplicationMenu(menu);
}

app.on("ready", () => {
// TODO: I think I can kill this but tbd
// Squirrel events have to be handled before anything else
// if (setupEvents.handleSquirrelEvent()) {
// // squirrel event handled and app will exit in 1000ms, so don't do anything else
// return;
// }

createWindow();
menuSetup();

powerMonitor.on("resume", () => {
mainWindow.reload();
});

mainWindow.on("close", e => {
if (willQuit) {
mainWindow = null;
} else {
e.preventDefault();
mainWindow.hide();
}
});

manageRefresh();
});

app.on("activate", () => mainWindow.show());
app.on("before-quit", () => (willQuit = true));
Loading

0 comments on commit 347b3a8

Please sign in to comment.