Skip to content

Commit

Permalink
Added force cinema mode
Browse files Browse the repository at this point in the history
  • Loading branch information
isaxk committed Aug 31, 2024
1 parent db06eb8 commit 6518e63
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 8 deletions.
22 changes: 15 additions & 7 deletions src/main/tabs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,10 @@ function windowOpenHandler(details): WindowOpenHandlerResponse {
};
}

async function updateCustomCss(
key: string,
view: WebContentsView,
) {
async function updateCustomCss(key: string, view: WebContentsView) {
let ytCss = JSON.parse(store.get(key, "")!);
return new Promise<string | null>(async (resolve) => {
if (ytCss.enabled===true) {
if (ytCss.enabled === true) {
if (ytCss.type === "url") {
await loadCss(ytCss.url).then(async (css) => {
resolve(await view.webContents.insertCSS(css));
Expand Down Expand Up @@ -140,11 +137,12 @@ export async function createTabManager(mainWindow: BrowserWindow) {
},
updateCss: async () => {
if (oldCssKey !== null) {
await view.webContents.removeInsertedCSS(oldCssKey).then(()=>console.log("remove"));
await view.webContents
.removeInsertedCSS(oldCssKey)
.then(() => console.log("remove"));
}
await updateCustomCss("music-css", view).then((key) => {
oldCssKey = key;

});
},
};
Expand Down Expand Up @@ -263,6 +261,7 @@ export async function createTabManager(mainWindow: BrowserWindow) {
await updateCustomCss("yt-css", view).then((key) => {
oldCssKey = key;
});
view.webContents.send("force-cinema", store.get("force-cinema", false));
});

return {
Expand Down Expand Up @@ -398,6 +397,15 @@ export async function createTabManager(mainWindow: BrowserWindow) {
}
});

ipcMain.on("set-config", (_, e) => {
if (e.key === "force-cinema") {
tabs.forEach((tab) => {
tab.data().type === "yt" ??
tab.view.webContents.send("force-cinema", e.value);
});
}
});

return {
getTabs: () => {
return tabs;
Expand Down
16 changes: 16 additions & 0 deletions src/preload/yt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,19 @@ ipcRenderer.on("picture-in-picture", async () => {
`)
)();
});

ipcRenderer.on("force-cinema", async (_, is: boolean) => {
if (is) {
(
await webFrame.executeJavaScript(`
document.cookie = 'wide=1; expires='+new Date('3099').toUTCString()+'; path=/';
`)
)();
} else {
(
await webFrame.executeJavaScript(`
document.cookie = 'wide=0; expires='+new Date('3099').toUTCString()+'; path=/';
`)
)();
}
});
2 changes: 1 addition & 1 deletion src/renderer/src/components/settings/SettingItem.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
}, 400);
}}
>
<div class="mb-4 rounded-md border dark:border-neutral-600">
<div class="pb-4 rounded-md border dark:border-neutral-600">
<Tabs.List
class="flex w-full justify-stretch rounded bg-zinc-200 p-1 text-center dark:bg-neutral-800"
>
Expand Down

0 comments on commit 6518e63

Please sign in to comment.