-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace background menu option with The Button #3
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
const { app, BrowserWindow, Menu, ipcMain, protocol } = require("electron"); | ||
const { app, BrowserWindow, ipcMain, protocol } = require("electron"); | ||
const path = require("path"); | ||
const fs = require("fs"); | ||
|
||
|
@@ -14,7 +14,8 @@ let backgroundsLoaded = false; | |
// setting API requests. | ||
let callObjectReady = false; | ||
|
||
let backgroundMenuButton = null; | ||
// Whether the backgrounds window is open | ||
let backgroundsWindowOpen = false; | ||
|
||
// We'll define a custom "bg" scheme to fetch our background images. | ||
// This allows us to load local images without disabling Electron's | ||
|
@@ -34,6 +35,7 @@ function createCallWindow() { | |
webPreferences: { | ||
preload: path.join(__dirname, "preloadCall.js"), | ||
}, | ||
autoHideMenuBar: true, | ||
}); | ||
|
||
// If the user closes the main call window, exit | ||
|
@@ -43,8 +45,9 @@ function createCallWindow() { | |
callWindow = null; | ||
app.quit(); | ||
}); | ||
|
||
callWindow.loadFile(path.join(__dirname, "../html", "index.html")); | ||
callWindow.loadFile( | ||
path.join(__dirname, "../renderer", "call", "index.html") | ||
); | ||
} | ||
|
||
// loadBackgroundFiles loads all jpg, jpeg, or png files in | ||
|
@@ -81,15 +84,16 @@ app.whenReady().then(() => { | |
const path = request.url.substring(5, url.length); | ||
callback({ path: path }); | ||
}); | ||
createMenu(); | ||
createCallWindow(); | ||
loadBackgroundFiles(); | ||
}); | ||
|
||
// createBackgroundSelectionWindow creates a window in which the user | ||
// can select a Daily video call background to set. | ||
function createBackgroundSelectionWindow() { | ||
backgroundMenuButton.enabled = false; | ||
if (backgroundsWindowOpen) return; | ||
|
||
backgroundsWindowOpen = true; | ||
|
||
const win = new BrowserWindow({ | ||
width: 500, | ||
|
@@ -100,41 +104,19 @@ function createBackgroundSelectionWindow() { | |
autoHideMenuBar: true, | ||
}); | ||
|
||
win.loadFile(path.join(__dirname, "../html", "background.html")); | ||
win.loadFile( | ||
path.join(__dirname, "../renderer", "background", "background.html") | ||
); | ||
|
||
win.webContents.once("dom-ready", () => { | ||
win.webContents.send("load-backgrounds", { backgrounds: backgroundFiles }); | ||
}); | ||
|
||
// Re-enable the menu button when the background selection window | ||
// is closed. | ||
win.on("close", () => { | ||
backgroundMenuButton.enabled = true; | ||
backgroundsWindowOpen = false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is no menu anymore, so this turns into a simple bool to prevent duplicate background selection windows. |
||
}); | ||
} | ||
|
||
// createMenu creates our application menu with the background setting option. | ||
function createMenu() { | ||
const template = [ | ||
{ | ||
label: "Options", | ||
submenu: [ | ||
{ | ||
id: "background", | ||
label: "Background 🏔️", | ||
enabled: false, | ||
click: async () => { | ||
createBackgroundSelectionWindow(); | ||
}, | ||
}, | ||
], | ||
}, | ||
]; | ||
const menu = Menu.buildFromTemplate(template); | ||
backgroundMenuButton = menu.getMenuItemById("background"); | ||
Menu.setApplicationMenu(menu); | ||
} | ||
|
||
// "set-background" event handler instructs the daily renderer | ||
// process to set the given background for the local participant. | ||
ipcMain.handle("set-background", (e, imgPath) => { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,22 +7,38 @@ window.addEventListener("DOMContentLoaded", () => { | |
function initCall() { | ||
const container = document.getElementById("container"); | ||
|
||
const url = new URL("./backgroundButton.png", document.baseURI); | ||
url.protocol = "bg"; | ||
|
||
callFrame = DailyIframe.createFrame(container, { | ||
showLeaveButton: true, | ||
iframeStyle: { | ||
position: "fixed", | ||
width: "calc(100% - 1rem)", | ||
height: "calc(100% - 1rem)", | ||
}, | ||
// Specify a custom button for background controls | ||
customTrayButtons: { | ||
backgrounds: { | ||
iconPath: url.href, | ||
label: "Background", | ||
tooltip: "Set Custom Background", | ||
}, | ||
}, | ||
}) | ||
.on("nonfatal-error", (e) => { | ||
console.warn("nonfatal error:", e); | ||
}) | ||
.on("started-camera", () => { | ||
api.tryEnableBackgrounds(); | ||
}) | ||
.on("left-meeting", () => { | ||
initCall(); | ||
}) | ||
.on("custom-button-click", (ev) => { | ||
// If the event is triggered by clicking | ||
// our background button, show the | ||
// background selection window | ||
if (ev.button_id === "backgrounds") { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this works (and is such a good use of The Button!!) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh wow I think I missed committing some CSS here, all the styling is gone. 1min! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (that's what I get for trying to finish a PR mid-all-hands) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be fixed now! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. much better! :D |
||
api.tryEnableBackgrounds(); | ||
} | ||
}); | ||
|
||
// TODO: Replace the following URL with your own room URL. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is modified because the html files have moved as mentioned in PR description.