Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/libvesktop/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export interface MenuItem {
type?: "separator";
}

export function initStatusNotifierItem(): boolean;
export function initStatusNotifierItem(appName: string): boolean;
export function setStatusNotifierIcon(pixmapData: Buffer): boolean;
export function setStatusNotifierTitle(title: string): boolean;
export function setStatusNotifierMenu(items: MenuItem[]): boolean;
Expand Down
9 changes: 8 additions & 1 deletion packages/libvesktop/src/libvesktop.cc
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,14 @@ Napi::Value InitStatusNotifierItem(const Napi::CallbackInfo &info)
return Napi::Boolean::New(env, true);
}

g_sni_instance = std::make_unique<StatusNotifierItem>();
if (info.Length() < 1 || !info[0].IsString())
{
Napi::TypeError::New(env, "Expected (string)").ThrowAsJavaScriptException();
return env.Null();
}

std::string app_name = info[0].As<Napi::String>().Utf8Value();
g_sni_instance = std::make_unique<StatusNotifierItem>(app_name);
bool success = g_sni_instance->initialize();

if (!success)
Expand Down
9 changes: 5 additions & 4 deletions packages/libvesktop/src/status_notifier_item.cc
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ GVariant *StatusNotifierItem::handle_get_property(
}
else if (g_strcmp0(property_name, "Id") == 0)
{
return g_variant_new_string("equibop");
return g_variant_new_string(self->app_name.c_str());
}
else if (g_strcmp0(property_name, "Title") == 0)
{
Expand Down Expand Up @@ -229,7 +229,7 @@ GVariant *StatusNotifierItem::handle_get_property(
{
GVariantBuilder builder;
g_variant_builder_init(&builder, G_VARIANT_TYPE("(sa(iiay)ss)"));
g_variant_builder_add(&builder, "s", "equibop");
g_variant_builder_add(&builder, "s", self->app_name.c_str());
g_variant_builder_open(&builder, G_VARIANT_TYPE("a(iiay)"));
g_variant_builder_close(&builder);
g_variant_builder_add(&builder, "s", self->current_title.c_str());
Expand Down Expand Up @@ -523,7 +523,8 @@ GVariant *StatusNotifierItem::handle_menu_get_property(
return nullptr;
}

StatusNotifierItem::StatusNotifierItem()
StatusNotifierItem::StatusNotifierItem(const std::string &app_name)
: app_name(app_name)
{
GError *error = nullptr;
bus.reset(g_bus_get_sync(G_BUS_TYPE_SESSION, nullptr, &error));
Expand All @@ -534,7 +535,7 @@ StatusNotifierItem::StatusNotifierItem()
return;
}

service_name = "org.equicord.equibop.StatusNotifierItem";
service_name = "org.equicord." + app_name + ".StatusNotifierItem";
object_path = "/StatusNotifierItem";
}

Expand Down
3 changes: 2 additions & 1 deletion packages/libvesktop/src/status_notifier_item.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class StatusNotifierItem
guint watcher_id = 0;
bool registered_with_watcher = false;
std::string service_name;
std::string app_name;
std::string object_path;
std::string menu_object_path = "/MenuBar";
std::string current_status = "Active";
Expand Down Expand Up @@ -111,7 +112,7 @@ class StatusNotifierItem
void subscribe_to_watcher();

public:
StatusNotifierItem();
StatusNotifierItem(const std::string &app_name);
~StatusNotifierItem();

bool initialize();
Expand Down
5 changes: 3 additions & 2 deletions src/main/autoStart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { existsSync, mkdirSync, rmSync, writeFileSync } from "fs";
import { join } from "path";
import { stripIndent } from "shared/utils/text";

import { AppName } from "./cli";
import { IS_FLATPAK } from "./constants";
import { requestBackground } from "./dbus";
import { Settings, State } from "./settings";
Expand All @@ -29,15 +30,15 @@ function getEscapedCommandLine() {
function makeAutoStartLinuxDesktop(): AutoStart {
const configDir = process.env.XDG_CONFIG_HOME || join(process.env.HOME!, ".config");
const dir = join(configDir, "autostart");
const file = join(dir, "equibop.desktop");
const file = join(dir, `${AppName}.desktop`);

return {
isEnabled: () => existsSync(file),
enable() {
const desktopFile = stripIndent`
[Desktop Entry]
Type=Application
Name=Equibop
Name=${AppName === "equibop" ? "Equibop" : AppName}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i dont really see a point in

"equibop" ? "Equibop"

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Default desktop entry is Equibop, like it was pre-changes in this PR
  • Default appname is equibop, as per above

The idea was to make sure Equibop doesn't change anything in how it announces itself unless --app-name parameter is passed. Using simply Name=${AppName} results in lowercase equibop when no parameter is passed.

Comment=Equibop autostart script
Exec=${getEscapedCommandLine().join(" ")}
StartupNotify=false
Expand Down
23 changes: 22 additions & 1 deletion src/main/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ const options = {
type: "boolean",
short: "r",
description: "Re-download Equicord and restart"
},
"app-name": {
type: "string",
hidden: true,
description:
"The name of the application (used for DBus service name, etc.). For KDE, ensure this matches exactly your .desktop file name (eg. use your-profile for your-profile.desktop)."
}
} satisfies Record<string, Option>;

Expand Down Expand Up @@ -115,6 +121,12 @@ export async function checkCommandLineForRepair() {
return true;
}

export const AppName = typeof CommandLine.values["app-name"] === "string" ? CommandLine.values["app-name"] : "equibop";

if (AppName !== "equibop") {
app.setName(AppName);
}

export function checkCommandLineForHelpOrVersion() {
const { help, version } = CommandLine.values;

Expand Down Expand Up @@ -147,7 +159,9 @@ export function checkCommandLineForHelpOrVersion() {
"short" in opt && `-${opt.short}`,
`--${name}`,
opt.type !== "boolean" &&
("options" in opt ? `<${opt.options.join(" | ")}>` : `<${opt.argumentName ?? opt.type}>`)
("options" in opt
? `<${opt.options.join(" | ")}>`
: `<${("argumentName" in opt && opt.argumentName) || opt.type}>`)
]
.filter(Boolean)
.join(" ");
Expand Down Expand Up @@ -178,6 +192,13 @@ export function checkCommandLineForHelpOrVersion() {
console.error(`Invalid value for --${name}: ${value}\nExpected one of: ${def.options.join(", ")}`);
app.exit(1);
}

if (name === "app-name" && !/^[A-Za-z0-9._-]+$/.test(value as string)) {
console.error(
`Invalid value for --${name}: ${value}\nExpected a desktop/DBus-safe identifier containing only letters, numbers, '.', '_' or '-'.`
);
app.exit(1);
}
}
}

Expand Down
9 changes: 8 additions & 1 deletion src/main/startup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import "./vesktopProtocol";

import { app, BrowserWindow, nativeTheme } from "electron";

import { AppName } from "./cli";
import { DATA_DIR } from "./constants";
import { createFirstLaunchTour } from "./firstLaunch";
import { createWindows } from "./mainWindow";
Expand All @@ -26,6 +27,12 @@ process.env.EQUICORD_USER_DATA_DIR = DATA_DIR;

const isLinux = process.platform === "linux";

if (isLinux) {
const desktopName = `${AppName}.desktop`;
process.env.CHROME_DESKTOP = desktopName;
app.setDesktopName?.(desktopName);
}

export let enableHardwareAcceleration = true;

function init() {
Expand Down Expand Up @@ -112,7 +119,7 @@ function init() {
if (isDeckGameMode) nativeTheme.themeSource = "dark";

app.whenReady().then(async () => {
if (process.platform === "win32") app.setAppUserModelId("org.equicord.equibop");
if (process.platform === "win32") app.setAppUserModelId(`org.equicord.${AppName}`);

registerScreenShareHandler();
registerMediaPermissionsHandler();
Expand Down
3 changes: 2 additions & 1 deletion src/main/tray.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { STATIC_DIR } from "shared/paths";
import { createAboutWindow } from "./about";
import { createArgumentsWindow } from "./arguments";
import { restartArRPC } from "./arrpc";
import { AppName } from "./cli";
import { AppEvents } from "./events";
import { Settings } from "./settings";
import { resolveAssetPath } from "./userAssets";
Expand Down Expand Up @@ -213,7 +214,7 @@ export async function initTray(win: BrowserWindow, setIsQuitting: (val: boolean)

if (isLinux && nativeSNI) {
try {
const success = nativeSNI.initStatusNotifierItem();
const success = nativeSNI.initStatusNotifierItem(AppName);
if (success) {
useNativeTray = true;
nativeTrayInitialized = true;
Expand Down
7 changes: 4 additions & 3 deletions src/main/utils/setAsDefaultProtocolClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import { execFile } from "child_process";
import { app } from "electron";

import { AppName } from "../cli";

export async function setAsDefaultProtocolClient(protocol: string) {
if (process.platform !== "linux") {
return app.setAsDefaultProtocolClient(protocol);
Expand All @@ -18,11 +20,10 @@ export async function setAsDefaultProtocolClient(protocol: string) {
// 7 (YES, SEVEN) years out of date xdg-utils which STILL has the bug.
// FIXME: remove this workaround when Ubuntu updates their xdg-utils or electron switches to xdg-mime.

const { CHROME_DESKTOP } = process.env;
if (!CHROME_DESKTOP) return false;
const desktopFile = process.env.CHROME_DESKTOP || `${AppName}.desktop`;

return new Promise<boolean>(resolve => {
execFile("xdg-mime", ["default", CHROME_DESKTOP, `x-scheme-handler/${protocol}`], err => {
execFile("xdg-mime", ["default", desktopFile, `x-scheme-handler/${protocol}`], err => {
resolve(err == null);
});
});
Expand Down
6 changes: 6 additions & 0 deletions src/module.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,9 @@ declare module "@vencord/venmic" {
unlink(): boolean;
}
}

declare namespace Electron {
interface App {
setDesktopName(desktopName: string): void;
}
}