Skip to content
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

feat: including media permission #332

Merged
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
1 change: 1 addition & 0 deletions public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"Name": "Name",
"Theme": "Theme",
"Notifications": "Notifications",
"Microphone and Camera": "Microphone and Camera",
"Sound": "Sound",
"Spellcheck": "Spellcheck",
"Use custom tab color": "Use custom tab color",
Expand Down
1 change: 1 addition & 0 deletions public/locales/pt/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"Name": "Nome",
"Theme": "Tema",
"Notifications": "Notificações",
"Microphone and Camera": "Microfone e Câmera",
"Sound": "Som",
"Spellcheck": "Verificação Ortográfica",
"Use custom tab color": "Usar cor personalizada para a aba",
Expand Down
16 changes: 16 additions & 0 deletions src/components/TabEditDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,22 @@ const TabEditDialog: Component<{
{t("Notifications")}
</StyledSwitch>
</div>
<div class="py-2">
<StyledSwitch
checked={props.tabToEdit().config.media}
onChange={(value) => {
updateAndSyncTabStore(
"tabs",
(t) => t.id === props.tabToEdit().id,
"config",
"media",
value
);
}}
>
{t("Microphone and Camera")}
</StyledSwitch>
</div>
<div class="py-2">
<StyledSwitch
checked={props.tabToEdit().config.sound}
Expand Down
1 change: 1 addition & 0 deletions src/components/WebView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const WebView: Component<{ tab: Tab }> = (props) => {
if (!didStopLoading()) return;

window.toggleNotifications(tab.config.notifications, `persist:${tab.id}`);
window.toggleMediaPermission(tab.config.media, `persist:${tab.id}`);
});

createEffect(() => {
Expand Down
1 change: 1 addition & 0 deletions src/contextBridge.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ declare global {
electronSettingsStore: ElectronSettingsStoreIpcApi;
whatsappPreloadPath: string;
toggleNotifications: (enabled: boolean, partition: string) => Promise<void>;
toggleMediaPermission: (enabled: boolean, partition: string) => Promise<void>;
electronIPCHandlers: {
onOpenSettings: (callback: () => void) => Electron.IpcRenderer;
onEditActiveTab: (callback: () => void) => Electron.IpcRenderer;
Expand Down
14 changes: 14 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,20 @@ function addIPCHandlers(mainWindow: BrowserWindow) {
}
);

ipcMain.handle(
"toggle-media-permission",
(_event, enabled: boolean, partition: string) => {
session
.fromPartition(partition)
.setPermissionRequestHandler((webContents, permission, callback) => {
if (permission === "media") {
callback(enabled);
}
});
}
);


ipcMain.on("open-link", (_event, url: string) => {
shell.openExternal(url);
});
Expand Down
5 changes: 5 additions & 0 deletions src/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,18 @@ const toggleNotifications = async (enabled: boolean, partition: string) => {
await ipcRenderer.invoke("toggle-notifications", enabled, partition);
};

const toggleMediaPermission = async (enabled: boolean, partition: string) => {
await ipcRenderer.invoke("toggle-media-permission", enabled, partition);
};

contextBridge.exposeInMainWorld("electronTabStore", electronTabStoreIpcApi);
contextBridge.exposeInMainWorld("electronThemeStore", electronThemeStoreIpcApi);
contextBridge.exposeInMainWorld(
"electronSettingsStore",
electronSettingsStoreIpcApi
);
contextBridge.exposeInMainWorld("toggleNotifications", toggleNotifications);
contextBridge.exposeInMainWorld("toggleMediaPermission", toggleMediaPermission);

contextBridge.exposeInMainWorld("electronIPCHandlers", {
onOpenSettings: (callback: () => void) =>
Expand Down
2 changes: 2 additions & 0 deletions src/stores/tabs/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export type Tab = {
messageCount?: number;
config: {
theme: string;
media: boolean;
notifications: boolean;
sound: boolean;
color: string | null;
Expand All @@ -26,6 +27,7 @@ export const getDefaultTab = (): Tab => ({
config: {
theme: "dark",
notifications: true,
media: false,
Copy link
Owner

Choose a reason for hiding this comment

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

actually I think it makes sense to have this be on by default since most users will want it to work without having to turn on a setting.

i've already merged the PR, so I'll just make that change on main before I create the release

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree, it makes sense the default to be enabled!

sound: true,
color: null,
spellChecker: true,
Expand Down
37 changes: 31 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2051,9 +2051,9 @@ camelcase-css@^2.0.1:
integrity sha512-QOSvevhslijgYwRx6Rv7zKdMF8lbRmx+uQGx2+vDc+KI/eBnsy9kit5aj23AgGu3pa4t9AgwbnXWqS+iOY+2aA==

caniuse-lite@^1.0.30001517, caniuse-lite@^1.0.30001520:
version "1.0.30001525"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001525.tgz#d2e8fdec6116ffa36284ca2c33ef6d53612fe1c8"
integrity sha512-/3z+wB4icFt3r0USMwxujAqRvaD/B7rvGTsKhbhSQErVrJvkZCLhgNLJxU8MevahQVH6hCU9FsHdNUFbiwmE7Q==
version "1.0.30001668"
resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001668.tgz"
integrity sha512-nWLrdxqCdblixUO+27JtGJJE/txpJlyUy5YN1u53wLZkP0emYCo5zgS6QYft7VUYR42LGgi/S5hdLZTrnyIddw==

chalk@^2.4.2:
version "2.4.2"
Expand Down Expand Up @@ -5623,7 +5623,16 @@ stream-buffers@~2.2.0:
resolved "https://registry.yarnpkg.com/stream-buffers/-/stream-buffers-2.2.0.tgz#91d5f5130d1cef96dcfa7f726945188741d09ee4"
integrity sha512-uyQK/mx5QjHun80FLJTfaWE7JtwfRMKBLkMne6udYOmvH0CawotVa7TfgYHzAnpphn4+TweIx1QKMnRIbipmUg==

"string-width-cjs@npm:string-width@^4.2.0", "string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
"string-width-cjs@npm:string-width@^4.2.0":
version "4.2.3"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
dependencies:
emoji-regex "^8.0.0"
is-fullwidth-code-point "^3.0.0"
strip-ansi "^6.0.1"

"string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
version "4.2.3"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
Expand Down Expand Up @@ -5675,7 +5684,14 @@ string_decoder@^1.1.1:
dependencies:
safe-buffer "~5.2.0"

"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1:
"strip-ansi-cjs@npm:strip-ansi@^6.0.1":
version "6.0.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
dependencies:
ansi-regex "^5.0.1"

strip-ansi@^6.0.0, strip-ansi@^6.0.1:
version "6.0.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
Expand Down Expand Up @@ -6244,7 +6260,7 @@ [email protected]:
resolved "https://registry.yarnpkg.com/winreg/-/winreg-1.2.4.tgz#ba065629b7a925130e15779108cf540990e98d1b"
integrity sha512-IHpzORub7kYlb8A43Iig3reOvlcBJGX9gZ0WycHhghHtA65X0LYnMRuJs+aH1abVnMJztQkvQNlltnbPi5aGIA==

"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0:
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0":
version "7.0.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
Expand All @@ -6262,6 +6278,15 @@ wrap-ansi@^6.2.0:
string-width "^4.1.0"
strip-ansi "^6.0.0"

wrap-ansi@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
dependencies:
ansi-styles "^4.0.0"
string-width "^4.1.0"
strip-ansi "^6.0.0"

wrap-ansi@^8.1.0:
version "8.1.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-8.1.0.tgz#56dc22368ee570face1b49819975d9b9a5ead214"
Expand Down