-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
113 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { contextBridge, ipcRenderer } from "electron"; | ||
|
||
contextBridge.exposeInMainWorld("preferences", { | ||
getShowInTray: async (): Promise<boolean> => { | ||
return await ipcRenderer.invoke("get-preference", "show-in-tray"); | ||
}, | ||
showInTrayChanged: (enabled: boolean): void => { | ||
ipcRenderer.send("preference-changed", "show-in-tray", enabled); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<label><input type="checkbox" id="show-in-tray"> Show in tray</label> | ||
|
||
<p>Some preferences require a restart to take effect.</p> | ||
<p>Press <kbd>CTRL</kbd> + <kbd>P</kbd> to open the preferences from the main window.</p> | ||
|
||
<script> | ||
const showInTray = document.querySelector("#show-in-tray"); | ||
|
||
showInTray.addEventListener("change", (event) => { | ||
preferences.showInTrayChanged(event.target.checked); | ||
}); | ||
|
||
(async () => { | ||
showInTray.checked = await preferences.getShowInTray(); | ||
})() | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import path from "path"; | ||
import { BrowserWindow, ipcMain } from "electron"; | ||
|
||
import WhatsApp from "../whatsapp"; | ||
import Module from "./module"; | ||
import Settings from "../settings"; | ||
|
||
export default class Preferences extends Module { | ||
private readonly window: BrowserWindow; | ||
private readonly settings: Settings; | ||
|
||
constructor( | ||
private readonly whatsApp: WhatsApp | ||
) { | ||
super(); | ||
|
||
this.settings = new Settings("preferences"); | ||
|
||
this.window = new BrowserWindow({ | ||
title: "WhatsApp - Preferences", | ||
width: 320, | ||
height: 240, | ||
show: false, | ||
minimizable: false, | ||
maximizable: false, | ||
resizable: false, | ||
autoHideMenuBar: true, | ||
webPreferences: { | ||
preload: path.join(__dirname, "preferences-module-preload.js") | ||
} | ||
}); | ||
|
||
this.window.on("close", this.onClose.bind(this)); | ||
|
||
ipcMain.handle("get-preference", this.onGetPreference.bind(this)); | ||
ipcMain.on("preference-changed", this.onPreferenceChanged.bind(this)); | ||
|
||
this.window.loadFile("src/module/preferences-module.html"); | ||
} | ||
|
||
get showInTray(): boolean { | ||
return this.settings.get("show-in-tray", true); | ||
} | ||
|
||
show(): void { | ||
this.window.show(); | ||
} | ||
|
||
private onClose(event: Electron.Event): void { | ||
this.window.hide(); | ||
|
||
if (!this.whatsApp.quitting) { | ||
event.preventDefault(); | ||
} | ||
} | ||
|
||
private onGetPreference(event: Electron.IpcMainInvokeEvent, key: string): void { | ||
return this.settings.get(key); | ||
} | ||
|
||
private onPreferenceChanged(event: Electron.IpcMainEvent, key: string, value: any): void { | ||
this.settings.set(key, value); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters