Skip to content

Commit bc50621

Browse files
authored
Merge pull request #132 from Brskt/linux-native-bridge
Add Linux native bridge for tidal-hifi
2 parents 4382add + d3ac064 commit bc50621

6 files changed

Lines changed: 350 additions & 76 deletions

File tree

native/injector.ts

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,40 @@ electron.app.commandLine.appendSwitch("remote-allow-origins", "http://localhost:
2626
if (process.platform === "linux") {
2727
// Zygote causes sandbox initialization failures on some Linux configurations
2828
electron.app.commandLine.appendSwitch("no-zygote");
29+
30+
// Match tidal-hifi's .desktop StartupWMClass so GNOME/KDE shows the correct dock icon
31+
// --class works for X11, CHROME_DESKTOP sets the Wayland app_id
32+
electron.app.commandLine.appendSwitch("class", "tidal-hifi");
33+
electron.app.name = "tidal-hifi";
34+
process.env.CHROME_DESKTOP = "tidal-hifi.desktop";
35+
36+
// tidal-hifi settings access for Linux integration
37+
ipcHandle("__Luna.getTidalHifiSetting", async (_, key: string) => {
38+
try {
39+
const configPath = path.join(electron.app.getPath("userData"), "config.json");
40+
const config = JSON.parse(await readFile(configPath, "utf8"));
41+
// Support nested keys like "discord.showSong"
42+
return key.split(".").reduce((obj, k) => obj?.[k], config);
43+
} catch {
44+
return undefined;
45+
}
46+
});
47+
48+
// tidal-hifi theme file reading
49+
ipcHandle("__Luna.getTidalHifiThemeCSS", async (_, themeName: string) => {
50+
if (!themeName || themeName === "none") return undefined;
51+
const userPath = path.join(electron.app.getPath("userData"), "themes", themeName);
52+
const resourcesPath = path.join(process.resourcesPath, themeName);
53+
try {
54+
return await readFile(userPath, "utf8");
55+
} catch {
56+
try {
57+
return await readFile(resourcesPath, "utf8");
58+
} catch {
59+
return undefined;
60+
}
61+
}
62+
});
2963
}
3064

3165
const bundleFile = async (url: string): Promise<[Buffer, ResponseInit]> => {
@@ -54,7 +88,7 @@ const lunaBundle = bundleFile("https://luna/luna.mjs").then(([content]) => conte
5488
ipcHandle("__Luna.renderJs", () => lunaBundle);
5589

5690
// #region HTTPS Handler
57-
const tidalMainHosts = new Set(["listen.tidal.com", "tidal.com", "desktop.tidal.com"]);
91+
const tidalMainHosts = new Set(["listen.tidal.com", "tidal.com", "desktop.tidal.com", "stage.tidal.com"]);
5892
let httpsHandlerActive = false;
5993

6094
const httpsHandler = async (req: Request): Promise<Response> => {
@@ -150,12 +184,7 @@ const ProxiedBrowserWindow = new Proxy(electron.BrowserWindow, {
150184
// Ensure smoothScrolling is always enabled
151185
options.webPreferences.smoothScrolling = true;
152186

153-
// explicitly set icon before load on linux
154187
const platformIsLinux = process.platform === "linux";
155-
const iconPath = path.join(tidalAppPath, "assets/icon.png");
156-
if (platformIsLinux) {
157-
options.icon = iconPath;
158-
}
159188

160189
// Check if this is the main Tidal window
161190
// tidal-hifi does not set the title, rely on dev tools instead.
@@ -190,7 +219,6 @@ const ProxiedBrowserWindow = new Proxy(electron.BrowserWindow, {
190219

191220
globalThis.luna.sendToRender = window.webContents.send;
192221

193-
194222
// Linux (tidal-hifi): Handle OAuth login in a popup window
195223
if (platformIsLinux) {
196224
let loginWindow: electron.BrowserWindow | null = null;
@@ -265,14 +293,6 @@ const ProxiedBrowserWindow = new Proxy(electron.BrowserWindow, {
265293
});
266294
});
267295

268-
// if we are on linux and this is the main tidal window,
269-
// set the icon again after load (potential KDE quirk)
270-
if (platformIsLinux && isTidalWindow) {
271-
window.webContents.once("did-finish-load", () => {
272-
window.setIcon(iconPath);
273-
});
274-
}
275-
276296
// #region Open from link
277297
// MacOS
278298
electron.app.setAsDefaultProtocolClient("tidaLuna");
@@ -353,9 +373,11 @@ electron.Menu.buildFromTemplate = (template) => {
353373
template.push({
354374
role: "toggleDevTools",
355375
visible: false,
376+
accelerator: "F12",
356377
});
357378
return originalBuildFromTemplate(template);
358379
};
380+
359381
// #endregion
360382

361383
// #region Start app
@@ -371,3 +393,4 @@ ipcHandle("__Luna.preloadErr", async (_, err: Error) => {
371393
console.error(err);
372394
electron.dialog.showErrorBox("TidaLuna", err.message);
373395
});
396+

native/preload.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,11 @@ ipcRenderer.on("__Luna.console", (_event, prop: ConsoleMethodName, args: any[])
4040
try {
4141
await webFrame.executeJavaScript(
4242
`(async () => {
43-
// Skip popup windows (login, Themer editor, etc.) - only load on TIDAL pages
44-
const isTidalPage = location.hostname.includes("tidal.com");
45-
if (!isTidalPage) {
46-
console.log("[Luna.preload] Skipping non-TIDAL page:", location.href);
43+
// Skip popup windows (login, Themer editor, etc.) and non-SPA pages (magazine, etc.)
44+
// Only load on the main TIDAL SPA entry point (pathname "/")
45+
const isTidalApp = location.hostname.includes("tidal.com") && location.pathname === "/";
46+
if (!isTidalApp) {
47+
console.log("[Luna.preload] Skipping non-TIDAL app page:", location.href);
4748
return;
4849
}
4950

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "luna",
3-
"version": "1.9.22-beta",
3+
"version": "1.10.0-beta",
44
"description": "A client mod for the Tidal music app for plugins",
55
"author": {
66
"name": "Inrixia",
@@ -44,4 +44,4 @@
4444
"esbuild": "^0.27.1",
4545
"html-minifier-terser": "^7.2.0"
4646
}
47-
}
47+
}

plugins/linux/src/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
export * from "./index.safe";
2+
export { showSettings, hideSettings } from "./tidalHifi";
23

3-
import "./mpris";
4+
5+
// Bridge to tidal-hifi's main process features (MPRIS, Discord RPC, notifications, hotkeys, etc.)
6+
import "./tidalHifi";

plugins/linux/src/mpris.ts

Lines changed: 0 additions & 54 deletions
This file was deleted.

0 commit comments

Comments
 (0)