forked from cassidoo/todometer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tons of electron building things
- Loading branch information
Showing
10 changed files
with
1,395 additions
and
188 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = [require.resolve("./.webpack.config.js")]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module.exports = config => { | ||
config.target = "electron-renderer"; | ||
return config; | ||
}; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
|
@@ -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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); |
Oops, something went wrong.