-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
110 lines (89 loc) · 2.84 KB
/
Copy pathmain.js
File metadata and controls
110 lines (89 loc) · 2.84 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
const { app, BrowserWindow, ipcMain } = require('electron');
const path = require('path');
const BotManager = require('./bot.js');
let mainWindow;
let botManager;
function createWindow() {
// Create the browser window.
mainWindow = new BrowserWindow({
width: 1200,
height: 800,
webPreferences: {
nodeIntegration: false,
contextIsolation: true,
enableRemoteModule: false,
preload: path.join(__dirname, 'preload.js') // We'll create this for secure IPC
},
title: 'Local Bot Client',
icon: path.join(__dirname, 'assets', 'icon.png') // Optional icon
});
// Load the app's index.html
mainWindow.loadFile('index.html');
// Open DevTools in development
if (process.env.NODE_ENV === 'development') {
mainWindow.webContents.openDevTools();
}
// Initialize bot manager
botManager = new BotManager();
botManager.init();
// Handle window closed
mainWindow.on('closed', () => {
mainWindow = null;
if (botManager) {
botManager.cleanup();
}
});
}
// App event listeners
app.whenReady().then(createWindow);
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});
// IPC handlers for communication with renderer
ipcMain.handle('get-guilds', async () => {
return botManager.getGuilds();
});
ipcMain.handle('get-channels', async (event, guildId) => {
return botManager.getChannels(guildId);
});
ipcMain.handle('send-message', async (event, channelId, message) => {
return botManager.sendMessage(channelId, message);
});
ipcMain.handle('get-logs', () => {
return botManager.getLogs();
});
ipcMain.handle('get-bots', () => {
return botManager.getBotConfigs();
});
ipcMain.handle('switch-bot', (event, botId) => {
botManager.switchBot(botId);
});
ipcMain.handle('reconnect-bot', () => {
botManager.reconnect();
});
ipcMain.handle('save-bot-config', async (event, token, name) => {
return botManager.saveBotConfig(token, name);
});
ipcMain.handle('get-stored-tokens', async () => {
return botManager.getStoredTokens();
});
ipcMain.handle('clear-all-data', async () => {
return botManager.clearAllData();
});
ipcMain.handle('start-discord-oauth', async () => {
// For desktop app, open browser for OAuth
const { shell } = require('electron');
const clientId = process.env.DISCORD_CLIENT_ID || 'YOUR_DISCORD_CLIENT_ID';
const redirectUri = encodeURIComponent('http://localhost:3000/oauth/callback');
const scope = 'identify';
const oauthUrl = `https://discord.com/api/oauth2/authorize?client_id=${clientId}&redirect_uri=${redirectUri}&response_type=code&scope=${scope}`;
shell.openExternal(oauthUrl);
return true;
});