-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.js
More file actions
92 lines (77 loc) · 3.21 KB
/
main.js
File metadata and controls
92 lines (77 loc) · 3.21 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
const { app, BrowserWindow } = require('electron');
const path = require('path');
const { fork } = require('child_process'); // Backend'i ayrı bir process'te çalıştırmak için
let mainWindow;
let serverProcess;
function createWindow() {
mainWindow = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: false, // Güvenlik için false önerilir
contextIsolation: true, // Güvenlik ve performans için true önerilir
preload: path.join(__dirname, 'preload.js') // İsteğe bağlı: Ön yükleme betiği
}
});
// Geliştirme modunda URL'yi veya production'da build edilmiş HTML'i yükle
// Dikkat: Client uygulamanız bir geliştirme sunucusu (örn. localhost:3000) kullanıyorsa burayı ona göre ayarlayın.
// Eğer client statik dosyalardan oluşuyorsa (build edildiyse):
mainWindow.loadFile(path.join(__dirname, 'client/build/index.html')); // Build edilmiş client yolu
// Şimdilik public içindeki index.html'i yükleyelim, build adımını sonra düşünürüz.
// mainWindow.loadFile(path.join(__dirname, 'client/public/index.html')); // Bu satır yorumlandı
// Geliştirici araçlarını aç (isteğe bağlı)
// mainWindow.webContents.openDevTools();
mainWindow.on('closed', function () {
mainWindow = null;
});
}
function startServer() {
// Backend sunucusunu ayrı bir process olarak başlat
// package.json'daki start script'ini kullanabiliriz
const backendPath = path.join(__dirname, 'backend', 'server.js');
serverProcess = fork(backendPath, [], {
// Gerekirse ortam değişkenleri veya diğer seçenekler eklenebilir
// cwd: path.join(__dirname, 'backend') // Eğer backend'in çalışma dizini farklıysa
});
serverProcess.on('message', (message) => {
console.log('Backend message:', message);
});
serverProcess.on('error', (err) => {
console.error('Backend error:', err);
});
serverProcess.on('exit', (code) => {
console.log(`Backend process exited with code ${code}`);
serverProcess = null; // Process sonlandığında referansı temizle
});
}
app.on('ready', () => {
startServer(); // Backend sunucusunu başlat
createWindow(); // Electron penceresini oluştur
});
app.on('window-all-closed', function () {
// macOS dışındaki tüm platformlarda, tüm pencereler kapatıldığında uygulamayı kapat
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('before-quit', () => {
// Uygulama kapanmadan önce backend process'ini sonlandır
if (serverProcess) {
console.log('Terminating backend process...');
serverProcess.kill();
}
});
app.on('activate', function () {
// macOS'ta, dock ikonu tıklandığında ve başka pencere açık değilse yeni pencere aç
if (mainWindow === null) {
createWindow();
}
});
// İsteğe bağlı: preload.js içeriği (Güvenlik için kullanılır)
// Bu dosya, renderer process'e güvenli bir şekilde Node.js API'lerini sunmak için kullanılır.
// Şimdilik boş veya temel bir preload.js oluşturabiliriz.
// console.log('Preload script loaded');
// const { contextBridge, ipcRenderer } = require('electron');
// contextBridge.exposeInMainWorld('electronAPI', {
// // Güvenli IPC fonksiyonları buraya eklenebilir
// });