-
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.
- Loading branch information
0 parents
commit 6bcf16d
Showing
32 changed files
with
5,787 additions
and
0 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,6 @@ | ||
node_modules | ||
*.log | ||
.next | ||
app | ||
dist | ||
.idea |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<p align="center"><img src="https://i.imgur.com/NZfsD1p.png"></p> | ||
|
||
## Usage | ||
|
||
### Create an App | ||
|
||
``` | ||
# with npx | ||
$ npx create-nextron-app my-app --example with-typescript | ||
# with yarn | ||
$ yarn create nextron-app my-app --example with-typescript | ||
# with pnpx | ||
$ pnpx create-nextron-app my-app --example with-typescript | ||
``` | ||
|
||
### Install Dependencies | ||
|
||
``` | ||
$ cd my-app | ||
# using yarn or npm | ||
$ yarn (or `npm install`) | ||
# using pnpm | ||
$ pnpm install --shamefully-hoist | ||
``` | ||
|
||
### Use it | ||
|
||
``` | ||
# development mode | ||
$ yarn dev (or `npm run dev` or `pnpm run dev`) | ||
# production build | ||
$ yarn build (or `npm run build` or `pnpm run build`) | ||
``` |
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,12 @@ | ||
appId: com.example.nextron | ||
productName: My Nextron App | ||
copyright: Copyright © 2018 Yoshihide Shiono | ||
directories: | ||
output: dist | ||
buildResources: resources | ||
files: | ||
- from: . | ||
filter: | ||
- package.json | ||
- app | ||
publish: null |
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,44 @@ | ||
import { app } from "electron"; | ||
import serve from "electron-serve"; | ||
import { createWindow } from "./helpers"; | ||
import LCUConn from "./helpers/util/Connector"; | ||
import "./helpers/ipc"; | ||
import Store from "electron-store"; | ||
Store.initRenderer() | ||
LCUConn().start(); | ||
|
||
const isProd: boolean = process.env.NODE_ENV === "production"; | ||
|
||
if (isProd) { | ||
serve({ directory: "app" }); | ||
} else { | ||
app.setPath("userData", `${app.getPath("userData")} (development)`); | ||
} | ||
|
||
(async () => { | ||
await app.whenReady(); | ||
|
||
const mainWindow = createWindow("main", { | ||
width: 400, | ||
height: 600, | ||
resizable: false, | ||
backgroundColor: "#18191B", | ||
title: "Convergence", | ||
frame: false, | ||
webPreferences: { | ||
nodeIntegration: true, | ||
}, | ||
}); | ||
|
||
if (isProd) { | ||
await mainWindow.loadURL("app://./home.html"); | ||
} else { | ||
const port = process.argv[2]; | ||
await mainWindow.loadURL(`http://localhost:${port}/home`); | ||
mainWindow.webContents.openDevTools({ mode: "detach" }); | ||
} | ||
})(); | ||
|
||
app.on("window-all-closed", () => { | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { | ||
BrowserWindow, | ||
BrowserWindowConstructorOptions, | ||
screen, | ||
} from "electron"; | ||
import Store from "electron-store"; | ||
|
||
export default ( | ||
windowName: string, | ||
options: BrowserWindowConstructorOptions | ||
): BrowserWindow => { | ||
const key = "window-state"; | ||
const name = `window-state-${windowName}`; | ||
const store = new Store({ name }); | ||
const defaultSize = { | ||
width: options.width, | ||
height: options.height, | ||
}; | ||
let state = {}; | ||
let win; | ||
|
||
const restore = () => store.get(key, defaultSize); | ||
|
||
const getCurrentPosition = () => { | ||
const position = win.getPosition(); | ||
const size = win.getSize(); | ||
return { | ||
x: position[0], | ||
y: position[1], | ||
width: size[0], | ||
height: size[1], | ||
}; | ||
}; | ||
|
||
const windowWithinBounds = (windowState, bounds) => { | ||
return ( | ||
windowState.x >= bounds.x && | ||
windowState.y >= bounds.y && | ||
windowState.x + windowState.width <= bounds.x + bounds.width && | ||
windowState.y + windowState.height <= bounds.y + bounds.height | ||
); | ||
}; | ||
|
||
const resetToDefaults = () => { | ||
const bounds = screen.getPrimaryDisplay().bounds; | ||
return Object.assign({}, defaultSize, { | ||
x: (bounds.width - defaultSize.width) / 2, | ||
y: (bounds.height - defaultSize.height) / 2, | ||
}); | ||
}; | ||
|
||
const ensureVisibleOnSomeDisplay = (windowState) => { | ||
const visible = screen.getAllDisplays().some((display) => { | ||
return windowWithinBounds(windowState, display.bounds); | ||
}); | ||
if (!visible) { | ||
// Window is partially or fully not visible now. | ||
// Reset it to safe defaults. | ||
return resetToDefaults(); | ||
} | ||
return windowState; | ||
}; | ||
|
||
const saveState = () => { | ||
if (!win.isMinimized() && !win.isMaximized()) { | ||
Object.assign(state, getCurrentPosition()); | ||
} | ||
store.set(key, state); | ||
}; | ||
|
||
state = ensureVisibleOnSomeDisplay(restore()); | ||
|
||
const browserOptions: BrowserWindowConstructorOptions = { | ||
...options, | ||
...state, | ||
webPreferences: { | ||
nodeIntegration: true, | ||
contextIsolation: false, | ||
...options.webPreferences, | ||
}, | ||
}; | ||
win = new BrowserWindow(browserOptions); | ||
|
||
win.on("close", saveState); | ||
|
||
return win; | ||
}; |
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 @@ | ||
import createWindow from "./create-window"; | ||
|
||
export { createWindow }; |
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,77 @@ | ||
import { dialog } from "electron"; | ||
import { ipcMain as ipc } from "electron-better-ipc"; | ||
import LCUEndpoints from "./util/Constants"; | ||
import { | ||
exportConfigData, | ||
loadConfigFile, | ||
loadPrevConfig, | ||
} from "./util/Config"; | ||
import Connector from "./util/Connector"; | ||
import { getIGB, getIGS, getSummonerName } from "./util/Summoner"; | ||
|
||
console.log("Registering IPC Listeners..."); | ||
|
||
Connector().on("connect", () => { | ||
console.log("ipc: connect"); | ||
ipc.sendToRenderers("lcu-connected"); | ||
}); | ||
|
||
Connector().on("disconnect", () => { | ||
console.log("ipc: disconnect"); | ||
ipc.sendToRenderers("lcu-disconnected"); | ||
}); | ||
|
||
ipc.answerRenderer("start-connector", () => { | ||
console.log("ipc: start-connector"); | ||
Connector().start(); | ||
return Connector().isConnected(); | ||
}); | ||
|
||
ipc.answerRenderer("is-lcu-ready", async () => { | ||
console.log("ipc: is-lcu-ready"); | ||
const isReady = await Connector().isReady(); | ||
return isReady; | ||
}); | ||
|
||
ipc.answerRenderer("lol-current-summoner", () => { | ||
console.log("ipc: lol-current-summoner"); | ||
if (Connector().isConnected()) { | ||
return Connector().get(LCUEndpoints.CHAT_ME); | ||
} | ||
|
||
return { gameName: "", gameTag: "" }; | ||
}); | ||
|
||
ipc.on("close-application", () => { | ||
console.log("ipc: close-application"); | ||
process.exit(0); | ||
}); | ||
|
||
ipc.answerRenderer("export-config", async () => { | ||
console.log("ipc: export-config"); | ||
const fileLocation = dialog.showSaveDialogSync({ title: "Save Config" }); | ||
|
||
if (fileLocation != null) { | ||
const IGS = await getIGS(); | ||
const IGB = await getIGB(); | ||
const summonerName = await getSummonerName(); | ||
|
||
return exportConfigData(IGS, IGB, summonerName, fileLocation); | ||
} | ||
|
||
return null; | ||
}); | ||
|
||
ipc.answerRenderer("import-config", async (path) => { | ||
console.log("ipc: import-config"); | ||
return loadConfigFile(path as string); | ||
}); | ||
|
||
ipc.answerRenderer("import-prev", () => { | ||
console.log("ipc: import-prev"); | ||
return loadPrevConfig(); | ||
}); | ||
|
||
Connector().on("connect", () => ipc.sendToRenderers("lcu-connected")); | ||
Connector().on("disconnect", () => ipc.sendToRenderers("lcu-disconnect")); | ||
console.log("Done Loading IPC Listeners"); |
Oops, something went wrong.