Skip to content

Commit 7154aab

Browse files
Make user preferences persist between app start. (#56)
Fixed ACPU/BCPU tables Align to center table's content
1 parent 02e1ad9 commit 7154aab

File tree

6 files changed

+48
-20
lines changed

6 files changed

+48
-20
lines changed

main.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ const startFlaskServer = () => {
105105
});
106106

107107
apiServer.on('close', (code) => {
108-
console.log(`child process exited with code ${code}`);
108+
console.log(`serverProcess exited with code ${code}`);
109109
});
110110

111111
apiServer.on('message', (message) => {
@@ -115,7 +115,7 @@ const startFlaskServer = () => {
115115
return apiServer;
116116
};
117117

118-
let child = null;
118+
let serverProcess = null;
119119
const createWindow = () => {
120120
mainWindow = new BrowserWindow({
121121
width: 1200,
@@ -132,18 +132,26 @@ const createWindow = () => {
132132
const menu = Menu.buildFromTemplate(template);
133133
Menu.setApplicationMenu(menu);
134134

135+
mainWindow.webContents.on('did-finish-load', () => {
136+
mainWindow.webContents.send('loadConfig', store.store);
137+
});
138+
135139
ipcMain.on('config', (event, arg) => {
136140
store.set('port', arg.port);
137141
store.set('device_xml', arg.device_xml);
138142

139-
child.kill();
140-
child = startFlaskServer();
141-
mainWindow.reload();
143+
serverProcess.kill();
144+
145+
app.relaunch();
146+
app.quit();
147+
});
148+
ipcMain.on('getConfig', (event, arg) => {
149+
mainWindow.webContents.send('loadConfig', store.store);
142150
});
143151
};
144152

145153
app.whenReady().then(() => {
146-
child = startFlaskServer();
154+
serverProcess = startFlaskServer();
147155
createWindow();
148156

149157
app.on('activate', () => {
@@ -152,6 +160,6 @@ app.whenReady().then(() => {
152160
});
153161

154162
app.on('window-all-closed', () => {
155-
child.kill('SIGINT');
163+
serverProcess.kill('SIGINT');
156164
if (process.platform !== 'darwin') app.quit();
157165
});

src/App.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,17 @@ function App() {
4646
const [topLevel, setTopLevel] = React.useState('');
4747
const [config, setConfig] = React.useState({});
4848
const { toggleItemSelection } = useSelection();
49+
const [preferencesChanged, setPreferencesChanged] = React.useState(false);
4950

5051
const [isModalOpen, setIsModalOpen] = React.useState(false);
5152
const showModal = () => {
53+
setPreferencesChanged(false);
5254
setIsModalOpen(true);
5355
};
5456
const handleOk = () => {
55-
setIsModalOpen(false);
56-
window.ipcAPI.send('config', config);
57+
// this will restart app
58+
if (preferencesChanged) window.ipcAPI.send('config', config);
59+
else setIsModalOpen(false);
5760
};
5861
const handleCancel = () => {
5962
setIsModalOpen(false);
@@ -69,14 +72,17 @@ function App() {
6972
// eslint-disable-next-line react-hooks/exhaustive-deps
7073
}, [openedTable]);
7174

72-
React.useEffect(() => server.GET(server.devices, setDevices), []);
73-
7475
React.useEffect(() => {
76+
window.ipcAPI.send('getConfig');
7577
if ((typeof window !== 'undefined')) {
7678
window.ipcAPI.loadPreferences('preferences', (event, data) => {
7779
setConfig(data);
7880
showModal();
7981
});
82+
window.ipcAPI.loadPreferences('loadConfig', (event, data) => {
83+
setConfig(data);
84+
server.setPort(data.port, setDevices);
85+
});
8086
}
8187
}, []);
8288

@@ -119,6 +125,7 @@ function App() {
119125
};
120126

121127
const handleConfigChange = (name, val) => {
128+
setPreferencesChanged(true);
122129
setConfig({ ...config, [name]: val });
123130
};
124131

src/components/style/ACPUTable.css

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
padding-top: 0;
44
display: inline-flex;
55
gap: 10px;
6+
width: 100%;
67
}
78

89
.acpu-group {
@@ -21,13 +22,15 @@
2122
}
2223

2324
.cpu-container {
24-
display: inline-flex;
25+
display: flex;
26+
flex-direction: row;
2527
gap: 10px;
28+
width: 100%;
2629
}
2730

2831
.acpu-group-container {
2932
border-right: 1px solid var(--border-color);
3033
border-left: 1px solid var(--border-color);
3134
padding-right: 10px;
3235
padding-left: 10px;
33-
}
36+
}

src/components/style/ComponentTable.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
.table-style td {
2424
white-space: nowrap;
25+
text-align: center;
2526
}
2627

2728
.table-style tbody tr:hover {

src/components/style/DesignParametesTable.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
flex-direction: row;
44
column-gap: 10px;
55
padding: 10px;
6+
width: 100%;
67
}
78

89
.param-element-container input,

src/utils/serverAPI.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,24 @@ import { formatString } from './common';
33
const config = require('../../rpe.config.json');
44

55
const { server } = config;
6-
const { port } = config;
6+
let { port } = config;
77

8-
export const devices = formatString('{0}:{1}/devices', server, port);
8+
export function devices() { return formatString('{0}:{1}/devices', server, port); }
9+
10+
export function setPort(p, fetchDevices) {
11+
if (p !== undefined) {
12+
port = p;
13+
// eslint-disable-next-line no-use-before-define
14+
GET(devices(), fetchDevices);
15+
}
16+
}
917

1018
export function peripheralPath(deviceId, url) {
11-
return formatString('{0}/{1}/peripherals/{2}', devices, deviceId, url);
19+
return formatString('{0}/{1}/peripherals/{2}', devices(), deviceId, url);
1220
}
1321

1422
export function deviceInfo(deviceId) {
15-
return formatString('{0}/{1}', devices, deviceId);
23+
return formatString('{0}/{1}', devices(), deviceId);
1624
}
1725

1826
export const Elem = {
@@ -26,15 +34,15 @@ export const Elem = {
2634

2735
export const api = {
2836
fetch(func, deviceId) {
29-
return formatString('{0}/{1}/{2}', devices, deviceId, func);
37+
return formatString('{0}/{1}/{2}', devices(), deviceId, func);
3038
},
3139

3240
consumption(func, deviceId) {
33-
return formatString('{0}/{1}/{2}/consumption', devices, deviceId, func);
41+
return formatString('{0}/{1}/{2}/consumption', devices(), deviceId, func);
3442
},
3543

3644
index(func, deviceId, index) {
37-
return formatString('{0}/{1}/{2}/{3}', devices, deviceId, func, index);
45+
return formatString('{0}/{1}/{2}/{3}', devices(), deviceId, func, index);
3846
},
3947
};
4048

0 commit comments

Comments
 (0)