diff options
Diffstat (limited to 'src/features/basicAuth/index.js')
-rw-r--r-- | src/features/basicAuth/index.js | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/src/features/basicAuth/index.js b/src/features/basicAuth/index.js new file mode 100644 index 000000000..03269582c --- /dev/null +++ b/src/features/basicAuth/index.js | |||
@@ -0,0 +1,68 @@ | |||
1 | import { ipcRenderer } from 'electron'; | ||
2 | import { observable } from 'mobx'; | ||
3 | |||
4 | import BasicAuthComponent from './Component'; | ||
5 | |||
6 | const debug = require('debug')('Franz:feature:basicAuth'); | ||
7 | |||
8 | const defaultState = { | ||
9 | isModalVisible: false, | ||
10 | service: null, | ||
11 | authInfo: null, | ||
12 | }; | ||
13 | |||
14 | export const state = observable(defaultState); | ||
15 | |||
16 | export function resetState() { | ||
17 | Object.assign(state, defaultState); | ||
18 | console.log('reset state', state); | ||
19 | } | ||
20 | |||
21 | export default function initialize() { | ||
22 | debug('Initialize basicAuth feature'); | ||
23 | |||
24 | window.franz.features.basicAuth = { | ||
25 | state, | ||
26 | }; | ||
27 | |||
28 | ipcRenderer.on('feature:basic-auth-request', (e, data) => { | ||
29 | debug(e, data); | ||
30 | // state.serviceId = data.serviceId; | ||
31 | state.authInfo = data.authInfo; | ||
32 | state.isModalVisible = true; | ||
33 | }); | ||
34 | |||
35 | // autorun(() => { | ||
36 | // // if (state.serviceId) { | ||
37 | // // const service = stores.services.one(state.serviceId); | ||
38 | // // if (service) { | ||
39 | // // state.service = service; | ||
40 | // // } | ||
41 | // // } | ||
42 | // }); | ||
43 | } | ||
44 | |||
45 | export function mainIpcHandler(mainWindow, authInfo) { | ||
46 | debug('Sending basic auth call', authInfo); | ||
47 | |||
48 | mainWindow.webContents.send('feature:basic-auth-request', { | ||
49 | authInfo, | ||
50 | }); | ||
51 | } | ||
52 | |||
53 | export function sendCredentials(user, password) { | ||
54 | debug('Sending credentials to main', user, password); | ||
55 | |||
56 | ipcRenderer.send('feature-basic-auth-credentials', { | ||
57 | user, | ||
58 | password, | ||
59 | }); | ||
60 | } | ||
61 | |||
62 | export function cancelLogin() { | ||
63 | debug('Cancel basic auth event'); | ||
64 | |||
65 | ipcRenderer.send('feature-basic-auth-cancel'); | ||
66 | } | ||
67 | |||
68 | export const Component = BasicAuthComponent; | ||