adding the connection and all

This commit is contained in:
talksik
2022-05-28 01:33:14 -05:00
parent 1826f26d80
commit 0e0a8629e0
2 changed files with 62 additions and 10 deletions
+61 -5
View File
@@ -1,5 +1,6 @@
import { app, BrowserWindow } from 'electron';
import { DEFAULT_APP_PRESET } from './electron/constants';
import { app, BrowserWindow, ipcMain, Display, screen } from 'electron';
import Channels, { DEFAULT_APP_PRESET, DimensionChangeRequest } from './electron/constants';
// This allows TypeScript to pick up the magic constant that's auto-generated by Forge's Webpack
// plugin that tells the Electron app where to look for the Webpack-bundled app code (depending on
// whether you're running in development or production).
@@ -12,9 +13,15 @@ if (require('electron-squirrel-startup')) {
app.quit();
}
// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
export let browserWindow: BrowserWindow;
let display: Display;
const createWindow = (): void => {
// Create the browser window.
const mainWindow = new BrowserWindow({
browserWindow = new BrowserWindow({
...DEFAULT_APP_PRESET,
webPreferences: {
preload: MAIN_WINDOW_PRELOAD_WEBPACK_ENTRY,
@@ -25,10 +32,12 @@ const createWindow = (): void => {
});
// and load the index.html of the app.
mainWindow.loadURL(MAIN_WINDOW_WEBPACK_ENTRY);
browserWindow.loadURL(MAIN_WINDOW_WEBPACK_ENTRY);
// Open the DevTools.
mainWindow.webContents.openDevTools({ mode: 'detach' });
browserWindow.webContents.openDevTools({ mode: 'detach' });
display = screen.getPrimaryDisplay();
};
// This method will be called when Electron has finished
@@ -36,6 +45,53 @@ const createWindow = (): void => {
// Some APIs can only be used after this event occurs.
app.on('ready', createWindow);
app.whenReady().then(() => {
// dynamically changing the window bounds
ipcMain.on(Channels.RESIZE_WINDOW, (event, req: DimensionChangeRequest) => {
if (req.setAlwaysOnTop) {
browserWindow.setAlwaysOnTop(true, 'floating');
} else {
browserWindow.setAlwaysOnTop(false);
}
if (req.addDimensions) {
const currentDimensions = browserWindow.getSize();
browserWindow.setSize(
currentDimensions[0] + req.dimensions.width,
currentDimensions[1] + req.dimensions.height,
false,
);
} else {
browserWindow.setSize(req.dimensions.width, req.dimensions.height, false);
}
if (req.setPosition) {
if (req.setPosition === 'center') {
browserWindow.center();
}
if (req.setPosition === 'topRight') {
browserWindow.setPosition(display.bounds.width - req.dimensions.width, 0);
console.log(display.bounds);
}
}
});
// globalShortcut.register("`", () => {
// console.log("Electron loves global shortcuts!");
// });
// on blur, show overlay, and tell app to trigger overlay mode
browserWindow.on('blur', () => {
browserWindow.webContents.send(Channels.ON_WINDOW_BLUR);
});
browserWindow.on('focus', () => {
browserWindow.webContents.send(Channels.ON_WINDOW_FOCUS);
});
});
// Quit when all windows are closed, except on macOS. There, it's common
// for applications and their menu bar to stay active until the user quits
// explicitly with Cmd + Q.
@@ -63,11 +63,7 @@ export function ElectronProvider({ children }: { children: React.ReactNode }) {
setIsWindowFocused(false);
// TODO: testing mode... uncomment both instructions below
// setDesktopMode('overlayOnly');
// todo: make sure that if I am toggle broadcasted into a line, then don't deselect selected line
// the overlay should be showing selected line if I am broadcasting toggled into it as well as of course all other toggle tuned ones
// setSelectedLineId(null);
setDesktopMode('overlayOnly');
});
window.electronAPI.on(Channels.ON_WINDOW_FOCUS, () => {