-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathWindows.js
More file actions
176 lines (158 loc) · 5.26 KB
/
Copy pathWindows.js
File metadata and controls
176 lines (158 loc) · 5.26 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
const { BrowserWindow, session, app } = require("electron");
const path = require("path");
const log = require("electron-log");
const { mediaHandler } = require("./utils");
// Windows Store detection
const isWindowsStore = process.env.WINDOWS_STORE === 'true' || process.env.STOREBUILD === 'true';
// Store versiyonunda electron-updater yükleme
let autoUpdater = null;
if (!isWindowsStore) {
try {
autoUpdater = require("electron-updater").autoUpdater;
} catch (error) {
console.log("electron-updater not available in Store version");
}
}
function createMainWindow(windowstate, url) {
let mainWindow = new BrowserWindow({
x: windowstate.x,
y: windowstate.y,
width: windowstate.width,
height: windowstate.height,
minWidth: 800,
minHeight: 600,
show: false,
frame: false,
backgroundColor: "#ffffff",
icon: path.join(__dirname, "topluyo.png"),
webPreferences: {
devTools: process.env.NODE_ENV === "development",
contextIsolation: false,
nodeIntegration: true,
nodeIntegrationInSubFrames: true,
preload: path.join(__dirname, "preloads/main.js"),
},
});
// Başlangıçta loading ekranı yükle
mainWindow.loadFile("loading.html");
mainWindow.once("ready-to-show", () => {
mainWindow.show();
});
if (windowstate) windowstate.manage(mainWindow);
if (!url) {
mainWindow.webContents.once("did-finish-load", () => {
// Store versiyonunda auto-updater çalıştırma
if (!isWindowsStore) {
checkForUpdatesAndLoad(mainWindow);
} else {
// Store versiyonunda direkt ana sayfayı yükle
mainWindow.loadURL("https://topluyo.com");
}
});
} else {
url = url.startsWith("/") ? url : `/${url}`;
mainWindow.loadURL("https://topluyo.com" + url);
}
mainWindow.webContents.on("did-fail-load", (e, code, desc) => {
console.error("Yükleme hatası:", code, desc);
});
session.defaultSession.setDisplayMediaRequestHandler(mediaHandler);
//mainWindow.webContents.openDevTools();
mainWindow.on("unresponsive", () => {
console.error("Ana pencere yanıt vermiyor.");
if (mainWindow && !mainWindow.isDestroyed()) {
mainWindow.webContents.send("update-message", "❗ Ana pencere yanıt vermiyor.");
}
});
mainWindow.on("closed", () => {
// Close all remaining child windows when main window is destroyed
BrowserWindow.getAllWindows().forEach(win => {
if (win !== mainWindow && !win.isDestroyed()) {
win.destroy();
}
});
mainWindow = null;
});
return mainWindow;
}
function checkForUpdatesAndLoad(mainWindow) {
// Desteklenmeyen ortamlarda (Store, development/paketlenmemiş veya AppImage olmayan Linux) güncellemeyi atla
if (
!autoUpdater ||
isWindowsStore ||
!app.isPackaged ||
(process.platform === "linux" && !process.env.APPIMAGE)
) {
console.log("Auto-updater not supported in this environment, loading main page...");
mainWindow.loadURL("https://topluyo.com");
return;
}
autoUpdater.logger = log;
autoUpdater.logger.transports.file.level = "info";
autoUpdater.autoDownload = true;
autoUpdater.autoInstallOnAppQuit = false;
autoUpdater.on("checking-for-update", () => {
console.log("Güncellemeler kontrol ediliyor...");
autoUpdater.logger = log;
autoUpdater.logger.transports.file.level = "info";
mainWindow.webContents.send(
"update-message",
"🔍 Güncellemeler kontrol ediliyor..."
);
});
autoUpdater.on("update-available", () => {
console.log("Güncellemeler kontrol ediliyor...");
autoUpdater.logger = log;
autoUpdater.logger.transports.file.level = "info";
mainWindow.webContents.send(
"update-message",
"✅ Güncelleme bulundu. İndiriliyor..."
);
});
autoUpdater.on("download-progress", (progressObj) => {
autoUpdater.logger = log;
autoUpdater.logger.transports.file.level = "info";
console.log("Güncellemeler kontrol ediliyor...");
mainWindow.webContents.send("download-progress", {
percent: progressObj.percent,
});
});
autoUpdater.on("update-downloaded", () => {
autoUpdater.logger = log;
autoUpdater.logger.transports.file.level = "info";
mainWindow.webContents.send(
"update-message",
"🎉 Güncelleme indirildi. Uygulama yeniden başlatılıyor..."
);
setTimeout(() => {
autoUpdater.quitAndInstall(true, true);
}, 2000);
});
autoUpdater.on("update-not-available", () => {
autoUpdater.logger = log;
autoUpdater.logger.transports.file.level = "info";
mainWindow.webContents.send(
"update-message",
"🚀 Güncel sürüm kullanılıyor."
);
setTimeout(() => {
mainWindow.loadURL("https://topluyo.com");
}, 1000);
});
autoUpdater.on("error", (err) => {
autoUpdater.logger = log;
autoUpdater.logger.transports.file.level = "info";
console.error("Güncelleme hatası:", err.message);
mainWindow.webContents.send(
"update-message",
`❌ Güncelleme hatası: ${err.message}`
);
setTimeout(() => {
mainWindow.loadURL("https://topluyo.com");
}, 2000);
});
autoUpdater.checkForUpdates();
//mainWindow.loadURL("https://topluyo.com");
}
exports.createMainWindow = createMainWindow;
exports.checkForUpdatesAndLoad = checkForUpdatesAndLoad;