Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add option to generate random seed #8

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
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