Skip to content

Commit

Permalink
progress bar when changing theme
Browse files Browse the repository at this point in the history
  • Loading branch information
vdesabou authored and vdesabou committed Jan 6, 2017
1 parent ef0331f commit 4a953d8
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
26 changes: 26 additions & 0 deletions spotify-mini-player/src/functions.php
Expand Up @@ -130,6 +130,12 @@ function invokeMopidyMethod($w, $method, $params, $displayError = true)
*/
function switchThemeColor($w,$theme_color)
{
touch($w->data().'/change_theme_color_in_progress');
$nb_images_downloaded = 0;
$nb_images_total = 222;
$w->write('Change Theme Color▹'. 0 .'▹'. $nb_images_total .'▹'.time().'▹'.'starting', 'change_theme_color_in_progress');
$in_progress_data = $w->read('change_theme_color_in_progress');
$words = explode('▹', $in_progress_data);

// Read settings from JSON

Expand All @@ -155,6 +161,11 @@ function switchThemeColor($w,$theme_color)
);

$w->request("$icon_url", $options);

++$nb_images_downloaded;
if ($nb_images_downloaded % 10 === 0) {
$w->write('Change Theme Color▹'.$nb_images_downloaded.'▹'.$nb_images_total.'▹'.$words[3].'▹'.'Icons', 'change_theme_color_in_progress');
}
}

// check icons from images directory
Expand Down Expand Up @@ -267,6 +278,10 @@ function switchThemeColor($w,$theme_color)
);

$w->request("$icon_url", $options);
++$nb_images_downloaded;
if ($nb_images_downloaded % 10 === 0) {
$w->write('Change Theme Color▹'.$nb_images_downloaded.'▹'.$nb_images_total.'▹'.$words[3].'▹'.'Icons UUID', 'change_theme_color_in_progress');
}
}

// check UUID images
Expand Down Expand Up @@ -335,6 +350,11 @@ function switchThemeColor($w,$theme_color)
);

$w->request("$icon_url", $options);

++$nb_images_downloaded;
if ($nb_images_downloaded % 10 === 0) {
$w->write('Change Theme Color▹'.$nb_images_downloaded.'▹'.$nb_images_total.'▹'.$words[3].'▹'.'Icons remote', 'change_theme_color_in_progress');
}
}

// check UUID images
Expand Down Expand Up @@ -363,6 +383,11 @@ function switchThemeColor($w,$theme_color)
);

$w->request("$icon_url", $options);

++$nb_images_downloaded;
if ($nb_images_downloaded % 10 === 0) {
$w->write('Change Theme Color▹'.$nb_images_downloaded.'▹'.$nb_images_total.'▹'.$words[3].'▹'.'Icons UUID remote page', 'change_theme_color_in_progress');
}
}

// check UUID images
Expand Down Expand Up @@ -390,6 +415,7 @@ function switchThemeColor($w,$theme_color)
logMsg('Error(switchThemeColor): (failed to load Spotify Mini Player.app for '.$theme_color.')');
}

deleteTheFile($w->data().'/change_theme_color_in_progress');
if (!$hasError) {
displayNotificationWithArtwork($w, 'All existing icons have been replaced by ' . $theme_color . ' icons', './images/change_theme_color.png', 'Settings');
} else {
Expand Down
14 changes: 14 additions & 0 deletions spotify-mini-player/src/main.php
Expand Up @@ -92,6 +92,20 @@
}
}

// check for download artworks in progress
$change_theme_color_in_progress = false;
if (file_exists($w->data().'/change_theme_color_in_progress')) {
$in_progress_data = $w->read('change_theme_color_in_progress');
$change_theme_color_in_progress_words = explode('▹', $in_progress_data);
$elapsed_time = time() - $change_theme_color_in_progress_words[3];
$change_theme_color_in_progress = true;
if ($change_theme_color_in_progress_words[2] != 0) {
$w->result(null, $w->data().'/change_theme_color_in_progress', $change_theme_color_in_progress_words[0].' in progress since '.beautifyTime($elapsed_time, true).' : '.floatToSquares(intval($change_theme_color_in_progress_words[1]) / intval($change_theme_color_in_progress_words[2])), $change_theme_color_in_progress_words[1].'/'.$change_theme_color_in_progress_words[2].' icons processed so far (empty icons can be seen until full download is complete)', './images/update_in_progress.png', 'no', null, '');
} else {
$w->result(null, $w->data().'/change_theme_color_in_progress', $change_theme_color_in_progress_words[0].' in progress since '.beautifyTime($elapsed_time, true).' : '.floatToSquares(0), 'No icons processed so far (empty icons can be seen until full download is complete)', './images/update_in_progress.png', 'no', null, '');
}
}

// Read settings from JSON

$settings = getSettings($w);
Expand Down

0 comments on commit 4a953d8

Please sign in to comment.