working communication between renderer and main process
This commit is contained in:
@@ -43,54 +43,55 @@ const createWindow = (): void => {
|
|||||||
// This method will be called when Electron has finished
|
// This method will be called when Electron has finished
|
||||||
// initialization and is ready to create browser windows.
|
// initialization and is ready to create browser windows.
|
||||||
// Some APIs can only be used after this event occurs.
|
// Some APIs can only be used after this event occurs.
|
||||||
app.on('ready', createWindow);
|
app
|
||||||
|
.whenReady()
|
||||||
app.whenReady().then(() => {
|
.then(createWindow)
|
||||||
// dynamically changing the window bounds
|
.then(() => {
|
||||||
ipcMain.on(Channels.RESIZE_WINDOW, (event, req: DimensionChangeRequest) => {
|
// dynamically changing the window bounds
|
||||||
if (req.setAlwaysOnTop) {
|
ipcMain.on(Channels.RESIZE_WINDOW, (event, req: DimensionChangeRequest) => {
|
||||||
browserWindow.setAlwaysOnTop(true, 'floating');
|
if (req.setAlwaysOnTop) {
|
||||||
} else {
|
browserWindow.setAlwaysOnTop(true, 'floating');
|
||||||
browserWindow.setAlwaysOnTop(false);
|
} 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') {
|
if (req.addDimensions) {
|
||||||
browserWindow.setPosition(display.bounds.width - req.dimensions.width, 0);
|
const currentDimensions = browserWindow.getSize();
|
||||||
|
browserWindow.setSize(
|
||||||
console.log(display.bounds);
|
currentDimensions[0] + req.dimensions.width,
|
||||||
|
currentDimensions[1] + req.dimensions.height,
|
||||||
|
false,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
browserWindow.setSize(req.dimensions.width, req.dimensions.height, false);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// globalShortcut.register("`", () => {
|
if (req.setPosition) {
|
||||||
// console.log("Electron loves global shortcuts!");
|
if (req.setPosition === 'center') {
|
||||||
// });
|
browserWindow.center();
|
||||||
|
}
|
||||||
|
|
||||||
// on blur, show overlay, and tell app to trigger overlay mode
|
if (req.setPosition === 'topRight') {
|
||||||
browserWindow.on('blur', () => {
|
browserWindow.setPosition(display.bounds.width - req.dimensions.width, 0);
|
||||||
browserWindow.webContents.send(Channels.ON_WINDOW_BLUR);
|
|
||||||
});
|
|
||||||
|
|
||||||
browserWindow.on('focus', () => {
|
console.log(display.bounds);
|
||||||
browserWindow.webContents.send(Channels.ON_WINDOW_FOCUS);
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 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
|
// 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
|
// for applications and their menu bar to stay active until the user quits
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ export function ElectronProvider({ children }: { children: React.ReactNode }) {
|
|||||||
setIsWindowFocused(false);
|
setIsWindowFocused(false);
|
||||||
|
|
||||||
// TODO: testing mode... uncomment both instructions below
|
// TODO: testing mode... uncomment both instructions below
|
||||||
setDesktopMode('overlayOnly');
|
// setDesktopMode('overlayOnly');
|
||||||
});
|
});
|
||||||
|
|
||||||
window.electronAPI.on(Channels.ON_WINDOW_FOCUS, () => {
|
window.electronAPI.on(Channels.ON_WINDOW_FOCUS, () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user