Skip to content

Commit

Permalink
Merge branch 'main' of github.com:pre-martin/StreamDeckSimHubPlugin
Browse files Browse the repository at this point in the history
  • Loading branch information
pre-martin committed Aug 31, 2024
2 parents 94dd7c4 + 700be8a commit 433f46b
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 107 deletions.
17 changes: 10 additions & 7 deletions StreamDeckSimHub.Plugin/StreamDeckSimHub.Plugin.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,30 +42,33 @@
<None Update="manifest.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="pi\input.html">
<None Update="pi\js\common.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="pi\js\input.js">
<None Update="pi\js\shakeit.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="pi\hotkey.html">
<None Update="pi\js\simhubrole.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="pi\js\shakeit.js">
<None Update="pi\input.html">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="pi\js\simhubrole.js">
<None Update="pi\js\input.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="pi\js\hotkey.js">
<None Update="pi\hotkey.html">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="pi\js\hotkey4.js">
<None Update="pi\js\hotkey.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="pi\hotkey4.html">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="pi\js\hotkey4.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="pi\dial.html">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down
1 change: 1 addition & 0 deletions StreamDeckSimHub.Plugin/pi/dial.html
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@
<script src="libs/js/api.js"></script>
<script src="libs/js/property-inspector.js"></script>
<script src="libs/js/utils.js"></script>
<script src="js/common.js"></script>
<script src="js/shakeit.js"></script>
<script src="js/simhubrole.js"></script>
<script src="js/dial.js"></script>
Expand Down
1 change: 1 addition & 0 deletions StreamDeckSimHub.Plugin/pi/hotkey.html
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
<script src="libs/js/api.js"></script>
<script src="libs/js/property-inspector.js"></script>
<script src="libs/js/utils.js"></script>
<script src="js/common.js"></script>
<script src="js/shakeit.js"></script>
<script src="js/simhubrole.js"></script>
<script src="js/hotkey.js"></script>
Expand Down
1 change: 1 addition & 0 deletions StreamDeckSimHub.Plugin/pi/hotkey4.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
<script src="libs/js/api.js"></script>
<script src="libs/js/property-inspector.js"></script>
<script src="libs/js/utils.js"></script>
<script src="js/common.js"></script>
<script src="js/hotkey4.js"></script>

</body>
Expand Down
1 change: 1 addition & 0 deletions StreamDeckSimHub.Plugin/pi/input.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<script src="libs/js/api.js"></script>
<script src="libs/js/property-inspector.js"></script>
<script src="libs/js/utils.js"></script>
<script src="js/common.js"></script>
<script src="js/input.js"></script>

</body>
Expand Down
42 changes: 42 additions & 0 deletions StreamDeckSimHub.Plugin/pi/js/common.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* Iterates over all elements in the array "settingIds", retrieves the values of their corresponding HTML elements, and stores
* them in a payload structure. This structure can be saved by the Property Inspector.
*/
const buildSettings = (settingIds) => {
let settings = {};
for (const id of settingIds) {
const element = document.getElementById(id);
if (!element) {
console.log('buildSettings: Could not find element ' + id + ' on page');
$PI.logMessage('buildSettings: Could not find element ' + id + ' on page');
continue;
}
if (element.getAttribute('type') === 'checkbox') {
settings[id] = element.checked;
} else {
settings[id] = element.value;
}
}

return settings;
}

/**
* Iterates over the structure "settings". The keys are used to find corresponding HTML elements, the value is then set
* as value of the HTML element.
*/
const restoreSettings = (settings) => {
for (const id in settings) {
try {
const element = document.getElementById(id);
if (element.getAttribute('type') === 'checkbox') {
element.checked = settings[id];
} else {
element.value = settings[id];
}
} catch (err) {
console.log('loadSettings failed for id ' + id + ': ' + err);
$PI.logMessage('loadSettings failed for id ' + id + ': ' + err);
}
}
}
27 changes: 2 additions & 25 deletions StreamDeckSimHub.Plugin/pi/js/dial.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,7 @@ $PI.onConnected(async jsn => {
});

