Skip to content

Commit

Permalink
Merge branch 'Legcord:dev' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
CCIGAMES authored Oct 16, 2024
2 parents f3f3d02 + 288cff7 commit ac2d623
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 67 deletions.
6 changes: 5 additions & 1 deletion assets/lang/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@
"settings-theme-desc": "Window style manages what titlebar Legcord uses.",
"settings-theme-default": "Default (Custom)",
"settings-theme-native": "Native",
"settings-theme-transparent": "Transparent",
"settings-theme-overlay": "Overlay",
"settings-transparency": "Transparency",
"settings-transparency-desc": "Set the transparency mode Legcord uses.",
"settings-transparency-universal": "Universal",
"settings-transparency-modern": "Modern (Windows 11 only)",
"settings-theme-transparent": "Transparent",
"settings-audio": "Audio",
"settings-audio-desc": "Select which method Legcord uses to grab audio from your system during screenshare.",
"settings-csp-desc": "Legcord CSP is our system that manages loading custom content loading into the Discord app. Stuff like client mods and themes depend on it. Disable if you want to get rid of mods and custom styles.",
Expand Down
Binary file modified build/icon.icns
Binary file not shown.
3 changes: 2 additions & 1 deletion src/@types/settings.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ export interface Settings {
// Only used for external url warning dialog.
ignoreProtocolWarning?: boolean;
customIcon: string;
windowStyle: "default" | "native" | "transparent" | "overlay";
windowStyle: "default" | "native" | "overlay";
channel: "stable" | "ptb" | "canary";
audio: "loopback" | "loopbackWithMute";
transparency: "universal" | "modern" | "none";
legcordCSP: boolean;
minimizeToTray: boolean;
multiInstance: boolean;
Expand Down
1 change: 1 addition & 0 deletions src/common/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const defaults: Settings = {
audio: "loopbackWithMute",
multiInstance: false,
mods: ["vencord"],
transparency: "none",
spellcheck: true,
hardwareAcceleration: true,
performanceMode: "none",
Expand Down
21 changes: 12 additions & 9 deletions src/discord/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function doAfterDefiningTheWindow(passedWindow: BrowserWindow): void {
void passedWindow.webContents.executeJavaScript(`document.body.setAttribute("isMaximized", "");`);
passedWindow.hide(); // please don't flashbang the user
}
if (getConfig("windowStyle") === "transparent" && process.platform === "win32") {
if (getConfig("transparency") === "modern" && process.platform === "win32") {
passedWindow.setBackgroundMaterial("mica");
if (getConfig("startMinimized") === false) {
passedWindow.show();
Expand Down Expand Up @@ -339,15 +339,18 @@ export function createWindow() {
height: 30,
};
break;
case "transparent":
}
switch (getConfig("transparency")) {
case "universal":
browserWindowOptions.backgroundColor = "#00000000";

if (os.platform() === "win32" && os.release().startsWith("10")) {
browserWindowOptions.transparent = true;
} else {
browserWindowOptions.transparent = false;
browserWindowOptions.frame = true;
}
browserWindowOptions.transparent = true;
break;
case "modern":
browserWindowOptions.backgroundColor = "#00000000";
browserWindowOptions.transparent = false;
browserWindowOptions.frame = true;
break;
case "none":
break;
}
const mainWindow = new BrowserWindow(browserWindowOptions);
Expand Down
8 changes: 8 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ if (!app.requestSingleInstanceLock() && getConfig("multiInstance") === false) {
// kill if 2nd instance
app.quit();
} else {
app.setAppUserModelId("app.legcord.Legcord");
app.commandLine.appendSwitch("disable-features", "WidgetLayering"); // fix dev tools layers
// Your data now belongs to CCP
crashReporter.start({ uploadToServer: false });
Expand Down Expand Up @@ -105,6 +106,9 @@ if (!app.requestSingleInstanceLock() && getConfig("multiInstance") === false) {
if (getConfig("audio") === undefined) setConfig("audio", "loopbackWithMute");
if (getConfig("keybinds") === undefined) setConfig("keybinds", []);
if (getConfig("trayIcon") === "default") setConfig("trayIcon", "dynamic");
if (getConfig("transparency") === undefined) setConfig("transparency", "none");
// @ts-ignore
if (getConfig("windowStyle") === "transparent") setConfig("windowStyle", "default");
if (getConfig("smoothScroll") === false) app.commandLine.appendSwitch("disable-smooth-scrolling");
if (getConfig("autoScroll")) app.commandLine.appendSwitch("enable-blink-features", "MiddleClickAutoscroll");
if (getConfig("disableHttpCache")) app.commandLine.appendSwitch("disable-http-cache");
Expand All @@ -128,6 +132,10 @@ if (!app.requestSingleInstanceLock() && getConfig("multiInstance") === false) {
// Approves the permissions request
callback(true);
}
if (permission === "fullscreen") {
// Approves the permissions request
callback(true);
}
});
app.on("activate", () => {
if (BrowserWindow.getAllWindows().length === 0) {
Expand Down
114 changes: 59 additions & 55 deletions src/screenshare/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,61 +33,65 @@ function showAudioDialog(): boolean {
}

function registerCustomHandler(): void {
session.defaultSession.setDisplayMediaRequestHandler((request, callback) => {
console.log(request);
void desktopCapturer
.getSources({
types: ["screen", "window"],
})
.then((sources) => {
if (!sources) return callback({});
isDone = false;
console.log(sources);
if (process.platform === "linux" && process.env.XDG_SESSION_TYPE?.toLowerCase() === "wayland") {
console.log("WebRTC Capturer detected, skipping window creation."); //assume webrtc capturer is used
let options: Streams = { video: sources[0] };
if (sources[0] === undefined) return callback({});
if (showAudioDialog() === true) options = { video: sources[0], audio: getConfig("audio") };
callback(options);
} else {
capturerWindow = new BrowserWindow({
width: 800,
height: 600,
title: "Legcord Screenshare",
darkTheme: true,
icon: getConfig("customIcon") ?? path.join(import.meta.dirname, "../", "/assets/desktop.png"),
frame: true,
autoHideMenuBar: true,
webPreferences: {
sandbox: false,
spellcheck: false,
preload: path.join(import.meta.dirname, "screenshare", "preload.mjs"),
},
});
ipcMain.once("selectScreenshareSource", (_event, id: string, name: string, audio: boolean) => {
isDone = true;
console.log(`Audio status: ${audio}`);
capturerWindow.close();
const result = { id, name };
session.defaultSession.setDisplayMediaRequestHandler(
(request, callback) => {
console.log(request);
void desktopCapturer
.getSources({
types: ["screen", "window"],
})
.then((sources) => {
if (!sources) return callback({});
isDone = false;
console.log(sources);
if (process.platform === "linux" && process.env.XDG_SESSION_TYPE?.toLowerCase() === "wayland") {
console.log("WebRTC Capturer detected, skipping window creation."); //assume webrtc capturer is used
let options: Streams = { video: sources[0] };
switch (process.platform) {
case "win32":
case "linux":
options = { video: result };
if (audio) options = { video: result, audio: getConfig("audio") };
callback(options);
break;
default:
callback({ video: result });
}
});
capturerWindow.on("closed", () => {
if (!isDone) callback({});
});
void capturerWindow.loadFile(path.join(import.meta.dirname, "html", "picker.html"));
capturerWindow.webContents.send("getSources", sources);
}
});
});
if (sources[0] === undefined) return callback({});
if (showAudioDialog() === true) options = { video: sources[0], audio: getConfig("audio") };
callback(options);
} else {
capturerWindow = new BrowserWindow({
width: 800,
height: 600,
title: "Legcord Screenshare",
darkTheme: true,
icon:
getConfig("customIcon") ?? path.join(import.meta.dirname, "../", "/assets/desktop.png"),
frame: true,
autoHideMenuBar: true,
webPreferences: {
sandbox: false,
spellcheck: false,
preload: path.join(import.meta.dirname, "screenshare", "preload.mjs"),
},
});
ipcMain.once("selectScreenshareSource", (_event, id: string, name: string, audio: boolean) => {
isDone = true;
console.log(`Audio status: ${audio}`);
capturerWindow.close();
const result = { id, name };
let options: Streams = { video: sources[0] };
switch (process.platform) {
case "win32":
case "linux":
options = { video: result };
if (audio) options = { video: result, audio: getConfig("audio") };
callback(options);
break;
default:
callback({ video: result });
}
});
capturerWindow.on("closed", () => {
if (!isDone) callback({});
});
void capturerWindow.loadFile(path.join(import.meta.dirname, "html", "picker.html"));
capturerWindow.webContents.send("getSources", sources);
}
});
},
{ useSystemPicker: true },
);
}
registerCustomHandler();
16 changes: 15 additions & 1 deletion src/shelter/settings/pages/SettingsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,25 @@ export function SettingsPage() {
>
<option value="default">{store.i18n["settings-theme-default"]}</option>
<option value="native">{store.i18n["settings-theme-native"]}</option>
<option value="transparent">{store.i18n["settings-theme-transparent"]}</option>
<Show when={window.legcord.platform === "win32"}>
<option value="overlay">{store.i18n["settings-theme-overlay"]}</option>
</Show>
</DropdownItem>
<DropdownItem
value={store.settings.transparency}
onChange={(e) =>
setConfig("transparency", (e.target as HTMLInputElement).value as Settings["transparency"], true)
}
title={store.i18n["settings-transparency"]}
note={store.i18n["settings-transparency-desc"]}
link="https://github.com/Legcord/Legcord/wiki/Transparency-options"
>
<option value="universal">{store.i18n["settings-transparency-universal"]}</option>
<Show when={window.legcord.platform === "win32"}>
<option value="modern">{store.i18n["settings-transparency-modern"]}</option>
</Show>
<option value="none">{store.i18n["settings-none"]}</option>
</DropdownItem>
<DropdownItem
value={store.settings.trayIcon}
onChange={(e) =>
Expand Down

0 comments on commit ac2d623

Please sign in to comment.