Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 54 additions & 2 deletions src/SettingsModal/General.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<div class="flex flex-col justify-between items-center w-full">
<div class="flex flex-col justify-start items-center w-full h-full overflow-y-auto">
<!-- <div class="flex flex-row w-full justify-between px-2">
<span class="shrink-0 pt-1">Theme: </span>
<select @change="setTheme" v-model="currentTheme"
Expand All @@ -17,13 +17,28 @@
<span class="my-auto">Run on startup: </span>
<input type="checkbox" class="toggle toggle-primary mr-2" :checked="autoStartStatus" @change="toggleAutostart" />
</div>
<div class="flex flex-row w-full justify-between px-2 mt-4">
<span class="my-auto">Act when Decker disconnects: <br></span>
<input type="checkbox" class="toggle toggle-primary mr-2" :checked="actOnDeckerDisconnect" @change="toggleActOnDeckerDisconnect" />
</div>
<div v-if="actOnDeckerDisconnect" v-for="slider in sliderAmount" :key="slider" class="flex flex-row w-full justify-between px-2 mt-2">
<span class="shrink-0 pt-1">Slider {{slider}}: </span>
<select @change="sliderDisconnectHandle" v-model="selectedValues[slider - 1]"
class="select select-bordered select-sm w-2/3 mx-2 truncate">
<option class="w-full" v-for="(option, index) in sliderOptions" :value="option" :key="index">
{{ option }}
</option>
</select>
</div>
</div>
</template>

<script>

import ConfigStore from "../ts/config.ts";
import SystemSettings from "../ts/systemSettings.ts";
import { useDeckerStore } from "../store/deckerStore";
import { mapState } from "pinia";