function loadSettings(settings) {
for (const id in settings) {
try {
const element = document.getElementById(id);
if (!element) continue;

if (element.getAttribute('type') === 'checkbox') {
element.checked = settings[id];
} else {
element.value = settings[id];
}
} catch (err) {
console.log('loadSettings failed for id ' + id + ': ' + err);
$PI.logMessage('loadSettings failed for id ' + id + ': ' + err);
}
}
restoreSettings(settings);

$ShakeIt.resolvePropertyNameFromCache(document.getElementById('simhubProperty'));
$ShakeIt.resolvePropertyNameFromCache(document.getElementById('displaySimhubProperty'));
Expand All @@ -64,16 +50,7 @@ function saveSettings() {
'displaySimhubProperty', 'displaySimhubPropertyClearNameCache', 'displayFormat'
];

let payload = {};
for (const id of settingIds) {
const element = document.getElementById(id);
if (element.getAttribute('type') === 'checkbox') {
payload[id] = element.checked;
} else {
payload[id] = element.value;
}
}

const payload = buildSettings(settingIds);
$PI.setSettings(payload);
}

Expand Down
33 changes: 2 additions & 31 deletions StreamDeckSimHub.Plugin/pi/js/hotkey.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,7 @@ function loadSettings(settings) {
settings['longKeypressTimeSpan'] = 500;
}

for (const id in settings) {
try {
const element = document.getElementById(id);
if (!element) continue;

if (element.getAttribute('type') === 'checkbox') {
element.checked = settings[id];
} else {
element.value = settings[id];
}
} catch (err) {
console.log('loadSettings failed for id ' + id + ': ' + err);
$PI.logMessage('loadSettings failed for id ' + id + ': ' + err);
}
}

restoreSettings(settings);
$ShakeIt.resolvePropertyNameFromCache(document.getElementById('simhubProperty'));
$ShakeIt.resolvePropertyNameFromCache(document.getElementById('titleSimhubProperty'));
}
Expand All @@ -68,21 +53,7 @@ function saveSettings() {
'titleSimhubProperty', 'titleSimhubPropertyClearNameCache', 'titleFormat'
];

let payload = {};
for (const id of settingIds) {
const element = document.getElementById(id);
if (!element) {
console.log('Save: Could not find element ' + id + ' on page!');
$PI.logMessage('Save: Could not find element ' + id + ' on page');
continue;
}
if (element.getAttribute('type') === 'checkbox') {
payload[id] = element.checked;
} else {
payload[id] = element.value;
}
}

let payload = buildSettings(settingIds);
// Adjust flat object so that it fits to the server side JSON object. This also means that these settings will be saved
// twice, but that is not a problem.
payload['longKeypressSettings'] = {};
Expand Down
24 changes: 2 additions & 22 deletions StreamDeckSimHub.Plugin/pi/js/hotkey4.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,14 @@ $PI.onConnected(jsn => {
});

function loadSettings(settings) {
for (const id in settings) {
try {
const element = document.getElementById(id);
if (element.getAttribute('type') === 'checkbox') {
element.checked = settings[id];
} else {
element.value = settings[id];
}
} catch (err) {
$PI.logMessage('loadSettings failed for id ' + id + ': ' + err);
}
}
restoreSettings(settings);
}

const saveSettingsDelayed = Utils.debounce(500, () => saveSettings());

function saveSettings() {
const settingIds = ['hotkey', 'ctrl', 'alt', 'shift', 'simhubControl', 'simhubProperty'];

let payload = {};
for (const id of settingIds) {
const element = document.getElementById(id);
if (element.getAttribute('type') === 'checkbox') {
payload[id] = element.checked;
} else {
payload[id] = element.value;
}
}

const payload = buildSettings(settingIds);
$PI.setSettings(payload);
}
24 changes: 2 additions & 22 deletions StreamDeckSimHub.Plugin/pi/js/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,14 @@ $PI.onConnected(jsn => {
});

function loadSettings(settings) {
for (const id in settings) {
try {
const element = document.getElementById(id);
if (element.getAttribute('type') === 'checkbox') {
element.checked = settings[id];
} else {
element.value = settings[id];
}
} catch (err) {
$PI.logMessage('loadSettings failed for id ' + id + ': ' + err);
}
}
restoreSettings(settings);
}

const saveSettingsDelayed = Utils.debounce(500, () => saveSettings());

function saveSettings() {
const settingIds = ['simhubControl'];

let payload = {};
for (const id of settingIds) {
const element = document.getElementById(id);
if (element.getAttribute('type') === 'checkbox') {
payload[id] = element.checked;
} else {
payload[id] = element.value;
}
}

const payload = buildSettings(settingIds);
$PI.setSettings(payload);
}

0 comments on commit 433f46b

Please sign in to comment.