aboutsummaryrefslogtreecommitdiffstats
path: root/src/features/basicAuth/index.js
blob: 99abf0d11e8e87200002c620f962654f9346c836 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import { ipcRenderer } from 'electron';
import { observable } from 'mobx';

import BasicAuthComponent from './Component';

const debug = require('debug')('Franz:feature:basicAuth');

const defaultState = {
  isModalVisible: false,
  service: null,
  authInfo: null,
};

export const state = observable(defaultState);

export function resetState() {
  Object.assign(state, defaultState);
  console.log('reset state', state);
}

export default function initialize(stores) {
  debug('Initialize basicAuth feature');

  window.franz.features.basicAuth = {
    state,
  };

  ipcRenderer.on('feature:basic-auth-request', (e, data) => {
    debug(e, data);
    // state.serviceId = data.serviceId;
    state.authInfo = data.authInfo;
    state.isModalVisible = true;
  });

  // autorun(() => {
  //   // if (state.serviceId) {
  //   // const service = stores.services.one(state.serviceId);
  //   // if (service) {
  //   //   state.service = service;
  //   // }
  //   // }
  // });
}

export function mainIpcHandler(mainWindow, authInfo) {
  debug('Sending basic auth call', authInfo);

  mainWindow.webContents.send('feature:basic-auth-request', {
    authInfo,
  });
}

export function sendCredentials(user, password) {
  debug('Sending credentials to main', user, password);

  ipcRenderer.send('feature-basic-auth-credentials', {
    user,
    password,
  });
}

export function cancelLogin() {
  debug('Cancel basic auth event');

  ipcRenderer.send('feature-basic-auth-cancel');
}

export const Component = BasicAuthComponent;