Skip to content

Commit d41693b

Browse files
authored
Merge pull request #42 from Omniaevo/develop
Close to tray in settings
2 parents 9635aa5 + c5101e5 commit d41693b

File tree

6 files changed

+46
-5
lines changed

6 files changed

+46
-5
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mqtt5-explorer",
3-
"version": "1.11.0",
3+
"version": "1.12.0",
44
"private": false,
55
"license": "GPLv3",
66
"description": "A simple MQTT client that supports MQTT5 protocol.",

src/App.vue

+3
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ export default {
6262
outline() {
6363
this.persistSettings();
6464
},
65+
closeToTray() {
66+
this.persistSettings();
67+
},
6568
clientId() {
6669
this.persistSettings();
6770
},

src/background.js

+12-3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ protocol.registerSchemesAsPrivileged([
3131
]);
3232

3333
const store = new Store();
34+
3435
let win;
3536
let tray;
3637

@@ -245,8 +246,10 @@ async function createWindow() {
245246

246247
// Close to tray
247248
win.on("close", (event) => {
248-
event.preventDefault();
249-
win.hide();
249+
if (store.get("close_to_tray") !== "false") {
250+
event.preventDefault();
251+
win.hide();
252+
}
250253
});
251254

252255
// Manage renderer messages
@@ -305,8 +308,14 @@ app.on("activate", () => {
305308
// Some APIs can only be used after this event occurs.
306309
app.on("ready", async () => createWindow());
307310

308-
app.on("before-quit", () => {
311+
app.on("before-quit", (event) => {
312+
event.preventDefault();
313+
314+
if (win) win.destroy();
309315
if (tray) tray.destroy();
316+
317+
app.removeAllListeners();
318+
app.exit();
310319
});
311320

312321
// Exit cleanly on request from parent process in development mode.

src/main.js

+4
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ Vue.mixin({
3434
outline() {
3535
return this.$store.getters.getOutline;
3636
},
37+
closeToTray() {
38+
return this.$store.getters.getCloseToTray;
39+
},
3740
darkTheme() {
3841
return (this.theme || "light") === "dark";
3942
},
@@ -81,6 +84,7 @@ Vue.mixin({
8184
},
8285
persistSettings() {
8386
this.$estore.set(this.settingsStore, JSON.stringify(this.allSettings));
87+
this.$estore.set("close_to_tray", `${this.allSettings.closeTray}`);
8488
},
8589
loadSettings() {
8690
this.$store.commit(

src/store/settings.js

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const settingsVuexModule = {
44
state: {
55
theme: "light",
66
outline: false,
7+
closeTray: true,
78
primaryColor: {
89
text: "Indie Indigo",
910
value: { light: "#3F51B5", dark: "#5C6BC0" },
@@ -18,6 +19,7 @@ const settingsVuexModule = {
1819
mutations: {
1920
setTheme: (state, theme) => (state.theme = theme),
2021
setOutline: (state, outline) => (state.outline = outline),
22+
setCloseToTray: (state, tray) => (state.closeTray = tray),
2123
setPrimaryColor: (state, primary) => (state.primaryColor = primary),
2224
setClientId: (state, clientId) => (state.clientId = clientId),
2325
setKeepalive: (state, keepalive) => (state.keepalive = keepalive),
@@ -27,6 +29,7 @@ const settingsVuexModule = {
2729
setAllSettings: (state, data) => {
2830
state.theme = data.theme || "light";
2931
state.outline = data.outline;
32+
state.closeTray = data.closeTray ?? true;
3033
// eslint-disable-next-line prettier/prettier
3134
state.primaryColor = data.primaryColor || {
3235
text: "Indie Indigo",
@@ -44,6 +47,7 @@ const settingsVuexModule = {
4447
getAllSettings: (state) => state,
4548
getTheme: (state) => state.theme,
4649
getOutline: (state) => state.outline,
50+
getCloseToTray: (state) => state.closeTray,
4751
getPrimaryColor: (state) => state.primaryColor,
4852
getClientId: (state) => state.clientId,
4953
getKeepalive: (state) => state.keepalive,

src/views/Home.vue

+22-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,20 @@
5959
</v-list-item>
6060

6161
<v-list-item>
62-
<v-switch v-model="selectedOutline" label="Outlined fields" inset />
62+
<v-list-item-content class="px-3">
63+
<div class="d-flex justify-space-between" style="gap: 1em">
64+
<v-switch
65+
v-model="selectedOutline"
66+
label="Outlined fields"
67+
inset
68+
/>
69+
<v-switch
70+
v-model="selectedCloseToTray"
71+
label="Close to system tray"
72+
inset
73+
/>
74+
</div>
75+
</v-list-item-content>
6376
</v-list-item>
6477

6578
<v-divider class="mx-3" />
@@ -396,6 +409,14 @@ export default {
396409
this.$store.commit("setOutline", newValue);
397410
},
398411
},
412+
selectedCloseToTray: {
413+
get() {
414+
return this.$store.getters.getCloseToTray;
415+
},
416+
set(newValue) {
417+
this.$store.commit("setCloseToTray", newValue);
418+
},
419+
},
399420
selectedColor: {
400421
get() {
401422
return this.$store.getters.getPrimaryColor;

0 commit comments

Comments
 (0)