Skip to content

Commit

Permalink
Merge pull request aces#38 from maltheism/main_login_component
Browse files Browse the repository at this point in the history
Main login component and cleanup
  • Loading branch information
maltheism authored Jun 28, 2021
2 parents baf60f6 + 573e0cc commit ea1f9e9
Show file tree
Hide file tree
Showing 11 changed files with 468 additions and 95 deletions.
18 changes: 12 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
{
"name": "eeg2bids",
"description": "EEG/iEEG to BIDS format Wizard",
"version": "1.0.0",
"version": "1.0.1",
"dependencies": {
"@electron/remote": "^1.1.0",
"electron-log": "^4.3.5",
"electron-store": "^8.0.0",
"keytar": "^7.7.0",
"prop-types": "^15.7.2",
"react": "^17.0.2",
"react-color": "^2.19.3",
"react-datepicker": "^4.1.1",
"react-dom": "^17.0.2",
"react-router-dom": "^5.2.0",
"react-scripts": "^4.0.2",
"react-switch": "^6.0.0",
"socket.io-client": "^4.1.2"
},
"devDependencies": {
Expand All @@ -30,9 +33,7 @@
"eslint-plugin-jsx-a11y": "^6.4.1",
"eslint-plugin-react": "^7.24.0",
"lint-staged": "^11.0.0",
"react-datepicker": "^4.1.1",
"react-switch": "^6.0.0",
"wait-on": "^5.3.0"
"wait-on": "^6.0.0"
},
"scripts": {
"rebuild": "rebuild --runtime=electron --target=11.2.1",
Expand Down Expand Up @@ -68,9 +69,14 @@
"not ie <= 11",
"not op_mini all"
],
"contributors": [
"Alizée Wickenheiser",
"Christine Rogers",
"Laëtitia Fesselier"
],
"author": {
"name": "Alizée Wickenheiser",
"email": "alizee.wickenheiser@mcgill.ca",
"name": "Loris Team",
"email": "[email protected].mcgill.ca",
"url": "https://github.com/aces/eeg2bids"
},
"build": {
Expand Down
36 changes: 36 additions & 0 deletions public/electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,42 @@ app.on('ready', async () => {
createSettingsWindow();
}
});
ipcMain.on('setLorisAuthenticationCredentials',
async (event, credentials) => {
const keytar = require('keytar');
// Delete all old credentials
const services = await keytar.findCredentials('EEG2BIDS');
for (const service of services) {
await keytar.deletePassword('EEG2BIDS', service.account);
}
// Set new credentials (secure)
await keytar.setPassword(
'EEG2BIDS',
credentials.lorisUsername,
credentials.lorisPassword,
);
// Set lorisURL in electron-store (not secure)
const Store = require('electron-store');
const schema = {
lorisURL: {
type: 'string',
format: 'url',
},
};
const store = new Store({schema});
store.set('lorisURL', credentials.lorisURL);
});
ipcMain.handle('getLorisAuthenticationCredentials', async (event, arg) => {
const keytar = require('keytar');
const credentials = await keytar.findCredentials('EEG2BIDS');
const Store = require('electron-store');
const store = new Store();
return {
lorisURL: store.get('lorisURL') ?? '',
lorisUsername: credentials[0] ? credentials[0].account : '',
lorisPassword: credentials[0] ? credentials[0].password : '',
};
});
});

app.on('window-all-closed', () => {
Expand Down
2 changes: 1 addition & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html lang="en">
<head>
<meta charset="utf-8" />
<meta http-equiv="Content-Security-Policy" content="script-src 'self';">
<meta http-equiv="Content-Security-Policy" content="script-src 'unsafe-inline' 'self';">
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
Expand Down
15 changes: 15 additions & 0 deletions public/preload.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
const {contextBridge} = require('electron');

/**
* contextBridge should be cautious of security risk.
*/
contextBridge.exposeInMainWorld('myAPI', {
dialog: () => {
const {dialog} = require('@electron/remote');
Expand All @@ -25,6 +28,18 @@ contextBridge.exposeInMainWorld('myAPI', {
const {shell} = require('electron');
shell.openExternal('https://mcin.ca');
},
getLorisAuthenticationCredentials: async () => {
const ipcRenderer = require('electron').ipcRenderer;
const credentials = await ipcRenderer.invoke(
'getLorisAuthenticationCredentials',
null,
);
return credentials;
},
setLorisAuthenticationCredentials: (credentials) => {
const ipcRenderer = require('electron').ipcRenderer;
ipcRenderer.send('setLorisAuthenticationCredentials', credentials);
},
openSettings: () => {
const ipcRenderer = require('electron').ipcRenderer;
ipcRenderer.send('openSettingsWindow', null);
Expand Down
42 changes: 36 additions & 6 deletions python/eeg2bids.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,24 @@
from python.libs.loris_api import LorisAPI
import csv

# EEG2BIDS Wizard version
appVersion = '1.0.1'

# LORIS credentials of user
lorisCredentials = {
'lorisURL': '',
'lorisUsername': '',
'lorisPassword': '',
}

# Create socket listener.
sio = socketio.Server(async_mode='eventlet', cors_allowed_origins=[])
app = socketio.WSGIApp(sio)
loris_api = LorisAPI()

# EEG2BIDS Wizard version
appVersion = '1.0.0'

# Create Loris API handler.
loris_api = LorisAPI()


@sio.event
Expand All @@ -27,8 +38,8 @@ def connect(sid, environ):
def tarfile_bids_thread(data):
iEEG.TarFile(data)
response = {
'compression_time': 'example_5mins'
}
'compression_time': 'example_5mins'
}
return eventlet.tpool.Proxy(response)


Expand All @@ -40,29 +51,46 @@ def tarfile_bids(sid, data):
print('response received!')
print(response)
send = {
'compression_time': response['compression_time']
}
'compression_time': response['compression_time']
}
print('send received!')
print(send)
sio.emit('response', send)


@sio.event
def set_loris_credentials(sid, data):
print('set_loris_credentials:', data)
lorisCredentials = data
if lorisCredentials.lorisURL.endswith('/'):
lorisCredentials.lorisURL = lorisCredentials.lorisURL[:-1]
loris_api.url = lorisCredentials.lorisURL + '/api/v0.0.4-dev/'
loris_api.username = lorisCredentials.lorisUsername
loris_api.password = lorisCredentials.lorisPassword
loris_api.login()
sio.emit('loris_sites', loris_api.get_sites())
sio.emit('loris_projects', loris_api.get_projects())


def get_loris_sites(sid):
sio.emit('loris_sites', loris_api.get_sites())


@sio.event
def get_loris_projects(sid):
sio.emit('loris_projects', loris_api.get_projects())


@sio.event
def get_loris_subprojects(sid, project):
sio.emit('loris_subprojects', loris_api.get_subprojects(project))


@sio.event
def get_loris_visits(sid, project):
sio.emit('loris_visits', loris_api.get_visits(project))


@sio.event
def ieeg_get_header(sid, data):
# data = { file_path: 'path to iEEG file' }
Expand All @@ -80,6 +108,7 @@ def ieeg_get_header(sid, data):
}
sio.emit('edf_header', response)


@sio.event
def get_metadata(sid, data):
# data = { file_path: 'path to metadata file' }
Expand All @@ -105,6 +134,7 @@ def get_metadata(sid, data):

sio.emit('metadata', response)


def edf_to_bids_thread(data):
print('data is ')
print(data)
Expand Down
Loading

0 comments on commit ea1f9e9

Please sign in to comment.