Skip to content

Commit

Permalink
#1306 Don't launch a scan on very first start. Only trigger it once w…
Browse files Browse the repository at this point in the history
…e're done with the startup wizard.

Signed-off-by: Michael Herger <michael@herger.net>
  • Loading branch information
michaelherger committed Jan 24, 2025
1 parent 40db8ec commit 607e288
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 61 deletions.
1 change: 1 addition & 0 deletions Changelog9.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ <h2><a name="v9.0.2" id="v9.0.2"></a>Version 9.0.2</h2>
<li><a href="https://github.com/LMS-Community/slimserver/issues/1193">#1193</a> - Don't throw error when fulltext search is being used before the end of a scan.</li>
<li><a href="https://github.com/LMS-Community/slimserver/issues/1288">#1288</a> - Update Carp::Assert to latest to fix compatibility with recent Perl versions.</li>
<li><a href="https://github.com/LMS-Community/slimserver/pull/1303">#1303</a> - Fix an issue where browsing releases would sometimes create thousands of parameters (and more - thanks @darrel-k!).</li>
<li><a href="https://github.com/LMS-Community/slimserver/pull/1306">#1306</a> - Don't run the scanner before we're done with the setup wizard.</li>
<li><a href="https://github.com/LMS-Community/slimserver/pull/1307">#1307</a> - Fix scanner progress information in the web UI.</li>
<li></li>
</ul>
Expand Down
2 changes: 1 addition & 1 deletion Slim/Web/Settings/Server/Basic.pm
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ sub handler {
my ($class, $client, $paramRef) = @_;

# tell the server not to trigger a rescan immediately, but let it queue up requests
# this is neede to prevent multiple scans to be triggered by change handlers for paths etc.
# this is needed to prevent multiple scans to be triggered by change handlers for paths etc.
Slim::Music::Import->doQueueScanTasks(1);
my $runScan;

Expand Down
121 changes: 62 additions & 59 deletions Slim/Web/Settings/Server/Wizard.pm
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ sub page {
sub handler {
my ($class, $client, $paramRef, $pageSetup, $httpClient, $response) = @_;

# tell the server not to trigger a rescan immediately, but let it queue up requests
# this is needed to prevent multiple scans to be triggered by change handlers for paths etc.
Slim::Music::Import->doQueueScanTasks(1);
my $scanOnChange = $serverPrefs->get('dontTriggerScanOnPrefChange');
$serverPrefs->set('dontTriggerScanOnPrefChange', 0);

$paramRef->{languageoptions} = Slim::Utils::Strings::languageOptions();

# redirect to the Default skin if another skin is set
Expand Down Expand Up @@ -99,17 +105,61 @@ sub handler {
# set right-to-left orientation for Hebrew users
$paramRef->{rtl} = 1 if ($paramRef->{prefs}->{language} eq 'HE');

foreach my $pref (@prefs) {
# install plugins if needed
if ($paramRef->{saveSettings}) {
@pluginsToInstall = ();
for my $param (keys %$paramRef) {
if ($paramRef->{$param} && $param =~ /^plugin-(.*)$/) {
# my $plugin = $1;
push @pluginsToInstall, $1;
}
}

if ($paramRef->{saveSettings}) {
@pluginsToInstall = ();
for my $param (keys %$paramRef) {
if ($paramRef->{$param} && $param =~ /^plugin-(.*)$/) {
# my $plugin = $1;
push @pluginsToInstall, $1;
Slim::Utils::ExtensionsManager::getAllPluginRepos({
type => 'plugin',
cb => sub {
my ($pluginData, $error) = @_;

my (undef, undef, $inactive) = Slim::Utils::ExtensionsManager::getCurrentPlugins();

my %pluginLookup;
foreach (@$pluginData, @$inactive) {
$pluginLookup{$_->{name}} = $_;
}

foreach my $plugin (@pluginsToInstall) {
Slim::Utils::ExtensionsManager->enablePlugin($plugin);
my $pluginDetails = $pluginLookup{$plugin} || {};

if ($pluginDetails->{url} && $pluginDetails->{sha}) {
main::INFOLOG && $log->is_info && $log->info("Downloading plugin: $plugin");

# 3rd party plugin - needs to be downloaded
Slim::Utils::PluginDownloader->install({
name => $plugin,
url => $pluginDetails->{url},
sha => lc($pluginDetails->{sha})
});

}
elsif ($pluginDetails->{version}) {
# built-in plugin - install
main::INFOLOG && $log->is_info && $log->info("Installing plugin: $plugin");
Slim::Utils::PluginManager->_needsEnable($plugin);
Slim::Utils::PluginManager->load('', $plugin);
}
}
}

if (scalar @pluginsToInstall) {
Slim::Utils::Timers::killTimers(undef, \&_checkPluginDownloads);
Slim::Utils::Timers::setTimer(undef, time() + 1, \&_checkPluginDownloads);
}
},
});
}

foreach my $pref (@prefs) {
if ($paramRef->{saveSettings}) {
# if a scan is running and one of the music sources has changed, abort scan
if (
( ($pref eq 'playlistdir' && $paramRef->{$pref} ne $serverPrefs->get($pref))
Expand All @@ -120,66 +170,15 @@ sub handler {
Slim::Music::Import->abortScan();
}

# revert logic: while the pref is "disable", the UI is opt-in
# if this value is set we actually want to not disable it...
elsif ($pref eq 'sn_disable_stats') {
$paramRef->{$pref} = $paramRef->{$pref} ? 0 : 1;
}

if ($pref eq 'mediadirs') {
my $dirs = $serverPrefs->get($pref);
unshift @$dirs, $paramRef->{$pref};

my $scanOnChange = $serverPrefs->get('dontTriggerScanOnPrefChange');
$serverPrefs->set('dontTriggerScanOnPrefChange', 0);
$serverPrefs->set($pref, [ Slim::Utils::Misc::uniq(@$dirs) ]);
$serverPrefs->set('dontTriggerScanOnPrefChange', $scanOnChange) if $scanOnChange;
}
else {
$serverPrefs->set($pref, $paramRef->{$pref});
}

Slim::Utils::ExtensionsManager::getAllPluginRepos({
type => 'plugin',
cb => sub {
my ($pluginData, $error) = @_;

my (undef, undef, $inactive) = Slim::Utils::ExtensionsManager::getCurrentPlugins();

my %pluginLookup;
foreach (@$pluginData, @$inactive) {
$pluginLookup{$_->{name}} = $_;
}

foreach my $plugin (@pluginsToInstall) {
Slim::Utils::ExtensionsManager->enablePlugin($plugin);
my $pluginDetails = $pluginLookup{$plugin} || {};

if ($pluginDetails->{url} && $pluginDetails->{sha}) {
main::INFOLOG && $log->is_info && $log->info("Downloading plugin: $plugin");

# 3rd party plugin - needs to be downloaded
Slim::Utils::PluginDownloader->install({
name => $plugin,
url => $pluginDetails->{url},
sha => lc($pluginDetails->{sha})
});

}
elsif ($pluginDetails->{version}) {
# built-in plugin - install
main::INFOLOG && $log->is_info && $log->info("Installing plugin: $plugin");
Slim::Utils::PluginManager->_needsEnable($plugin);
Slim::Utils::PluginManager->load('', $plugin);
}
}

if (scalar @pluginsToInstall) {
Slim::Utils::Timers::killTimers(undef, \&_checkPluginDownloads);
Slim::Utils::Timers::setTimer(undef, time() + 1, \&_checkPluginDownloads);
}
},
});
}

if (main::DEBUGLOG && $log->is_debug) {
Expand Down Expand Up @@ -209,6 +208,10 @@ sub handler {
$paramRef->{plugins} = $wzData->{plugins};
$paramRef->{pluginsJSON} = to_json($paramRef->{plugins});

$serverPrefs->set('dontTriggerScanOnPrefChange', $scanOnChange) if $scanOnChange;
Slim::Music::Import->doQueueScanTasks(0);
Slim::Music::Import->nextScanTask();

# if the wizard has been run for the first time, redirect to the main we page
if ($paramRef->{firstTimeRunCompleted}) {
$response->code(RC_MOVED_TEMPORARILY);
Expand Down
2 changes: 1 addition & 1 deletion slimserver.pl
Original file line number Diff line number Diff line change
Expand Up @@ -1093,7 +1093,7 @@ sub checkDataSource {

$prefs->set('mediadirs', $mediadirs) if $modified;

return if !Slim::Schema::hasLibrary();
return if !Slim::Schema::hasLibrary() || !$prefs->get('wizardDone');

$sqlHelperClass->checkDataSource();

Expand Down

0 comments on commit 607e288

Please sign in to comment.