-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
123 lines (101 loc) · 3.34 KB
/
main.js
File metadata and controls
123 lines (101 loc) · 3.34 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
const { app, BrowserWindow, ipcMain } = require('electron')
const db = require('./database.js')
let win;
function createWindow () {
win = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: true,
contextIsolation: false
}
})
win.loadFile('index.html')
}
app.whenReady().then(createWindow)
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit()
}
})
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow()
}
})
const embyManager = require('./emby-manager.js');
let nextPort = 8096;
let currentUser = null;
ipcMain.on('login-user', (event, args) => {
const user = db.getUser(args.username);
if (user && user.password === args.password) {
// Check for expiration, but allow admin to always log in
if (user.role !== 'admin' && user.access_expires_at && new Date(user.access_expires_at) < new Date()) {
console.log(`Benutzerkonto für ${user.username} ist abgelaufen.`);
return;
}
currentUser = user;
if (user.role === 'admin') {
event.sender.send('login-success-admin', user);
} else {
event.sender.send('login-success', user);
}
} else {
console.log('Ungültiger Benutzername oder ungültiges Passwort');
}
});
ipcMain.on('get-all-users', (event) => {
const users = db.getAllUsers();
event.sender.send('all-users-data', users);
});
ipcMain.on('create-user', (event, args) => {
const { username, password, duration } = args;
const embyPort = nextPort++;
const expirationDate = new Date();
expirationDate.setDate(expirationDate.getDate() + parseInt(duration, 10));
db.addUser(username, password, embyPort, expirationDate.toISOString());
embyManager.createEmbyInstance(username, embyPort);
const users = db.getAllUsers();
event.sender.send('all-users-data', users);
});
ipcMain.on('delete-user', (event, userId) => {
// Note: In a real app, we should verify that the sender is an admin.
const userToDelete = db.getAllUsers().find(u => u.id === userId);
if (userToDelete) {
db.deleteUser(userToDelete.username);
// In a real app, you might want to clean up the user's data directory as well.
}
// Refresh user list
const users = db.getAllUsers();
event.sender.send('all-users-data', users);
});
ipcMain.on('start-emby', () => {
if (currentUser) {
embyManager.startEmby(currentUser.username, currentUser.emby_port);
win.webContents.send('emby-status-changed', 'Läuft');
}
});
// Admin controls
ipcMain.on('admin-restart-emby', (event, username) => {
const user = db.getAllUsers().find(u => u.username === username);
if (user) {
embyManager.restartEmby(user.username, user.emby_port);
}
// Notify to refresh statuses
event.sender.send('all-server-statuses-data', embyManager.getAllServerStatuses());
});
ipcMain.on('get-all-server-statuses', (event) => {
event.sender.send('all-server-statuses-data', embyManager.getAllServerStatuses());
});
ipcMain.on('stop-emby', () => {
if (currentUser) {
embyManager.stopEmby(currentUser.username);
win.webContents.send('emby-status-changed', 'Gestoppt');
}
});
ipcMain.on('restart-emby', () => {
if (currentUser) {
embyManager.restartEmby(currentUser.username, currentUser.emby_port);
win.webContents.send('emby-status-changed', 'Läuft');
}
});