export default {
name: "General",
Expand All @@ -32,8 +47,17 @@ export default {
themes: ["light", "dark"],
currentTheme: "",
autoStartStatus: false,
actOnDeckerDisconnect: false,
sliderOptions: ["Do nothing", "Mute", "Maximize volume"],
sliderAmount: 3,
selectedValues: [], // Array to store selected values for each slider
}
},
computed: {
...mapState(useDeckerStore, {
sliders: 'getSliders',
}),
},
methods: {
// async getTheme() {
// this.currentTheme = await ConfigStore.get("theme") || "dark";
Expand All @@ -46,7 +70,9 @@ export default {
// },
async getAutostartStatus() {
this.autoStartStatus = await SystemSettings.checkAutostartStatus();
console.log(await SystemSettings.checkAutostartStatus());
},
async getActOnDeckerDisconnect() {
this.actOnDeckerDisconnect = await ConfigStore.get("actOnDeckerDisconnect");
},
async toggleAutostart() {
if(this.autoStartStatus){
Expand All @@ -56,11 +82,37 @@ export default {
}
else await SystemSettings.enableAutostart();
this.getAutostartStatus();
},
async toggleActOnDeckerDisconnect() {
if(this.actOnDeckerDisconnect){
await ConfigStore.set("actOnDeckerDisconnect", false);
ConfigStore.save();
this.getActOnDeckerDisconnect();
return;
}
else await ConfigStore.set("actOnDeckerDisconnect", true);
ConfigStore.save();
this.getActOnDeckerDisconnect();
},
// Update the selected option for each slider, i.e do nothing, mute, maximize volume
async sliderDisconnectHandle() {
console.log(this.selectedValues);
await ConfigStore.set("sliderDisconnectHandleOptions", this.selectedValues);
ConfigStore.save();
},
async getDisconnectHandleSelectedValues() {
const storedValues = await ConfigStore.get("sliderDisconnectHandleOptions");
if(storedValues) this.selectedValues = storedValues;
else this.selectedValues = Array(this.sliderAmount).fill(this.sliderOptions[0]);
}
},
mounted() {
// this.getTheme();
this.getAutostartStatus();
this.getActOnDeckerDisconnect();
this.getDisconnectHandleSelectedValues();

this.sliderAmount = this.sliders.length; // Set the amount of sliders to the amount of sliders in the store
},
}
</script>
Expand Down
85 changes: 77 additions & 8 deletions src/ts/decker.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,99 @@
import { listen } from '@tauri-apps/api/event';
import { invoke } from '@tauri-apps/api/tauri';
import { useDeckerStore } from "../store/deckerStore.ts";
import SystemVolumeController from "./volumeControl.ts";
import ConfigStore from './config.ts';

class Decker {
private comPort: string = "";
private initiated: boolean;
// private debug: boolean;
public sliders: Array<number> = [];

constructor() {
this.comPort = "";
this.initiated = false;
}

private async initClass() {
const deckerStore = useDeckerStore();
await listen('connection-change', (event: any) => {
if(event.payload.message === "connected"){
deckerStore.setConnected(true);
this.updateSliders();
} else if (event.payload.message === "disconnected"){
this.handleSliderDisconnect();
deckerStore.setConnected(false);
}
})
}

public retryConnection(){
this.init(this.comPort);
}

private async handleSliderDisconnect(){
const actOnDeckerDisconnect = await ConfigStore.get("actOnDeckerDisconnect"); // Get the value of actOnDeckerDisconnect from config
if(!actOnDeckerDisconnect) return; // If actOnDeckerDisconnect is false, don't do anything

const sliderOptions = await ConfigStore.get("sliderDisconnectHandleOptions");

sliderOptions.forEach( (sliderOption: string, index: number) => {
sliderOption = sliderOption.toLowerCase();
if(sliderOption === "do nothing") return;

if(sliderOption === "mute"){
console.log("Muting slider", index);
SystemVolumeController.setChannelVolume(index, 0.001); // Set the volume to 0.001 to mute it, since WSAPI is a piece of work.
}

if(sliderOption === "maximize volume"){
SystemVolumeController.setChannelVolume(index, 1.0);
}

});
}

// Update sliders after reconnecting the Decker.
private async updateSliders(){
const actOnDeckerDisconnect = await ConfigStore.get("actOnDeckerDisconnect"); // Get the value of actOnDeckerDisconnect from config
console.log({actOnDeckerDisconnect});
const sliders = useDeckerStore().sliders;
if(actOnDeckerDisconnect === true){
sliders.forEach((_sliderVol, index) => {
console.log("Setting slider", index, "to 0.001");
SystemVolumeController.setChannelVolume(index, 0.001);
});
}

sliders.forEach((sliderVol, index) => {
if (sliderVol === 0) sliderVol = 0.1;

const targetVolume = sliderVol / 100;
const initialVolume = sliderVol;
const increment = 0.5; // Adjust the increment value as needed
let currentVolume = initialVolume;
if(currentVolume + increment > targetVolume) currentVolume = targetVolume; // If the current volume + increment is greater than the target volume, set the current volume to the target volume.

const graduallyIncreaseVolume = () => {
SystemVolumeController.setChannelVolume(index, currentVolume);
currentVolume += increment;

if (currentVolume <= targetVolume) {
setTimeout(graduallyIncreaseVolume, 50); // Adjust the timeout value as needed
}
};

graduallyIncreaseVolume();
});
}


public async init(comPort: string){
const deckerStore = useDeckerStore();
if(!this.initiated) this.initClass();
this.initiated = true;

const deckerStore = useDeckerStore();
this.comPort = comPort;

console.log("Connecting to Decker...", comPort)
Expand All @@ -32,13 +107,7 @@ class Decker {
});
// await invoke('init_process');

await listen('connection-change', (event: any) => {
if(event.payload.message === "connected"){
deckerStore.setConnected(true);
} else if (event.payload.message === "disconnected"){
deckerStore.setConnected(false);
}
})


const unlisten = await listen('slider-change', (event: any) => {
deckerStore.setConnected(true);
Expand Down
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2148,13 +2148,13 @@ tailwindcss@^3.1, tailwindcss@^3.3.3:

"tauri-plugin-autostart-api@https://github.com/tauri-apps/tauri-plugin-autostart#v1":
version "0.0.0"
resolved "git+ssh://git@github.com/tauri-apps/tauri-plugin-autostart.git#072ebc2914c19eb7022c90add7ea328d437d5eb2"
resolved "git+ssh://git@github.com/tauri-apps/tauri-plugin-autostart.git#7404c3ccd2e45c642e3b876500ab79d88af85e4d"
dependencies:
"@tauri-apps/api" "1.5.1"

"tauri-plugin-store-api@https://github.com/tauri-apps/tauri-plugin-store#v1":
version "0.0.0"
resolved "git+ssh://git@github.com/tauri-apps/tauri-plugin-store.git#6e19887b1bdea9b921a31993d72396a350731e07"
resolved "git+ssh://git@github.com/tauri-apps/tauri-plugin-store.git#3367248b2661abcb73d2a89f30df780c387fb57d"
dependencies:
"@tauri-apps/api" "1.5.1"

Expand Down