-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathutils.js
More file actions
122 lines (111 loc) · 2.75 KB
/
utils.js
File metadata and controls
122 lines (111 loc) · 2.75 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
const {
ipcMain,
desktopCapturer,
BrowserWindow,
dialog,
app,
shell,
} = require("electron");
const path = require("path");
const getAllSources = async () => {
try {
const sources = await desktopCapturer.getSources({
types: ["window", "screen"],
});
return sources.map((source) => ({
name: source.name,
id: source.id,
thumbnail: source.thumbnail.toDataURL(),
}));
} catch (e) {
throw e;
}
};
async function createStreamWindow(_, callback) {
console.log(callback);
let callbackcalled = false;
const win = new BrowserWindow({
width: 620,
height: 400,
autoHideMenuBar: true,
icon: path.join(app.getAppPath(), "topluyo.png"),
webPreferences: {
nodeIntegration: true,
contextIsolation: true,
enableRemoteModule: true,
preload: path.join(__dirname, "preload.js"),
},
});
win.loadFile("ScreenShare.html");
const allSources = await getAllSources();
ipcMain.handle("setSource", async (_, data) => {
if (callbackcalled) return;
const selectedSource = allSources.find((s) => s.id === data.id);
try {
if (!selectedSource) {
throw new Error("Source not found");
}
callbackcalled = true;
let stream = { video: selectedSource };
if (data.isAudioEnabled) {
stream.audio = "loopback";
}
callback(stream);
ipcMain.removeHandler("getSources");
ipcMain.removeHandler("setSource");
win.close();
} catch (e) {
throw e;
}
});
win.on("close", () => {
if (callbackcalled) return;
callbackcalled = true;
try {
ipcMain.removeHandler("getSources");
ipcMain.removeHandler("setSource");
callback(null);
} catch (e) {
throw e;
}
});
}
const mediaHandler = async (req, callback) => {
try {
ipcMain.removeHandler("setSource");
ipcMain.removeHandler("getSources");
const allSources = await getAllSources();
ipcMain.handle("getSources", async () => {
return allSources;
});
await createStreamWindow(req, callback);
} catch (e) {
dialog.showErrorBox("Error", "hata:" + e.message);
}
};
//* URL Safety Function
function isSafeUrl(url) {
try {
const parsedUrl = new URL(url);
if (
parsedUrl.origin === "https://topluyo.com" &&
parsedUrl.protocol === "https:"
) {
if (parsedUrl.search && parsedUrl.search.includes("!login")) {
return false;
}
return true;
}
} catch (e) {
return false;
}
}
const openExternalLinks = (url) => {
if (process.platform === "linux") {
const newUrl = new URL(url);
require("child_process").exec(`xdg-open "${newUrl}"`);
} else {
shell.openExternal(url);
}
};
module.exports = { isSafeUrl, mediaHandler, openExternalLinks };