-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmain.js
More file actions
475 lines (420 loc) · 16.2 KB
/
Copy pathmain.js
File metadata and controls
475 lines (420 loc) · 16.2 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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
const { app, BrowserWindow, ipcMain, shell, dialog } = require("electron");
const windowStateKeeper = require("electron-window-state");
const { createMainWindow } = require("./Windows");
const { openExternalLinks, ossWindow } = require("./utils");
const fs = require("fs");
const path = require("path");
let captureModule = null;
try {
captureModule = require("./native/topluyo-capture");
} catch (e) {
console.log("Native capture module not available yet:", e.message);
}
// Windows Store detection
const isWindowsStore = process.env.WINDOWS_STORE === 'true' || process.windowsStore || false;
// Store versiyonu için error handling
if (isWindowsStore) {
process.on('uncaughtException', (error) => {
console.log('Uncaught Exception in Store version:', error);
// Store versiyonunda uygulamayı crash etme
return;
});
process.on('unhandledRejection', (reason, promise) => {
console.log('Unhandled Rejection in Store version:', reason);
// Store versiyonunda uygulamayı crash etme
return;
});
}
let mainWindow = null;
let deeplinkingUrl = null;
const gotLock = app.requestSingleInstanceLock();
if (process.platform === "linux") {
app.disableHardwareAcceleration();
app.commandLine.appendSwitch("disable-gpu");
app.commandLine.appendSwitch("disable-software-rasterizer");
app.commandLine.appendSwitch("no-sandbox");
}
if (process.platform === "win32") {
if (process.defaultApp) {
if (process.argv.length >= 2) {
app.setAsDefaultProtocolClient("topluyo", process.execPath, [
path.resolve(process.argv[1]),
]);
}
} else {
app.setAsDefaultProtocolClient("topluyo");
}
} else if (process.platform === "linux" && !isWindowsStore) {
// Store versiyonunda Linux script'i çalıştırma
try {
require("./linuxscript");
} catch (error) {
console.log('Linux script not available:', error.message);
}
}
if (!gotLock) {
app.quit();
process.exit(0);
} else {
app.on("second-instance", (event, commandLine) => {
// Windows ve Linux için URL'yi al
const url = commandLine.find((arg) => arg.startsWith("topluyo://"));
if (url) {
deeplinkingUrl = url;
if (mainWindow) {
mainWindow.show();
mainWindow.focus();
mainWindow.loadURL(
"https://topluyo.com" + url.replace("topluyo://", "/")
);
}
}
});
}
app.whenReady().then(() => {
//* Load the previous state with fallback to defaults
const mainWindowState = windowStateKeeper({
defaultWidth: 800,
defaultHeight: 600,
});
const initialUrlArg = process.argv.find((arg) =>
arg.startsWith("topluyo://")
);
if (initialUrlArg) {
deeplinkingUrl = initialUrlArg;
}
mainWindow = createMainWindow(
mainWindowState,
deeplinkingUrl ? deeplinkingUrl.replace("topluyo://", "/") : null
);
//* url handler
mainWindow.webContents.setWindowOpenHandler(({ url }) => {
openExternalLinks(url);
// if (isSafeUrl(url)) {
// mainWindow.loadURL(url.replace("https://topluyo.com/", "/"));
// return { action: "deny" };
// } else if (url.startsWith("topluyo://")) {
// mainWindow.loadURL(url.replace("https://topluyo.com/", "/"));
// return { action: "deny" };
// } else if (url.startsWith("javascript:")) {
// return { action: "deny" };
// } else {
// const parsedUrl = new URL(url);
// if (parsedUrl.search && parsedUrl.search.includes("!login")) {
// shell.openExternal(url);
// } else {
// dialog
// .showMessageBox({
// type: "warning",
// buttons: ["Evet", "Hayır"],
// defaultId: 1,
// cancelId: 1,
// title: "Dış Bağlantı Açılıyor",
// message: "Bu bağlantıyı açmak istiyor musunuz?\n" + url,
// })
// .then((response) => {
// if (response.response === 0) {
// openExternalLinks(url);
// }
// });
// }
// return { action: "deny" };
//}
});
});
if (process.platform === "darwin") {
app.on("open-url", (event, url) => {
event.preventDefault();
deeplinkingUrl = url;
if (mainWindow) {
mainWindow.show();
mainWindow.focus();
mainWindow.loadURL(
"https://topluyo.com" + url.replace("topluyo://", "/")
);
}
});
}
app.on("window-all-closed", function () {
if (process.platform === "win32") {
app.quit();
} else {
app.exit();
}
});
ipcMain.on("open-oss", () => {
ossWindow();
});
// OSS kütüphanelerini al
ipcMain.handle("get-oss-libraries", async () => {
try {
const packageJsonPath = path.join(__dirname, "package.json");
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
const libraries = [];
// Lisans dosyasını okuma fonksiyonu
const readLicenseFile = (packagePath) => {
const possibleLicenseFiles = [
'LICENSE',
'LICENSE.txt',
'LICENSE.md',
'LICENCE',
'LICENCE.txt',
'LICENCE.md',
'license',
'license.txt',
'license.md'
];
for (const fileName of possibleLicenseFiles) {
const licensePath = path.join(packagePath, fileName);
if (fs.existsSync(licensePath)) {
try {
return fs.readFileSync(licensePath, 'utf8').trim();
} catch (error) {
console.error(`Error reading license file ${licensePath}:`, error);
}
}
}
return null;
};
// Ana uygulama bilgisi
const mainLicenseText = readLicenseFile(__dirname);
libraries.push({
name: packageJson.name,
version: packageJson.version,
description: packageJson.description || "Topluyo Desktop Uygulaması",
license: packageJson.license || "MIT",
licenseText: mainLicenseText,
homepage: "https://topluyo.com",
repository: null
});
// Dependencies
if (packageJson.dependencies) {
for (const [name, version] of Object.entries(packageJson.dependencies)) {
try {
const depPackagePath = path.join(__dirname, "node_modules", name);
const depPackageJsonPath = path.join(depPackagePath, "package.json");
if (fs.existsSync(depPackageJsonPath)) {
const depPackage = JSON.parse(fs.readFileSync(depPackageJsonPath, 'utf8'));
const licenseText = readLicenseFile(depPackagePath);
libraries.push({
name: depPackage.name,
version: depPackage.version,
description: depPackage.description || `${name} kütüphanesi`,
license: depPackage.license || "Belirtilmemiş",
licenseText: licenseText,
homepage: depPackage.homepage || null,
repository: depPackage.repository?.url || depPackage.repository || null
});
} else {
// Paket dosyası yoksa temel bilgilerle ekle
libraries.push({
name: name,
version: version.replace(/[\^~>=<]/, ''),
description: `${name} kütüphanesi`,
license: "Belirtilmemiş",
licenseText: null,
homepage: null,
repository: null
});
}
} catch (error) {
console.error(`Error reading package info for ${name}:`, error);
}
}
}
// DevDependencies (sadece production'da değilse)
if (packageJson.devDependencies && process.env.NODE_ENV === 'development') {
for (const [name, version] of Object.entries(packageJson.devDependencies)) {
try {
const depPackagePath = path.join(__dirname, "node_modules", name);
const depPackageJsonPath = path.join(depPackagePath, "package.json");
if (fs.existsSync(depPackageJsonPath)) {
const depPackage = JSON.parse(fs.readFileSync(depPackageJsonPath, 'utf8'));
const licenseText = readLicenseFile(depPackagePath);
libraries.push({
name: depPackage.name + " (dev)",
version: depPackage.version,
description: depPackage.description || `${name} geliştirme kütüphanesi`,
license: depPackage.license || "Belirtilmemiş",
licenseText: licenseText,
homepage: depPackage.homepage || null,
repository: depPackage.repository?.url || depPackage.repository || null
});
}
} catch (error) {
console.error(`Error reading dev package info for ${name}:`, error);
}
}
}
// Electron ve Node.js gibi sistem bileşenleri
libraries.push({
name: "Electron",
version: process.versions.electron,
description: "Cross-platform desktop uygulamaları geliştirmek için kullanılan framework. Chromium ve Node.js teknolojilerini bir araya getirir.",
license: "MIT",
licenseText: `MIT License
Copyright (c) Electron contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.`,
homepage: "https://electronjs.org",
repository: "https://github.com/electron/electron"
});
libraries.push({
name: "Node.js",
version: process.versions.node,
description: "JavaScript runtime ortamı. Electron uygulamalarının backend işlemlerini yürütür.",
license: "MIT",
licenseText: `MIT License
Copyright Node.js contributors. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.`,
homepage: "https://nodejs.org",
repository: "https://github.com/nodejs/node"
});
libraries.push({
name: "Chromium",
version: process.versions.chrome,
description: "Electron'un temelini oluşturan açık kaynak web tarayıcı projesi. Web içeriklerinin render edilmesi için kullanılır.",
license: "BSD-3-Clause",
licenseText: `BSD 3-Clause License
Copyright (c) The Chromium Authors. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.`,
homepage: "https://www.chromium.org",
repository: "https://chromium.googlesource.com/chromium/src/"
});
return libraries;
} catch (error) {
console.error("Error reading OSS libraries:", error);
throw error;
}
});
// Harici link açma
ipcMain.handle("open-external", async (_, url) => {
shell.openExternal(url);
});
ipcMain.on("minimize", () => {
BrowserWindow.getFocusedWindow().minimize();
});
ipcMain.on("maximize", () => {
const focusedWindow = BrowserWindow.getFocusedWindow();
if (focusedWindow.isMaximized()) {
focusedWindow.unmaximize();
} else {
focusedWindow.maximize();
}
});
ipcMain.on("close", () => {
BrowserWindow.getFocusedWindow().close();
});
ipcMain.handle("start-native-audio", (event) => {
const sourceId = global.lastSelectedSource || "";
console.log("start-native-audio invoked. Selected source:", sourceId);
if (process.platform === "linux") {
try {
const { setupLinuxAudio } = require('./linux-audio');
return setupLinuxAudio(sourceId);
} catch (e) {
console.error(e);
return false;
}
}
if (process.platform === "darwin") {
return false; // macOS için direkt web apilerine bırak
}
if (!captureModule) return false;
// Find the actual Audio Service PID to exclude Topluyo's audio perfectly
const { app } = require('electron');
const metrics = app.getAppMetrics();
const audioService = metrics.find(m => m.type === 'Utility' && m.name === 'Audio Service');
let targetPid = audioService ? audioService.pid : process.pid;
let isIncludeMode = false; // Default: Exclude Topluyo (Screen Share)
if (sourceId.startsWith("window:")) {
// e.g., "window:1575868:0"
const parts = sourceId.split(":");
if (parts.length >= 2) {
const hwnd = parseInt(parts[1], 10);
const pid = captureModule.getPidFromHwnd(hwnd);
if (pid > 0) {
targetPid = pid;
isIncludeMode = true; // Only capture this application
console.log(`Window Capture Mode: HWND=${hwnd}, PID=${pid}. We will ONLY capture this app's audio.`);
}
}
} else {
console.log(`Screen Capture Mode: Excluding Topluyo PID=${targetPid} to prevent echo.`);
}
captureModule.stopCapture();
try {
return captureModule.startCapture(targetPid, isIncludeMode, (buffer, meta) => {
try {
if (event.senderFrame && !event.senderFrame.isDestroyed()) {
event.senderFrame.send("native-audio-data", buffer, meta);
} else if (event.sender && !event.sender.isDestroyed()) {
event.sender.send("native-audio-data", buffer, meta);
}
} catch (e) {
// Ignore if sender is destroyed
}
});
} catch (err) {
console.error("Native WASAPI failed to start:", err);
return false; // Tells preload.js to fallback to Electron loopback
}
});
ipcMain.handle("stop-native-audio", () => {
if (process.platform === "linux") {
try {
const { cleanupLinuxAudio } = require('./linux-audio');
cleanupLinuxAudio();
} catch (e) {}
}
if (captureModule) {
captureModule.stopCapture();
}
return true;
});