Skip to content

Commit

Permalink
Merge pull request #368 from woniuxingdong/master
Browse files Browse the repository at this point in the history
  • Loading branch information
caorushizi authored Dec 12, 2024
2 parents 68fa822 + 998e24d commit f41ba42
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 3 deletions.
4 changes: 4 additions & 0 deletions packages/main/src/controller/HomeController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ export default class HomeController implements Controller {
if (key === "allowBeta") {
this.updater.changeAllowBeta(val);
}
// audio muted mode
if (key === "audioMuted") {
this.webviewService.setAudioMuted(val);
}

this.store.set(key, val);
}
Expand Down
2 changes: 2 additions & 0 deletions packages/main/src/main.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ declare interface AppStore {
allowBeta: boolean;
// 关闭主窗口
closeMainWindow: boolean;
// 浏览器中是否播放声音,默认静音
audioMuted: boolean;
}

declare interface BrowserStore {
Expand Down
11 changes: 8 additions & 3 deletions packages/main/src/services/WebviewService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,8 @@ export default class WebviewService {
},
});
this.view.setBackgroundColor("#fff");
this.view.webContents.setAudioMuted(true);

const { isMobile } = this.store.store;
const { isMobile, audioMuted } = this.store.store;
this.setAudioMuted(audioMuted);
this.setUserAgent(isMobile);

this.view.webContents.on("dom-ready", this.onDomReady);
Expand Down Expand Up @@ -305,6 +304,12 @@ export default class WebviewService {
this.logger.info(`[AdBlocker] disable`);
}

setAudioMuted(audioMuted?: boolean) {
if (!this.view) return;
this.view.webContents.setAudioMuted(audioMuted? true: false);
this.logger.info(`Play audio: ${!audioMuted}`);
}

setUserAgent(isMobile?: boolean) {
if (!this.view) return;
if (isMobile) {
Expand Down
1 change: 1 addition & 0 deletions packages/main/src/vendor/ElectronStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export default class StoreService extends Store<AppStore> implements Vendor {
autoUpgrade: true,
allowBeta: false,
closeMainWindow: false,
audioMuted: true,
},
});
}
Expand Down
2 changes: 2 additions & 0 deletions packages/renderer/src/i18n/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ Referer: http://www.example.com`,
numberOfEpisodes: "Number of episodes",
showNumberOfEpisodes: "Show number of episodes",
canUseMouseWheelToAdjust: "Can use mouse wheel to adjust",
audioMuted: "Audio Muted Mode",
openBrowser: "Open Browser",
privacy: "Privacy Mode",
privacyTooltip:
Expand Down Expand Up @@ -300,6 +301,7 @@ Referer: http://www.example.com`,
numberOfEpisodes: "集数",
showNumberOfEpisodes: "显示集数",
canUseMouseWheelToAdjust: "可以使用鼠标滚轮调整",
audioMuted: "静音模式",
openBrowser: "打开浏览器",
privacy: "隐私模式",
privacyTooltip: "打开开关后浏览器将不保存任何数据",
Expand Down
3 changes: 3 additions & 0 deletions packages/renderer/src/pages/SettingPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,9 @@ const SettingPage: React.FC = () => {
</Form.Item>
</GroupWrapper>
<GroupWrapper hidden={isWeb} title={t("browserSetting")}>
<Form.Item label={t("audioMuted")} name="audioMuted">
<Switch />
</Form.Item>
<Form.Item label={t("openInNewWindow")} name="openInNewWindow">
<Switch />
</Form.Item>
Expand Down
2 changes: 2 additions & 0 deletions packages/renderer/src/renderer.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ declare interface AppStore {
downloadProxySwitch?: boolean;
// 自动更新
autoUpgrade?: boolean;
// 浏览器中是否播放声音,默认静音
audioMuted?: boolean;
}

declare interface BrowserStore {
Expand Down
1 change: 1 addition & 0 deletions packages/renderer/src/store/appSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const initialState: AppStore = {
machineId: "",
downloadProxySwitch: false,
autoUpgrade: true,
audioMuted: true,
};

export const appSlice = createSlice({
Expand Down

0 comments on commit f41ba42

Please sign in to comment.