Skip to content

Commit

Permalink
add right click quit
Browse files Browse the repository at this point in the history
  • Loading branch information
vincelwt committed Dec 2, 2022
1 parent 5d15630 commit 9ce68f0
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 53 deletions.
3 changes: 2 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
margin-bottom: -10px;
}
.sticky{
.sticky,
.pointer-events-auto.flex.border-orange-500{
display: none;
}
`)
Expand Down
108 changes: 56 additions & 52 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const {
app,
nativeImage,
shell,
Tray,
Menu,
MenuItem,
globalShortcut,
Expand All @@ -14,56 +15,65 @@ const image = nativeImage.createFromPath(
path.join(__dirname, `images/newiconTemplate.png`)
);

const mb = menubar({
browserWindow: {
icon: image,
transparent: path.join(__dirname, `images/iconApp.png`),
webPreferences: {
webviewTag: true,
nativeWindowOpen: true,
app.on("ready", () => {
const tray = new Tray(image);

const contextMenu = Menu.buildFromTemplate([
{ role: "about" },
{ type: "separator" },
{ role: "quit" },
]);

const mb = menubar({
browserWindow: {
icon: image,
transparent: path.join(__dirname, `images/iconApp.png`),
webPreferences: {
webviewTag: true,
nativeWindowOpen: true,
},
width: 450,
height: 550,
},
width: 450,
height: 550,
},
preloadWindow: true,
showDockIcon: false,
icon: image,
});
tray,
preloadWindow: true,
showDockIcon: false,
icon: image,
});

mb.on("ready", () => {
app.dock.hide();
mb.on("ready", () => {
app.dock.hide();

tray.on("right-click", () => {
mb.tray.popUpContextMenu(contextMenu);
});

const { window } = mb;
const { window } = mb;

const menu = new Menu();
const menu = new Menu();

let isShown = false;
menu
.on("after-show", () => {
isShown = true;
})
.on("after-hide", () => {
isShown = false;
})
.on("focus-lost", () => {
isShown = false;
globalShortcut.register("CommandOrControl+Shift+g", () => {
console.log(window.isFocused(), window.isVisible());
if (window.isVisible()) {
mb.hideWindow();
} else {
mb.showWindow();
mb.app.show();
mb.app.focus();
}
});

globalShortcut.register("CommandOrControl+Shift+g", () => {
console.log(window.isFocused(), window.isVisible());
if (window.isVisible()) {
mb.hideWindow();
} else {
mb.showWindow();
mb.app.show();
mb.app.focus();
}
});
Menu.setApplicationMenu(menu);

// open devtools
// window.webContents.openDevTools();

Menu.setApplicationMenu(menu);
console.log("Menubar app is ready.");
});

// open devtools
// window.webContents.openDevTools();
mb.on("after-hide", () => {
mb.app.hide();
});

// open in new window
app.on("web-contents-created", (event, contents) => {
Expand All @@ -73,19 +83,13 @@ mb.on("ready", () => {
});
});

console.log("Menubar app is ready.");
// prevent background flickering
app.commandLine.appendSwitch(
"disable-backgrounding-occluded-windows",
"true"
);
});

// prevent background flickering
mb.app.commandLine.appendSwitch(
"disable-backgrounding-occluded-windows",
"true"
);

// restore focus to previous app on hiding
mb.on("after-hide", () => {
mb.app.hide();
});

// 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
Expand Down

0 comments on commit 9ce68f0

Please sign in to comment.