-
-
Notifications
You must be signed in to change notification settings - Fork 3
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 56be5d7
Showing
23 changed files
with
13,428 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,5 @@ | ||
node_modules | ||
*.log | ||
.next | ||
app | ||
dist |
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,40 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": "Nextron: Main", | ||
"type": "node", | ||
"request": "attach", | ||
"protocol": "inspector", | ||
"port": 9292, | ||
"skipFiles": ["<node_internals>/**"], | ||
"sourceMapPathOverrides": { | ||
"webpack:///./~/*": "${workspaceFolder}/node_modules/*", | ||
"webpack:///./*": "${workspaceFolder}/*", | ||
"webpack:///*": "*" | ||
} | ||
}, | ||
{ | ||
"name": "Nextron: Renderer", | ||
"type": "chrome", | ||
"request": "attach", | ||
"port": 5858, | ||
"timeout": 10000, | ||
"urlFilter": "http://localhost:*", | ||
"webRoot": "${workspaceFolder}/app", | ||
"sourceMapPathOverrides": { | ||
"webpack:///./src/*": "${webRoot}/*" | ||
} | ||
} | ||
], | ||
"compounds": [ | ||
{ | ||
"name": "Nextron: All", | ||
"preLaunchTask": "dev", | ||
"configurations": ["Nextron: Main", "Nextron: Renderer"] | ||
} | ||
] | ||
} |
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,21 @@ | ||
{ | ||
"version": "2.0.0", | ||
"tasks": [ | ||
{ | ||
"type": "npm", | ||
"script": "dev", | ||
"isBackground": true, | ||
"problemMatcher": { | ||
"owner": "custom", | ||
"pattern": { | ||
"regexp": "" | ||
}, | ||
"background": { | ||
"beginsPattern": "started server", | ||
"endsPattern": "Debugger listening on" | ||
} | ||
}, | ||
"label": "dev" | ||
} | ||
] | ||
} |
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/a9QWW0v.png"></p> | ||
|
||
## Usage | ||
|
||
### Create an App | ||
|
||
``` | ||
# with npx | ||
$ npx create-nextron-app my-app --example with-typescript-tailwindcss | ||
# with yarn | ||
$ yarn create nextron-app my-app --example with-typescript-tailwindcss | ||
# with pnpx | ||
$ pnpx create-nextron-app my-app --example with-typescript-tailwindcss | ||
``` | ||
|
||
### 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,32 @@ | ||
import { app } from 'electron'; | ||
import serve from 'electron-serve'; | ||
import { createWindow } from './helpers'; | ||
|
||
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: 1000, | ||
height: 600, | ||
}); | ||
|
||
if (isProd) { | ||
await mainWindow.loadURL('app://./home.html'); | ||
} else { | ||
const port = process.argv[2]; | ||
await mainWindow.loadURL(`http://localhost:${port}/home`); | ||
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,84 @@ | ||
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, | ||
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,5 @@ | ||
import createWindow from './create-window'; | ||
|
||
export { | ||
createWindow, | ||
}; |
Oops, something went wrong.