desktop: destroy system tray on toggle off setting

This commit is contained in:
Abdullah Atta
2023-11-18 14:53:14 +05:00
parent 3f32673b0a
commit b0fe967087
3 changed files with 15 additions and 11 deletions

View File

@@ -83,7 +83,7 @@ export const osIntegrationRouter = t.router({
AutoLaunch.disable();
}
config.desktopSettings = settings;
setupDesktopIntegration();
setupDesktopIntegration(settings);
}),
selectDirectory: t.procedure

View File

@@ -107,7 +107,7 @@ async function createWindow() {
}
await AssetManager.loadIcons();
setupDesktopIntegration();
setupDesktopIntegration(config.desktopSettings);
mainWindow.webContents.session.setSpellCheckerDictionaryDownloadURL(
"http://dictionaries.notesnook.com/"

View File

@@ -17,25 +17,27 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { app } from "electron";
import { config } from "./config";
import { setupTray } from "./tray";
import { DesktopIntegration, config } from "./config";
import { setupTray, destroyTray } from "./tray";
import { AutoLaunch } from "./autolaunch";
export function setupDesktopIntegration() {
const desktopIntegration = config.desktopSettings;
export function setupDesktopIntegration(
desktopIntegration: DesktopIntegration
) {
if (
desktopIntegration.closeToSystemTray ||
desktopIntegration.minimizeToSystemTray
) {
setupTray();
} else {
destroyTray();
}
// when close to system tray is enabled, it becomes nigh impossible
// to "quit" the app. This is necessary in order to fix that.
if (desktopIntegration.closeToSystemTray) {
app.on("before-quit", () => app.exit(0));
}
app.on("before-quit", () =>
desktopIntegration.closeToSystemTray ? app.exit(0) : null
);
globalThis.window?.on("close", (e) => {
if (config.desktopSettings.closeToSystemTray) {
@@ -49,7 +51,9 @@ export function setupDesktopIntegration() {
try {
globalThis.window?.minimize();
globalThis.window?.hide();
} catch (error) {}
} catch (error) {
console.error(error);
}
}
}
});