Skip to content

Commit

Permalink
feat: add option to generate random seed
Browse files Browse the repository at this point in the history
  • Loading branch information
Attacktive committed Nov 30, 2023
1 parent 15a3a8d commit 3f744a0
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
4 changes: 4 additions & 0 deletions contents/config/main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@
<label>Need this to enable a refetch button in the config page that bypasses the apply button.</label>
<default>false</default>
</entry>
<entry name="Random Seed" type="bool">
<label>Enable random seed.</label>
<default>false</default>
</entry>
</group>

</kcfg>
13 changes: 13 additions & 0 deletions contents/ui/config.qml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ ColumnLayout {

property string cfg_SearchColor

property bool cfg_RandomSeed

Image {
id: currentWallpaper
source: wallpaper.configuration.currentWallpaperThumbnail
Expand Down Expand Up @@ -288,6 +290,17 @@ ColumnLayout {
}
}
}

RowLayout {
Kirigami.FormData.label: i18n("Random seed")
CheckBox {
text: i18n("Enable")
checked: cfg_RandomSeed
onToggled: {
cfg_RandomSeed = checked;
}
}
}
}

Label {
Expand Down
16 changes: 16 additions & 0 deletions contents/ui/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ QQC2.StackView {

url += `ratios=${encodeURIComponent(root.aspectRatio)}&`

if (wallpaper.configuration.RandomSeed) {
url += `seed=${generateSeed()}`
}

url += `q=${encodeURIComponent(wallpaper.configuration.Query)}`
console.error('using url: ' + url);

Expand Down Expand Up @@ -239,6 +243,18 @@ QQC2.StackView {
pendingImage = null;
}

function generateSeed() {
const characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
const generatedCharacters = [];

for (let i = 0; i < 6; i++) {
const randomIndex = Math.floor(Math.random() * characters.length);
generatedCharacters.push(characters.charAt(randomIndex));
}

return generatedCharacters.join('');
}

replaceEnter: Transition {
OpacityAnimator {
id: replaceEnterOpacityAnimator
Expand Down

0 comments on commit 3f744a0

Please sign in to comment.