mirror of
https://github.com/ElectronNET/Electron.NET.git
synced 2026-07-09 02:07:47 +00:00
browserWindows.ts: Fix SetThumbarButtons
This commit is contained in:
@@ -524,8 +524,21 @@ module.exports = (socket, app) => {
|
||||
});
|
||||
socket.on('browserWindowSetThumbarButtons', (id, thumbarButtons) => {
|
||||
thumbarButtons.forEach(thumbarButton => {
|
||||
const imagePath = path.join(__dirname.replace('api', ''), 'bin', thumbarButton.icon.toString());
|
||||
thumbarButton.icon = electron_1.nativeImage.createFromPath(imagePath);
|
||||
const originalIconPath = thumbarButton.icon.toString();
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
let imagePath = originalIconPath;
|
||||
if (!path.isAbsolute(originalIconPath)) {
|
||||
imagePath = path.join(__dirname.replace('api', ''), 'bin', originalIconPath);
|
||||
}
|
||||
const { nativeImage } = require('electron');
|
||||
if (fs.existsSync(imagePath)) {
|
||||
thumbarButton.icon = nativeImage.createFromPath(imagePath);
|
||||
}
|
||||
else {
|
||||
// Fallback to empty image to avoid failure
|
||||
thumbarButton.icon = nativeImage.createEmpty();
|
||||
}
|
||||
thumbarButton.click = () => {
|
||||
electronSocket.emit('thumbarButtonClicked', thumbarButton['id']);
|
||||
};
|
||||
@@ -576,8 +589,14 @@ module.exports = (socket, app) => {
|
||||
getWindowById(id).setFocusable(focusable);
|
||||
});
|
||||
socket.on('browserWindowSetParentWindow', (id, parent) => {
|
||||
const child = getWindowById(id);
|
||||
if (!parent) {
|
||||
// Clear parent: make this window top-level
|
||||
child.setParentWindow(null);
|
||||
return;
|
||||
}
|
||||
const browserWindow = electron_1.BrowserWindow.fromId(parent.id);
|
||||
getWindowById(id).setParentWindow(browserWindow);
|
||||
child.setParentWindow(browserWindow);
|
||||
});
|
||||
socket.on('browserWindowGetParentWindow', (id) => {
|
||||
const browserWindow = getWindowById(id).getParentWindow();
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -665,8 +665,20 @@ export = (socket: Socket, app: Electron.App) => {
|
||||
|
||||
socket.on('browserWindowSetThumbarButtons', (id, thumbarButtons: Electron.ThumbarButton[]) => {
|
||||
thumbarButtons.forEach(thumbarButton => {
|
||||
const imagePath = path.join(__dirname.replace('api', ''), 'bin', thumbarButton.icon.toString());
|
||||
thumbarButton.icon = nativeImage.createFromPath(imagePath);
|
||||
const originalIconPath = thumbarButton.icon.toString();
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
let imagePath = originalIconPath;
|
||||
if (!path.isAbsolute(originalIconPath)) {
|
||||
imagePath = path.join(__dirname.replace('api', ''), 'bin', originalIconPath);
|
||||
}
|
||||
const { nativeImage } = require('electron');
|
||||
if (fs.existsSync(imagePath)) {
|
||||
thumbarButton.icon = nativeImage.createFromPath(imagePath);
|
||||
} else {
|
||||
// Fallback to empty image to avoid failure
|
||||
thumbarButton.icon = nativeImage.createEmpty();
|
||||
}
|
||||
thumbarButton.click = () => {
|
||||
electronSocket.emit('thumbarButtonClicked', thumbarButton['id']);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user