Skip to content

Commit a5b04ea

Browse files
committed
Removed unused clone and fixed messages
1 parent 3ab05d6 commit a5b04ea

1 file changed

Lines changed: 19 additions & 21 deletions

File tree

packages/wallpaper_generator/lib/src/wallpaper_generator.dart

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ class WallpaperGenerator {
3434
WallpaperBackground? wallpaperBackground = wallpaper.background;
3535
if (wallpaperBackground != null) {
3636

37-
updatingFunction("Working on background... setup...");
3837
Color backgroundColor = ColorFromString.fromString(wallpaperBackground.color);
3938
finalImage = fill(finalImage, color: backgroundColor);
4039

@@ -51,21 +50,22 @@ class WallpaperGenerator {
5150

5251
// If src is not null, try downloading the image.
5352
if(src != null && src.isNotEmpty) {
54-
updatingFunction("Working on background... convert the image...");
5553

5654
// Try to fetch the already decoded image
55+
updatingFunction("Try to fetch background from cache...");
5756
Image? backgroundSrcImage = await imageDatabase.fetchImage(src);
5857

5958
// Decode the image
6059
if (backgroundSrcImage == null) {
61-
updatingFunction("First time decoding the background, it may take a while...");
6260
ByteBuffer? resultBytes;
63-
61+
62+
updatingFunction("Loading the background...");
6463
final HttpRequest res = await HttpRequest.request(src, responseType: 'arraybuffer');
6564
if(res.status == 200){
6665
resultBytes = res.response as ByteBuffer;
6766
}
6867

68+
updatingFunction("First time decoding the background, it may take a while...");
6969
if(resultBytes != null) {
7070
backgroundSrcImage = decodeImage(Uint8List.view(resultBytes));
7171
if (backgroundSrcImage != null) {
@@ -76,11 +76,10 @@ class WallpaperGenerator {
7676

7777
// Apply the background image if valid
7878
if (backgroundSrcImage != null) {
79-
backgroundSrcImage = backgroundSrcImage.clone();
80-
finalImage.clear(ColorFromString.fromString(null)); // Apply default background color
81-
updatingFunction("Working on background... apply recoloring...");
79+
finalImage.clear(ColorFromString.fromString(null));
80+
updatingFunction("Recoloring the background...");
8281
backgroundSrcImage = scaleRgba(backgroundSrcImage, scale: backgroundColor);
83-
updatingFunction("Working on background... apply the background...");
82+
updatingFunction("Apply the background...");
8483
finalImage = compositeImage(finalImage, backgroundSrcImage);
8584
}
8685
}
@@ -91,48 +90,48 @@ class WallpaperGenerator {
9190
if (wallpaperLogos != null) {
9291
for (int i = 0; i < wallpaperLogos.length; i++) {
9392
WallpaperLogo wallpaperLogo = wallpaperLogos[i];
94-
updatingFunction("Working on logo [${i + 1}/${wallpaperLogos.length}]... setup...");
9593
String? src;
9694
String? type = wallpaperLogo.type;
9795
String? name = wallpaperLogo.name;
9896
double size = wallpaperLogo.size;
9997
WallpaperLogoPosition? position = wallpaperLogo.position;
10098

10199
// Inject the src from name
100+
PathUrl? path;
102101
if(name != null && name.isNotEmpty && type != null && type.isNotEmpty) {
103102
switch(type)
104103
{
105104
case "octocat":
106-
PathUrl? octocatSrc = octocats.search(name);
107-
if(octocatSrc != null) {
108-
src = octocatSrc.getFullPath();
109-
}
105+
path = octocats.search(name);
110106
break;
111107
case "logo":
112-
PathUrl? logoSrc = logos.search(name);
113-
if(logoSrc != null) {
114-
src = logoSrc.getFullPath();
115-
}
108+
path = logos.search(name);
116109
break;
117110
}
118111
}
112+
113+
if(path != null) {
114+
src = path.getFullPath();
115+
}
119116

120117
// If src is not null, try downloading the image.
121118
if(src != null && src.isNotEmpty) {
122119

123120
// Try to hit the image from cache or get via http
121+
updatingFunction("Try to fetch logo '${path!.getFileName(false)}' from cache...");
124122
Image? logoSrcImage = await imageDatabase.fetchImage(src);
125123

126124
// Decode the image
127125
if(logoSrcImage == null) {
128-
updatingFunction("Decoding the logo [${i + 1}/${wallpaperLogos.length}]...");
129126
ByteBuffer? resultBytes;
130127

128+
updatingFunction("Fetch the logo '${path.getFileName(false)}' from the web...");
131129
final HttpRequest res = await HttpRequest.request(src, responseType: 'arraybuffer');
132130
if(res.status == 200){
133131
resultBytes = res.response as ByteBuffer;
134132
}
135133

134+
updatingFunction("First time decoding the logo '${path.getFileName(false)}', it may take a while...");
136135
if(resultBytes != null) {
137136
logoSrcImage = decodeImage(Uint8List.view(resultBytes));
138137
if (logoSrcImage != null) {
@@ -143,10 +142,9 @@ class WallpaperGenerator {
143142

144143
// The logo is not valid, to the next logo...
145144
if (logoSrcImage == null) continue;
146-
logoSrcImage = logoSrcImage.clone();
147145

148146
// Apply the color by multiplication
149-
updatingFunction("Working on logo [${i + 1}/${wallpaperLogos.length}]... apply recoloring...");
147+
updatingFunction("Recoloring of logo '${path.getFileName(false)}'...");
150148
Color color = ColorFromString.fromString(wallpaperLogo.color);
151149
logoSrcImage = scaleRgba(logoSrcImage, scale: color, mask: logoSrcImage, maskChannel: Channel.alpha);
152150

@@ -160,7 +158,7 @@ class WallpaperGenerator {
160158
double centerX = ((wallpaperWidth * logoPosX) - logoWidth / 2);
161159
double centerY = ((wallpaperHeight * logoPosY) - logoHeight / 2);
162160

163-
updatingFunction("Working on logo [${i + 1}/${wallpaperLogos.length}]... apply the logo...");
161+
updatingFunction("Apply the logo '${path.getFileName(false)}'...");
164162

165163
// Apply the logo into the final image
166164
finalImage = compositeImage(

0 commit comments

Comments
 (0)