Skip to content

Commit

Permalink
Merge pull request #42 from Omniaevo/develop
Browse files Browse the repository at this point in the history
Close to tray in settings
  • Loading branch information
BlazeRed committed Feb 16, 2024
2 parents 9635aa5 + c5101e5 commit d41693b
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mqtt5-explorer",
"version": "1.11.0",
"version": "1.12.0",
"private": false,
"license": "GPLv3",
"description": "A simple MQTT client that supports MQTT5 protocol.",
Expand Down
3 changes: 3 additions & 0 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ export default {
outline() {
this.persistSettings();
},
closeToTray() {
this.persistSettings();
},
clientId() {
this.persistSettings();
},
Expand Down
15 changes: 12 additions & 3 deletions src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ protocol.registerSchemesAsPrivileged([
]);

const store = new Store();

let win;
let tray;

Expand Down Expand Up @@ -245,8 +246,10 @@ async function createWindow() {

// Close to tray
win.on("close", (event) => {
event.preventDefault();
win.hide();
if (store.get("close_to_tray") !== "false") {
event.preventDefault();
win.hide();
}
});

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

app.on("before-quit", () => {
app.on("before-quit", (event) => {
event.preventDefault();

if (win) win.destroy();
if (tray) tray.destroy();

app.removeAllListeners();
app.exit();
});

// Exit cleanly on request from parent process in development mode.
Expand Down
4 changes: 4 additions & 0 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ Vue.mixin({
outline() {
return this.$store.getters.getOutline;
},
closeToTray() {
return this.$store.getters.getCloseToTray;
},
darkTheme() {
return (this.theme || "light") === "dark";
},
Expand Down Expand Up @@ -81,6 +84,7 @@ Vue.mixin({
},
persistSettings() {
this.$estore.set(this.settingsStore, JSON.stringify(this.allSettings));
this.$estore.set("close_to_tray", `${this.allSettings.closeTray}`);
},
loadSettings() {
this.$store.commit(
Expand Down
4 changes: 4 additions & 0 deletions src/store/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const settingsVuexModule = {
state: {
theme: "light",
outline: false,
closeTray: true,
primaryColor: {
text: "Indie Indigo",
value: { light: "#3F51B5", dark: "#5C6BC0" },
Expand All @@ -18,6 +19,7 @@ const settingsVuexModule = {
mutations: {
setTheme: (state, theme) => (state.theme = theme),
setOutline: (state, outline) => (state.outline = outline),
setCloseToTray: (state, tray) => (state.closeTray = tray),
setPrimaryColor: (state, primary) => (state.primaryColor = primary),
setClientId: (state, clientId) => (state.clientId = clientId),
setKeepalive: (state, keepalive) => (state.keepalive = keepalive),
Expand All @@ -27,6 +29,7 @@ const settingsVuexModule = {
setAllSettings: (state, data) => {
state.theme = data.theme || "light";
state.outline = data.outline;
state.closeTray = data.closeTray ?? true;
// eslint-disable-next-line prettier/prettier
state.primaryColor = data.primaryColor || {
text: "Indie Indigo",
Expand All @@ -44,6 +47,7 @@ const settingsVuexModule = {
getAllSettings: (state) => state,
getTheme: (state) => state.theme,
getOutline: (state) => state.outline,
getCloseToTray: (state) => state.closeTray,
getPrimaryColor: (state) => state.primaryColor,
getClientId: (state) => state.clientId,
getKeepalive: (state) => state.keepalive,
Expand Down
23 changes: 22 additions & 1 deletion src/views/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,20 @@
</v-list-item>

<v-list-item>
<v-switch v-model="selectedOutline" label="Outlined fields" inset />
<v-list-item-content class="px-3">
<div class="d-flex justify-space-between" style="gap: 1em">
<v-switch
v-model="selectedOutline"
label="Outlined fields"
inset
/>
<v-switch
v-model="selectedCloseToTray"
label="Close to system tray"
inset
/>
</div>
</v-list-item-content>
</v-list-item>

<v-divider class="mx-3" />
Expand Down Expand Up @@ -396,6 +409,14 @@ export default {
this.$store.commit("setOutline", newValue);
},
},
selectedCloseToTray: {
get() {
return this.$store.getters.getCloseToTray;
},
set(newValue) {
this.$store.commit("setCloseToTray", newValue);
},
},
selectedColor: {
get() {
return this.$store.getters.getPrimaryColor;
Expand Down

0 comments on commit d41693b

Please sign in to comment.