Repository navigation
Expand file tree
/
Copy pathlinuxscript.js
More file actions
79 lines (73 loc) · 2.76 KB
/
Copy pathlinuxscript.js
File metadata and controls
79 lines (73 loc) · 2.76 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
const { execFileSync } = require("child_process");
const fs = require("fs");
const path = require("path");
const os = require("os");
function fixChromeSandbox() {
if (process.env.APPIMAGE) {
console.log("ℹ️ AppImage ortamı: chrome-sandbox ayarı gereksiz, atlanıyor.");
return;
}
try {
const chromeSandboxPath = path.join(__dirname, "node_modules/electron/dist/chrome-sandbox");
if (fs.existsSync(chromeSandboxPath)) {
console.log("🔧 chrome-sandbox izni ayarlanıyor...");
execFileSync("sudo", ["chown", "root", chromeSandboxPath]);
execFileSync("sudo", ["chmod", "4755", chromeSandboxPath]);
console.log("✅ chrome-sandbox hazır.");
} else {
console.warn("⚠️ chrome-sandbox bulunamadı.");
}
} catch (error) {
console.error("🚫 chrome-sandbox ayarlanırken hata:", error.message);
}
}
function ensureShmExists() {
try {
const shmStat = fs.statSync("/dev/shm");
if (!shmStat.isDirectory()) {
throw new Error("/dev/shm is not a directory");
}
} catch (err) {
try {
console.log("⚠️ /dev/shm yok, oluşturuluyor...");
execFileSync("sudo", ["mkdir", "-p", "/dev/shm"]);
execFileSync("sudo", ["chmod", "1777", "/dev/shm"]);
console.log("✅ /dev/shm başarıyla oluşturuldu.");
} catch (e) {
console.error("🚫 /dev/shm oluşturulamadı:", e.message);
}
}
}
function registerProtocol() {
const desktopPath = path.join(os.homedir(), ".local/share/applications/topluyo.desktop");
// Sanitize paths: strip newlines to prevent .desktop entry injection via env vars
const appPath = (process.env.APPIMAGE || process.execPath).replace(/[\n\r]/g, '');
const iconPath = (process.env.APPIMAGE
? path.join(process.env.APPDIR, ".DirIcon")
: path.join(__dirname, "topluyo.png")).replace(/[\n\r]/g, '');
const desktopEntry = `[Desktop Entry]
Name=Topluyo
Exec=env ELECTRON_DISABLE_SANDBOX=1 "${appPath}" --no-sandbox --disable-dev-shm-usage %u
Type=Application
Terminal=false
MimeType=x-scheme-handler/topluyo;
Categories=Network;Chat;
NoDisplay=false
StartupWMClass=Topluyo
Icon=${iconPath}
`;
try {
fs.writeFileSync(desktopPath, desktopEntry, { mode: 0o755 });
execFileSync("chmod", ["+x", desktopPath]);
execFileSync("xdg-mime", ["default", "topluyo.desktop", "x-scheme-handler/topluyo"]);
execFileSync("update-desktop-database", [path.join(os.homedir(), ".local/share/applications")]);
console.log("✅ topluyo:// protokolü başarıyla kaydedildi.");
} catch (err) {
console.error("🚫 Protokol kaydı başarısız:", err.message);
}
}
if (process.platform === "linux") {
// fixChromeSandbox(); // Not needed when using --no-sandbox
registerProtocol();
// ensureShmExists(); // Not needed when using --disable-dev-shm-usage
}