forked from suyu/suyu
android: Move driver installation off of main thread
Additionally creates an indeterminate loading dialog during installation
This commit is contained in:
parent
72bef4fa95
commit
a49a24b079
4 changed files with 42 additions and 21 deletions
|
@ -17,15 +17,21 @@ import androidx.core.view.ViewCompat
|
||||||
import androidx.core.view.WindowCompat
|
import androidx.core.view.WindowCompat
|
||||||
import androidx.core.view.WindowInsetsCompat
|
import androidx.core.view.WindowInsetsCompat
|
||||||
import androidx.core.view.updatePadding
|
import androidx.core.view.updatePadding
|
||||||
|
import androidx.lifecycle.lifecycleScope
|
||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
import org.yuzu.yuzu_emu.NativeLibrary
|
import org.yuzu.yuzu_emu.NativeLibrary
|
||||||
import org.yuzu.yuzu_emu.R
|
import org.yuzu.yuzu_emu.R
|
||||||
import org.yuzu.yuzu_emu.activities.EmulationActivity
|
import org.yuzu.yuzu_emu.activities.EmulationActivity
|
||||||
import org.yuzu.yuzu_emu.databinding.ActivityMainBinding
|
import org.yuzu.yuzu_emu.databinding.ActivityMainBinding
|
||||||
|
import org.yuzu.yuzu_emu.databinding.DialogProgressBarBinding
|
||||||
import org.yuzu.yuzu_emu.features.settings.ui.SettingsActivity
|
import org.yuzu.yuzu_emu.features.settings.ui.SettingsActivity
|
||||||
import org.yuzu.yuzu_emu.model.GameProvider
|
import org.yuzu.yuzu_emu.model.GameProvider
|
||||||
import org.yuzu.yuzu_emu.ui.platform.PlatformGamesFragment
|
import org.yuzu.yuzu_emu.ui.platform.PlatformGamesFragment
|
||||||
import org.yuzu.yuzu_emu.utils.*
|
import org.yuzu.yuzu_emu.utils.*
|
||||||
|
import java.io.IOException
|
||||||
|
|
||||||
class MainActivity : AppCompatActivity(), MainView {
|
class MainActivity : AppCompatActivity(), MainView {
|
||||||
private var platformGamesFragment: PlatformGamesFragment? = null
|
private var platformGamesFragment: PlatformGamesFragment? = null
|
||||||
|
@ -200,20 +206,40 @@ class MainActivity : AppCompatActivity(), MainView {
|
||||||
Uri.parse(result!!.dataString),
|
Uri.parse(result!!.dataString),
|
||||||
takeFlags
|
takeFlags
|
||||||
)
|
)
|
||||||
GpuDriverHelper.installCustomDriver(this, result.data)
|
|
||||||
val driverName = GpuDriverHelper.customDriverName
|
val progressBinding = DialogProgressBarBinding.inflate(layoutInflater)
|
||||||
if (driverName != null) {
|
progressBinding.progressBar.isIndeterminate = true
|
||||||
Toast.makeText(
|
val installationDialog = MaterialAlertDialogBuilder(this)
|
||||||
this,
|
.setTitle(R.string.installing_driver)
|
||||||
getString(R.string.select_gpu_driver_install_success, driverName),
|
.setView(progressBinding.root)
|
||||||
Toast.LENGTH_SHORT
|
.show()
|
||||||
).show()
|
|
||||||
} else {
|
lifecycleScope.launch {
|
||||||
Toast.makeText(
|
withContext(Dispatchers.IO) {
|
||||||
this,
|
// Ignore file exceptions when a user selects an invalid zip
|
||||||
R.string.select_gpu_driver_error,
|
try {
|
||||||
Toast.LENGTH_LONG
|
GpuDriverHelper.installCustomDriver(applicationContext, result.data)
|
||||||
).show()
|
} catch (_: IOException) {}
|
||||||
|
|
||||||
|
withContext(Dispatchers.Main) {
|
||||||
|
installationDialog.dismiss()
|
||||||
|
|
||||||
|
val driverName = GpuDriverHelper.customDriverName
|
||||||
|
if (driverName != null) {
|
||||||
|
Toast.makeText(
|
||||||
|
applicationContext,
|
||||||
|
getString(R.string.select_gpu_driver_install_success, driverName),
|
||||||
|
Toast.LENGTH_SHORT
|
||||||
|
).show()
|
||||||
|
} else {
|
||||||
|
Toast.makeText(
|
||||||
|
applicationContext,
|
||||||
|
R.string.select_gpu_driver_error,
|
||||||
|
Toast.LENGTH_LONG
|
||||||
|
).show()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,11 +98,7 @@ object GpuDriverHelper {
|
||||||
)
|
)
|
||||||
|
|
||||||
// Unzip the driver.
|
// Unzip the driver.
|
||||||
try {
|
unzip(driverInstallationPath + DRIVER_INTERNAL_FILENAME, driverInstallationPath!!)
|
||||||
unzip(driverInstallationPath + DRIVER_INTERNAL_FILENAME, driverInstallationPath!!)
|
|
||||||
} catch (e: IOException) {
|
|
||||||
throw RuntimeException(e)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Initialize the driver parameters.
|
// Initialize the driver parameters.
|
||||||
initializeDriverParameters(context)
|
initializeDriverParameters(context)
|
||||||
|
@ -111,7 +107,6 @@ object GpuDriverHelper {
|
||||||
// Parse the custom driver metadata to retrieve the name.
|
// Parse the custom driver metadata to retrieve the name.
|
||||||
val customDriverName: String?
|
val customDriverName: String?
|
||||||
get() {
|
get() {
|
||||||
// Parse the custom driver metadata to retrieve the name.
|
|
||||||
val metadata = GpuDriverMetadata(driverInstallationPath + META_JSON_FILENAME)
|
val metadata = GpuDriverMetadata(driverInstallationPath + META_JSON_FILENAME)
|
||||||
return metadata.name
|
return metadata.name
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,6 @@ class GpuDriverMetadata(metadataFilePath: String) {
|
||||||
driverVersion = json.getString("driverVersion")
|
driverVersion = json.getString("driverVersion")
|
||||||
minApi = json.getInt("minApi")
|
minApi = json.getInt("minApi")
|
||||||
libraryName = json.getString("libraryName")
|
libraryName = json.getString("libraryName")
|
||||||
Log.info("Guh")
|
|
||||||
} catch (e: JSONException) {
|
} catch (e: JSONException) {
|
||||||
// JSON is malformed, ignore and treat as unsupported metadata.
|
// JSON is malformed, ignore and treat as unsupported metadata.
|
||||||
} catch (e: IOException) {
|
} catch (e: IOException) {
|
||||||
|
|
|
@ -68,6 +68,7 @@
|
||||||
<string name="select_gpu_driver_use_default">Using default GPU driver</string>
|
<string name="select_gpu_driver_use_default">Using default GPU driver</string>
|
||||||
<string name="select_gpu_driver_error">Invalid driver selected, using system default!</string>
|
<string name="select_gpu_driver_error">Invalid driver selected, using system default!</string>
|
||||||
<string name="system_gpu_driver">System GPU driver</string>
|
<string name="system_gpu_driver">System GPU driver</string>
|
||||||
|
<string name="installing_driver">Installing driver…</string>
|
||||||
|
|
||||||
<!-- Preferences Screen -->
|
<!-- Preferences Screen -->
|
||||||
<string name="preferences_settings">Settings</string>
|
<string name="preferences_settings">Settings</string>
|
||||||
|
|
Loading…
Reference in a new issue