Skip to content
This repository was archived by the owner on Jan 8, 2022. It is now read-only.

Commit 481ce63

Browse files
jrschumacheregoist
authored andcommitted
Add login support (#72)
1 parent 1c41a4f commit 481ce63

File tree

8 files changed

+115
-4
lines changed

8 files changed

+115
-4
lines changed

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,3 @@ npm run dist
4848
## License
4949

5050
MIT © [EGOIST](https://github.com/egoist)
51-
52-

app/index.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
const path = require('path')
22
const { app, BrowserWindow, Menu } = require('electron')
3+
const debug = require('debug')('devdocs-desktop:index')
34
const createMenu = require('./menu')
45
const config = require('./config')
56
const tray = require('./tray')
67
const updater = require('./updater')
78
const { toggleGlobalShortcut } = require('./utils')
9+
const login = require('./login')
810

911
require('electron-debug')()
1012
require('electron-context-menu')({
@@ -78,6 +80,12 @@ function createMainWindow() {
7880
return win
7981
}
8082

83+
app.on('login', (event, webContents, request, authInfo, cb) => {
84+
debug('app.on(login)')
85+
event.preventDefault()
86+
login(cb)
87+
})
88+
8189
app.on('ready', () => {
8290
const shortcut = config.get('shortcut')
8391
for (const name in shortcut) {

app/login.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const { BrowserWindow, ipcMain } = require('electron')
2+
const path = require('path')
3+
const debug = require('debug')('devdocs-desktop:login')
4+
5+
module.exports = cb => {
6+
debug('Login launching...')
7+
const loginWindow = new BrowserWindow({
8+
width: 300,
9+
height: 300,
10+
frame: false,
11+
resizable: false
12+
})
13+
loginWindow.loadURL(`file://${path.join(__dirname, '/renderer/login.html')}`)
14+
15+
ipcMain.once('login-message', (event, usernameAndPassword) => {
16+
debug('Login message recieved', usernameAndPassword[0])
17+
cb(usernameAndPassword[0], usernameAndPassword[1])
18+
loginWindow.close()
19+
})
20+
return loginWindow
21+
}

app/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"homepage": "https://github.com/egoist/devdocs-desktop#readme",
3030
"dependencies": {
3131
"axios": "^0.16.2",
32+
"debug": "^3.1.0",
3233
"electron-context-menu": "^0.9.1",
3334
"electron-debug": "^1.1.0",
3435
"electron-is-dev": "^0.1.2",

app/renderer/login.css

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
2+
* {
3+
font-family: Verdana, sans-serif;
4+
}
5+
6+
html, body {
7+
height: 100%;
8+
margin: 0;
9+
-webkit-app-region: drag;
10+
background: #fff;
11+
}
12+
.login-form {
13+
height: 100%;
14+
display: flex;
15+
flex-direction: column;
16+
justify-content: center;
17+
align-items: center;
18+
}
19+
20+
.login-form > div {
21+
text-align: center;
22+
}
23+
24+
.login-form .input-div {
25+
margin: 5px;
26+
}
27+
28+
.login-form > div > input {
29+
display: block;
30+
height: 30px;
31+
width: 250px;
32+
margin: 10px;
33+
padding: 10px;
34+
text-align: center;
35+
font-size: 16px;
36+
-webkit-app-region: no-drag;
37+
}
38+
39+
.login-form > div > button {
40+
border: 0;
41+
font-size: 15px;
42+
font-weight: 100;
43+
text-transform: uppercase;
44+
height: 50px;
45+
width: 274px;
46+
background-color: #2196F3;
47+
color: white;
48+
-webkit-app-region: no-drag;
49+
}
50+
51+
button:hover {
52+
background-color: #0D47A1;
53+
}

app/renderer/login.html

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="UTF-8" />
5+
<title>Login Prompt</title>
6+
<link rel="stylesheet" href="./login.css">
7+
</head>
8+
<body>
9+
<form id="login-form" class="login-form">
10+
<div class="input-div">
11+
<input id="username-input" type="text" autofocus placeholder="Username" />
12+
<input id="password-input" type="password" placeholder="Password" />
13+
</div>
14+
<div>
15+
<button id="submit-form-button" type="submit">Login</button>
16+
</div>
17+
</form>
18+
<script src="./login.js"></script>
19+
</body>
20+
</html>

app/renderer/login.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const { ipcRenderer } = require('electron')
2+
3+
document.getElementById('login-form').addEventListener('submit', event => {
4+
event.preventDefault()
5+
ipcRenderer.send('login-message', [
6+
document.getElementById('username-input').value,
7+
document.getElementById('password-input').value
8+
])
9+
})

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"postinstall": "electron-builder install-app-deps",
1515
"test": "npm run lint",
1616
"lint": "xo",
17-
"app": "electron app/index.js",
17+
"app": "DEBUG=devdocs-desktop:* electron app/index.js",
1818
"pack": "build --dir",
1919
"dist": "build",
2020
"release": "build"
@@ -47,7 +47,8 @@
4747
"browser"
4848
],
4949
"rules": {
50-
"guard-for-in": 0
50+
"guard-for-in": 0,
51+
"max-params": ["error", 5]
5152
}
5253
},
5354
"build": {

0 commit comments

Comments
 (0)