-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Better template with electron 17.1
- Loading branch information
1 parent
8887a94
commit a6526eb
Showing
34 changed files
with
6,324 additions
and
6,410 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
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,3 @@ | ||
build | ||
dist | ||
node_modules |
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,9 @@ | ||
{ | ||
"tabWidth": 4, | ||
"useTabs": true, | ||
"bracketSpacing": true, | ||
"singleQuote": false, | ||
"endOfLine": "crlf", | ||
"trailingComma": "all", | ||
"semi": true | ||
} |
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
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
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,6 @@ | ||
module.exports = { | ||
plugins: { | ||
tailwindcss: {}, | ||
autoprefixer: {}, | ||
}, | ||
}; |
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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,42 +1,37 @@ | ||
const { app, BrowserWindow, Tray, Notification, Menu } = require("electron"); | ||
|
||
const { app, BrowserWindow } = require("electron"); | ||
const { createTray } = require("./utils/createTray"); | ||
const { createMainWindow } = require("./utils/createMainWindow"); | ||
const { createPopupWindow } = require("./utils/createPopupWindow"); | ||
const { showNotification } = require("./utils/showNotification"); | ||
const AutoLaunch = require("auto-launch"); | ||
const remote = require("@electron/remote/main"); | ||
const config = require("./utils/config"); | ||
|
||
if (config.isDev) require("electron-reloader")(module); | ||
if (require("electron-squirrel-startup")) app.quit(); | ||
|
||
const path = require("path"); | ||
const isDev = require("electron-is-dev"); | ||
|
||
require("@electron/remote/main").initialize(); | ||
|
||
const icon = path.join(__dirname, "/favicon.ico"); | ||
let mainWindow = null; | ||
remote.initialize(); | ||
|
||
function createWindow() { | ||
mainWindow = new BrowserWindow({ | ||
width: 800, | ||
height: 600, | ||
webPreferences: { | ||
nodeIntegration: true, | ||
enableRemoteModule: true, | ||
devTools: false, | ||
contextIsolation: false, | ||
}, | ||
frame: true, | ||
icon, | ||
title: "Electron - React Template", | ||
}); | ||
mainWindow.loadURL( | ||
isDev | ||
? "http://localhost:3000" | ||
: `file://${path.join(__dirname, "../build/index.html")}`, | ||
const autoStart = new AutoLaunch({ | ||
name: config.appName, | ||
}); | ||
if (!config.isDev) autoStart.enable(); | ||
|
||
app.on("ready", async () => { | ||
config.mainWindow = await createMainWindow(); | ||
config.tray = createTray(); | ||
config.popupWindow = await createPopupWindow(); | ||
showNotification( | ||
config.appName, | ||
"Application running on background! See application tray.", | ||
); | ||
} | ||
|
||
app.on("ready", createWindow); | ||
}); | ||
|
||
app.on("window-all-closed", function () { | ||
app.on("window-all-closed", () => { | ||
if (process.platform !== "darwin") app.quit(); | ||
}); | ||
|
||
app.on("activate", function () { | ||
if (BrowserWindow.getAllWindows().length === 0) createWindow(); | ||
app.on("activate", () => { | ||
if (BrowserWindow.getAllWindows().length === 0) | ||
config.mainWindow = createMainWindow(); | ||
}); |
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
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,14 @@ | ||
const { join } = require("path"); | ||
const isDev = require("electron-is-dev"); | ||
|
||
let config = { | ||
appName: "Electron React Tailwind Template", | ||
icon: join(__dirname, "..", "/favicon.ico"), | ||
tray: null, | ||
isQuiting: false, | ||
mainWindow: null, | ||
popupWindow: null, | ||
isDev, | ||
}; | ||
|
||
module.exports = config; |
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,33 @@ | ||
const { BrowserWindow } = require("electron"); | ||
const { join } = require("path"); | ||
const remote = require("@electron/remote/main"); | ||
const config = require("./config"); | ||
|
||
exports.createMainWindow = async () => { | ||
const window = new BrowserWindow({ | ||
width: 800, | ||
height: 600, | ||
webPreferences: { | ||
nodeIntegration: true, | ||
enableRemoteModule: true, | ||
devTools: config.isDev, | ||
contextIsolation: false, | ||
}, | ||
frame: false, | ||
icon: config.icon, | ||
title: config.appName, | ||
}); | ||
remote.enable(window.webContents); | ||
await window.loadURL( | ||
config.isDev | ||
? "http://localhost:3000" | ||
: `file://${join(__dirname, "..", "../build/index.html")}`, | ||
); | ||
window.on("close", (e) => { | ||
if (!config.isQuiting) { | ||
e.preventDefault(); | ||
window.hide(); | ||
} | ||
}); | ||
return window; | ||
}; |
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,53 @@ | ||
const { BrowserWindow } = require("electron"); | ||
const { join } = require("path"); | ||
const config = require("./config"); | ||
const remote = require("@electron/remote/main"); | ||
|
||
exports.createPopupWindow = async () => { | ||
const window = new BrowserWindow({ | ||
width: 260, | ||
height: 360, | ||
x: 0, | ||
y: 0, | ||
resizable: false, | ||
alwaysOnTop: true, | ||
webPreferences: { | ||
nodeIntegration: true, | ||
enableRemoteModule: true, | ||
devTools: config.isDev, | ||
contextIsolation: false, | ||
}, | ||
frame: false, | ||
icon: config.icon, | ||
title: config.appName, | ||
}); | ||
remote.enable(window.webContents); | ||
await window.loadURL( | ||
config.isDev | ||
? "http://localhost:3000/#/popup" | ||
: `file://${join(__dirname, "..", "../build/index.html#popup")}`, | ||
); | ||
window.hide(); | ||
window.on("close", (e) => { | ||
if (!config.isQuiting) { | ||
e.preventDefault(); | ||
window.hide(); | ||
} | ||
}); | ||
window.on("blur", () => { | ||
window.hide(); | ||
}); | ||
|
||
config.tray.removeAllListeners("click"); | ||
config.tray.on("click", (_, bounds) => { | ||
window.setPosition( | ||
bounds.x - window.getSize()[0], | ||
bounds.y - window.getSize()[1], | ||
false, | ||
); | ||
if (window.isVisible()) window.hide(); | ||
else window.show(); | ||
}); | ||
|
||
return window; | ||
}; |
Oops, something went wrong.