Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Hi-Ray committed Oct 27, 2022
0 parents commit 6bcf16d
Show file tree
Hide file tree
Showing 32 changed files with 5,787 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
node_modules
*.log
.next
app
dist
.idea
5 changes: 5 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions .idea/aws.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/converge.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/discord.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 38 additions & 0 deletions README.md
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`)
```
12 changes: 12 additions & 0 deletions electron-builder.yml
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
44 changes: 44 additions & 0 deletions main/background.ts
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();
});
87 changes: 87 additions & 0 deletions main/helpers/create-window.ts
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;
};
3 changes: 3 additions & 0 deletions main/helpers/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import createWindow from "./create-window";

export { createWindow };
77 changes: 77 additions & 0 deletions main/helpers/ipc.ts
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");
Loading

0 comments on commit 6bcf16d

Please sign in to comment.