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

Adding Manually Update Plugins #1512

Open
wants to merge 5 commits into
base: master
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
1 change: 1 addition & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,80 @@ object PluginManager {
}
}

fun manuallyReloadAndUpdatePlugins(activity: Activity) {
phisher98 marked this conversation as resolved.
Show resolved Hide resolved
showToast("Starting plugin update process!", Toast.LENGTH_LONG)

// Load all online plugins
loadAllOnlinePlugins(activity)
afterPluginsLoadedEvent.invoke(false)

val urls = (getKey<Array<RepositoryData>>(REPOSITORIES_KEY)
?: emptyArray()) + PREBUILT_REPOSITORIES

val onlinePlugins = urls.toList().apmap {
getRepoPlugins(it.url)?.toList() ?: emptyList()
}.flatten().distinctBy { it.second.url }

// Collect all saved plugins and map them to the online plugins for updates
val allPlugins = getPluginsOnline().map { savedData ->
onlinePlugins
.filter { onlineData -> savedData.internalName == onlineData.second.internalName }
.map { onlineData ->
OnlinePluginData(savedData, onlineData)
}.filter {
it.validOnlineData(activity) // Ensure valid data
}
}.flatten().distinctBy { it.onlineData.second.url }

val updatedPlugins = mutableListOf<String>()

// Process updates
allPlugins.apmap { pluginData ->
if (pluginData.isDisabled) {
// Unload disabled plugins
Log.d("PluginManager", "Unloading disabled plugin: ${pluginData.onlineData.second.name}")
unloadPlugin(pluginData.savedData.filePath)
} else {
// Ensure the existing plugin file is deleted before downloading the new version
val existingFile = File(pluginData.savedData.filePath)
if (existingFile.exists()) {
existingFile.delete() // Delete the existing file
}

downloadPlugin(
activity,
pluginData.onlineData.second.url,
pluginData.savedData.internalName,
File(pluginData.savedData.filePath),
true // Force overwrite
).let { success ->
if (success) {
updatedPlugins.add(pluginData.onlineData.second.name)
}
}
}
}.also {
// Show toast after all updates are completed
main {
if (updatedPlugins.isNotEmpty()) {
val updatedCount = updatedPlugins.size
showToast("Successfully updated $updatedCount plugin(s)!", Toast.LENGTH_LONG)
} else {
showToast("No plugins were updated.", Toast.LENGTH_LONG)
}

// Create a notification with the update results
val uitext = txt(R.string.plugins_updated, updatedPlugins.size)
createNotification(activity, uitext, updatedPlugins)
}
}

loadedOnlinePlugins = true
afterPluginsLoadedEvent.invoke(false)

Log.i("PluginManager", "Plugin update done!")
}

private fun Context.createNotificationChannel() {
hasCreatedNotChanel = true
// Create the NotificationChannel, but only on API 26+ because
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import com.lagradost.cloudstream3.databinding.LogcatBinding
import com.lagradost.cloudstream3.mvvm.logError
import com.lagradost.cloudstream3.mvvm.normalSafeApiCall
import com.lagradost.cloudstream3.network.initClient
import com.lagradost.cloudstream3.plugins.PluginManager
import com.lagradost.cloudstream3.services.BackupWorkManager
import com.lagradost.cloudstream3.utils.txt
import com.lagradost.cloudstream3.ui.settings.Globals.EMULATOR
Expand Down Expand Up @@ -259,6 +260,13 @@ class SettingsUpdates : PreferenceFragmentCompat() {
}
return@setOnPreferenceClickListener true
}

getPref(R.string.manual_update_plugins_key)?.setOnPreferenceClickListener {
ioSafe {
PluginManager.manuallyReloadAndUpdatePlugins(activity ?: return@ioSafe)
}
return@setOnPreferenceClickListener true // Return true for the listener
}
}

private fun getBackupDirsForDisplay(): List<String> {
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -832,4 +832,7 @@
<string name="software_decoding_key" translatable="false">software_decoding_key</string>
<string name="software_decoding">Software decoding</string>
<string name="software_decoding_desc">Software decoding enables the player to play video files not supported by your phone, but may cause laggy or unstable playback on high resolution</string>
<string name="update_plugins">Update Plugins</string>
<string name="update_plugins_manually">Update plugins manually!!</string>
<string name="manual_update_plugins_key" translatable="false">manual_update_plugins</string>
</resources>
6 changes: 6 additions & 0 deletions app/src/main/res/xml/settings_updates.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@
android:key="@string/auto_download_plugins_key"
android:title="@string/automatic_plugin_download"
android:summary="@string/automatic_plugin_download_summary" />

<Preference
android:icon="@drawable/ic_baseline_extension_24"
android:key="@string/manual_update_plugins_key"
android:title="@string/update_plugins"
android:summary="@string/update_plugins_manually"/>
</PreferenceCategory>

<PreferenceCategory
Expand Down