summaryrefslogtreecommitdiff
path: root/client/main.js
diff options
context:
space:
mode:
Diffstat (limited to 'client/main.js')
-rwxr-xr-xclient/main.js65
1 files changed, 56 insertions, 9 deletions
diff --git a/client/main.js b/client/main.js
index b6a02b9..acede07 100755
--- a/client/main.js
+++ b/client/main.js
@@ -24,6 +24,7 @@ app.setPath("sessionData", localchatDataRoot + "/client/session");
app.setAppLogsPath(localchatDataRoot + "/client/logs");
if (require('os').platform() !== "darwin" && require('os').platform() !== "win32" && require('os').platform() !== "linux") return;
+global.windows = [];
const createWindow = () => {
app.setPath("userData", localchatDataRoot + "/client");
@@ -62,12 +63,36 @@ const createWindow = () => {
});
mainWindow.loadFile(global._localchatPath + "/index.html");
+ windows.push(mainWindow);
if (os.platform() === "win32") mainWindow.setContentProtection(true);
+ ipcMain.on('screenSharing', (event, url, id) => {
+ let screenSharingWindow = new BrowserWindow({
+ width: 1280,
+ minWidth: 480,
+ height: 720,
+ minHeight: 640,
+ icon: require('os').platform() === "darwin" ? "./icon.icns" : (require('os').platform() === "linux" ? "./icon.png" : "./icon.ico"),
+ disableAutoHideCursor: true,
+ backgroundColor: "#000000",
+ darkTheme: true,
+ autoHideMenuBar: true,
+ webPreferences: {
+ nodeIntegration: true,
+ contextIsolation: false,
+ additionalArguments: "--user-data-dir=\"" + localchatDataRoot + "/client" + "\""
+ }
+ });
+
+ windows.push(screenSharingWindow);
+ screenSharingWindow.loadURL("file://" + encodeURI(global._localchatPath) + "/screen.html?" + url + "#" + id);
+ if (os.platform() === "win32") screenSharingWindow.setContentProtection(true);
+ });
+
mainWindow.send("path", app.getPath("userData"));
mainWindow.send("launcher", global._localchatLauncherVersion);
- ipcMain.on('menu', (event, items) => {
+ function createMenu(items) {
let menuItems = [];
for (let item of items) {
@@ -75,19 +100,23 @@ const createWindow = () => {
type: item.type ?? "normal",
label: item.label ?? "",
enabled: item.enabled ?? true,
- click: () => {
+ click: item.submenu ? null : () => {
mainWindow.webContents.executeJavaScript(item.script ?? "");
- }
+ },
+ submenu: item.submenu ? createMenu(item.submenu) : null
}));
}
- let menu = Menu.buildFromTemplate(menuItems);
+ return Menu.buildFromTemplate(menuItems);
+ }
+
+ ipcMain.on('menu', (event, items) => {
+ let menu = createMenu(items);
menu.popup(mainWindow);
});
ipcMain.handle('screenshot', async (event) => {
let screens = await desktopCapturer.getSources({ types: ['screen'], thumbnailSize: { width: 1920, height: 1080 } });
- console.log(screens)
if (screens[0]) {
return screens[0].thumbnail.toJPEG(80).toString("base64");
@@ -96,6 +125,24 @@ const createWindow = () => {
}
});
+ ipcMain.handle('screenshotRaw', async (_, id) => {
+ let screens = await desktopCapturer.getSources({ types: ['screen', 'window'], thumbnailSize: { width: 1280, height: 720 } });
+ let screen = screens.filter(i => i.id === id)[0];
+
+ if (screen) {
+ return screen.thumbnail.toJPEG(80);
+ } else {
+ return null;
+ }
+ });
+
+ ipcMain.handle('sources', async (event) => {
+ return await desktopCapturer.getSources({
+ types: ['screen', 'window'],
+ thumbnailSize: {width: 0, height: 0}
+ });
+ });
+
ipcMain.handle('clipboard', async (event) => {
if (clipboard.readText().trim() !== "") {
return {
@@ -192,13 +239,13 @@ const createWindow = () => {
app.whenReady().then(() => {
globalShortcut.register('Alt+CommandOrControl+C', () => {
- if (mainWindow) {
+ for (let window of windows) {
try {
- if (!mainWindow.isVisible()) {
- mainWindow.show();
+ if (!window.isVisible()) {
+ window.show();
if (process.platform === "darwin") app.dock.show();
} else {
- mainWindow.hide();
+ window.hide();
if (process.platform === "darwin") app.dock.hide();
}
} catch (e) {}