-
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.
Merge pull request #1 from Makisuo/ts-rework
Ts rework
- Loading branch information
Showing
68 changed files
with
4,037 additions
and
9,526 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 |
---|---|---|
@@ -1,24 +1,8 @@ | ||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
node_modules | ||
*.log | ||
.next | ||
app | ||
dist | ||
|
||
# dependencies | ||
/node_modules | ||
/.pnp | ||
.pnp.js | ||
electron-builder.yml | ||
|
||
# testing | ||
/coverage | ||
|
||
# production | ||
/build | ||
/dist | ||
|
||
# misc | ||
.DS_Store | ||
.env.local | ||
.env.development.local | ||
.env.test.local | ||
.env.production.local | ||
|
||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* |
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 +1,38 @@ | ||
### Readme | ||
<p align="center"><img src="https://i.imgur.com/flcMvDC.png"></p> | ||
|
||
## Usage | ||
|
||
### Create an App | ||
|
||
``` | ||
# with npm | ||
$ npm init nextron-app my-app --example with-typescript-material-ui | ||
# with yarn | ||
$ yarn create nextron-app my-app --example with-typescript-material-ui | ||
# with pnpx | ||
$ pnpx create-nextron-app my-app --example with-typescript-material-ui | ||
``` | ||
|
||
### 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,58 @@ | ||
import os from 'os' | ||
const { app, autoUpdater, dialog } = require('electron') | ||
const version = app.getVersion() | ||
const platform = os.platform() + '_' + os.arch() // usually returns darwin_64 | ||
|
||
const updaterFeedURL = | ||
'https://league-utils-release.herokuapp.com/' + platform + '/' + version | ||
|
||
export function appUpdater() { | ||
autoUpdater.setFeedURL(updaterFeedURL) | ||
/* Log whats happening | ||
TODO send autoUpdater events to renderer so that we could console log it in developer tools | ||
You could alsoe use nslog or other logging to see what's happening */ | ||
autoUpdater.on('error', (err) => console.log(err)) | ||
autoUpdater.on('checking-for-update', () => | ||
console.log('checking-for-update') | ||
) | ||
autoUpdater.on('update-available', () => console.log('update-available')) | ||
autoUpdater.on('update-not-available', () => | ||
console.log('update-not-available') | ||
) | ||
|
||
// Ask the user if update is available | ||
autoUpdater.on('update-downloaded', (event, releaseNotes, releaseName) => { | ||
let message = | ||
app.getName() + | ||
' ' + | ||
releaseName + | ||
' is now available. It will be installed the next time you restart the application.' | ||
if (releaseNotes) { | ||
const splitNotes = releaseNotes.split(/[^\r]\n/) | ||
message += '\n\nRelease notes:\n' | ||
splitNotes.forEach((notes) => { | ||
message += notes + '\n\n' | ||
}) | ||
} | ||
// Ask user to update the app | ||
dialog.showMessageBox( | ||
{ | ||
type: 'question', | ||
buttons: ['Install and Relaunch', 'Later'], | ||
defaultId: 0, | ||
message: | ||
'A new version of ' + | ||
app.getName() + | ||
' has been downloaded', | ||
detail: message, | ||
}, | ||
(response) => { | ||
if (response === 0) { | ||
setTimeout(() => autoUpdater.quitAndInstall(), 1) | ||
} | ||
} | ||
) | ||
}) | ||
// init for updates | ||
autoUpdater.checkForUpdates() | ||
} |
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 { autoUpdater } from 'electron-updater' | ||
|
||
import { createWindow } from './helpers' | ||
|
||
import { appUpdater } from './autoUpdater' | ||
|
||
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() | ||
|
||
// autoUpdater.checkForUpdatesAndNotify() | ||
|
||
// autoUpdater.on('update-downloaded', (info) => { | ||
// autoUpdater.quitAndInstall() | ||
// }) | ||
const mainWindow = createWindow('main', { | ||
width: 1000, | ||
height: 600, | ||
}) | ||
|
||
mainWindow.setMenuBarVisibility(false) | ||
|
||
if (isProd) { | ||
await mainWindow.loadURL('app://./index.html') | ||
appUpdater() | ||
} else { | ||
const port = process.argv[2] | ||
await mainWindow.loadURL(`http://localhost:${port}/`) | ||
mainWindow.webContents.openDevTools() | ||
} | ||
})() | ||
|
||
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,86 @@ | ||
import { | ||
screen, | ||
BrowserWindow, | ||
BrowserWindowConstructorOptions, | ||
} 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, | ||
...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,5 @@ | ||
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 |
---|---|---|
@@ -1,56 +1,36 @@ | ||
{ | ||
"name": "leagueutils", | ||
"version": "0.2.2", | ||
"private": true, | ||
"author": "Makisuo", | ||
"main": "public/electron.js", | ||
"homepage": "./", | ||
"build": { | ||
"appId": "com.example.electron-cra", | ||
"publish": { | ||
"provider": "github", | ||
}, | ||
"files": [ "build/**/*", "node_modules/**/*" ], | ||
"directories": { | ||
"buildResources": "assets" | ||
} | ||
}, | ||
"dependencies": { | ||
"@material-ui/core": "^4.10.0", | ||
"@material-ui/icons": "^4.9.1", | ||
"@testing-library/jest-dom": "^4.2.4", | ||
"@testing-library/react": "^9.3.2", | ||
"@testing-library/user-event": "^7.1.2", | ||
"cross-env": "^7.0.2", | ||
"electron-is-dev": "^1.2.0", | ||
"electron-updater": "^4.3.1", | ||
"react": "^16.13.1", | ||
"react-dom": "^16.13.1", | ||
"react-history": "^0.18.2", | ||
"react-router-dom": "^5.2.0", | ||
"react-scripts": "3.4.1" | ||
}, | ||
"private": false, | ||
"name": "league-utils", | ||
"description": "League Utils", | ||
"version": "0.2.5", | ||
"author": "David Granzin <[email protected]>", | ||
"main": "app/background.js", | ||
"scripts": { | ||
"react-start": "react-scripts start", | ||
"react-build": "react-scripts build", | ||
"react-test": "react-scripts test --env=jsdom", | ||
"react-eject": "react-scripts eject", | ||
"electron-build": "electron-builder", | ||
"release": "yarn react-build && electron-builder --win --publish=always", | ||
"build": "yarn react-build && yarn electron-build", | ||
"start": "concurrently \"cross-env BROWSER=none yarn react-start\" \"wait-on http://localhost:3000 && electron .\"" | ||
"dev": "nextron", | ||
"build": "nextron build", | ||
"publish": "electron-builder --publish always", | ||
"postinstall": "electron-builder install-app-deps" | ||
}, | ||
"eslintConfig": { | ||
"extends": "react-app" | ||
}, | ||
"browserslist": { | ||
"production": [ ">0.2%", "not dead", "not op_mini all" ], | ||
"development": [ "last 1 chrome version", "last 1 firefox version", "last 1 safari version" ] | ||
"dependencies": { | ||
"@material-ui/icons": "^4.11.2", | ||
"electron-serve": "^1.0.0", | ||
"electron-store": "^6.0.1", | ||
"electron-updater": "^4.3.5", | ||
"use-async-effect": "^2.2.2", | ||
"zustand": "^3.3.1" | ||
}, | ||
"devDependencies": { | ||
"concurrently": "^5.2.0", | ||
"electron": "^9.0.0", | ||
"electron-builder": "^22.7.0", | ||
"wait-on": "^5.0.0" | ||
"@material-ui/core": "^4.11.1", | ||
"@types/node": "^14.6.4", | ||
"@types/react": "^16.9.49", | ||
"@types/react-dom": "^16.9.8", | ||
"electron": "^11.1.1", | ||
"electron-builder": "^22.9.1", | ||
"next": "^10.0.5", | ||
"next-images": "^1.7.0", | ||
"nextron": "^6.0.3", | ||
"react": "^17.0.1", | ||
"react-dom": "^17.0.1", | ||
"typescript": "^4.1.3" | ||
} | ||
} |
Oops, something went wrong.