-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add electron for desktop application
- Loading branch information
1 parent
878acce
commit 4a6d66d
Showing
8 changed files
with
2,641 additions
and
65 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 |
---|---|---|
|
@@ -23,3 +23,5 @@ package-lock.json | |
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
out/ |
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,51 @@ | ||
const { app, BrowserWindow, Menu, dialog } = require("electron"); | ||
const path = require("path"); | ||
|
||
function createWindow () { | ||
const win = new BrowserWindow({ | ||
width: 1300, | ||
height: 750, | ||
resizable: false, | ||
webPreferences: { | ||
preload: path.join(__dirname, "preload.js") | ||
} | ||
}); | ||
|
||
win.setIcon(new URL(path.join(__dirname, "./build/icon_snake.png"), "file:").href); | ||
win.loadURL(new URL(path.join(__dirname, "./build/index.html"), "file:").href); | ||
|
||
Menu.setApplicationMenu(Menu.buildFromTemplate([ | ||
{ | ||
label: "Back", | ||
click: function() { | ||
win.loadURL(new URL(path.join(__dirname, "./build/index.html"), "file:").href); | ||
} | ||
}, | ||
{ | ||
label: "About", | ||
click: function() { | ||
dialog.showMessageBox(win, { | ||
title: "About", | ||
message: "This is a Snake Game, and it's written in React + TypeScript.\nThe project is open source on Github. You can build and play it on your computer or play it online.\n\nCopyright (c) NriotHrreion "+ new Date().getFullYear(), | ||
type: "info" | ||
}); | ||
} | ||
} | ||
])); | ||
} | ||
|
||
app.whenReady().then(() => { | ||
createWindow(); | ||
|
||
app.on("activate", () => { | ||
if(BrowserWindow.getAllWindows().length === 0) { | ||
createWindow(); | ||
} | ||
}); | ||
}); | ||
|
||
app.on("window-all-closed", () => { | ||
if(process.platform !== "darwin") { | ||
app.quit(); | ||
} | ||
}); |
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
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
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
Oops, something went wrong.