mirror of
https://gitlab.futo.org/videostreaming/grayjay.git
synced 2025-09-18 15:32:35 +00:00
Change when plugins are disabled on reload and listing reloads
This commit is contained in:
parent
8c1a18d8b4
commit
a9bb900994
2 changed files with 44 additions and 22 deletions
|
@ -177,16 +177,11 @@ class StatePlatform {
|
||||||
}
|
}
|
||||||
|
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
|
var toDisables = mutableListOf<IPlatformClient>();
|
||||||
var enabled: Array<String>;
|
var enabled: Array<String>;
|
||||||
synchronized(_clientsLock) {
|
synchronized(_clientsLock) {
|
||||||
for(e in _enabledClients) {
|
for(e in _enabledClients) {
|
||||||
try {
|
toDisables.add(e);
|
||||||
e.disable();
|
|
||||||
onSourceDisabled.emit(e);
|
|
||||||
}
|
|
||||||
catch(ex: Throwable) {
|
|
||||||
UIDialogs.appToast(ToastView.Toast("If this happens often, please inform the developers on Github", false, null, "Plugin [${e.name}] failed to disable"));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_enabledClients.clear();
|
_enabledClients.clear();
|
||||||
|
@ -236,6 +231,18 @@ class StatePlatform {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
selectClients(*enabled);
|
selectClients(*enabled);
|
||||||
|
|
||||||
|
for(toDisable in toDisables) {
|
||||||
|
launch(Dispatchers.IO) {
|
||||||
|
try {
|
||||||
|
toDisable.disable();
|
||||||
|
onSourceDisabled.emit(toDisable);
|
||||||
|
}
|
||||||
|
catch(ex: Throwable) {
|
||||||
|
Logger.e(TAG, "FAILED TO DISABLE CLIENT [${toDisable?.name}] AFTER UpdateAvailableClients", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -348,11 +355,11 @@ class StatePlatform {
|
||||||
StateApp.instance.handleCaptchaException(c, ex);
|
StateApp.instance.handleCaptchaException(c, ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var toDisable: IPlatformClient? = null;
|
||||||
synchronized(_clientsLock) {
|
synchronized(_clientsLock) {
|
||||||
if (_enabledClients.contains(client)) {
|
if (_enabledClients.contains(client)) {
|
||||||
_enabledClients.remove(client);
|
_enabledClients.remove(client);
|
||||||
client.disable();
|
toDisable = client;
|
||||||
onSourceDisabled.emit(client);
|
|
||||||
newClient.initialize();
|
newClient.initialize();
|
||||||
_enabledClients.add(newClient);
|
_enabledClients.add(newClient);
|
||||||
}
|
}
|
||||||
|
@ -360,6 +367,18 @@ class StatePlatform {
|
||||||
_availableClients.removeIf { it.id == id };
|
_availableClients.removeIf { it.id == id };
|
||||||
_availableClients.add(newClient);
|
_availableClients.add(newClient);
|
||||||
}
|
}
|
||||||
|
if(toDisable != null) {
|
||||||
|
launch(Dispatchers.IO) {
|
||||||
|
try {
|
||||||
|
toDisable?.disable();
|
||||||
|
onSourceDisabled.emit(client);
|
||||||
|
}
|
||||||
|
catch (ex: Throwable) {
|
||||||
|
Logger.e(TAG, "FAILED TO DISABLE CLIENT [${toDisable?.name}] AFTER RELOAD", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
afterReload?.invoke();
|
afterReload?.invoke();
|
||||||
return@withContext newClient;
|
return@withContext newClient;
|
||||||
};
|
};
|
||||||
|
|
|
@ -402,18 +402,25 @@ class StatePlugins {
|
||||||
}
|
}
|
||||||
|
|
||||||
val icon = config.absoluteIconUrl?.let { absIconUrl ->
|
val icon = config.absoluteIconUrl?.let { absIconUrl ->
|
||||||
withContext(Dispatchers.Main) {
|
|
||||||
it.setText("Saving plugin...");
|
|
||||||
it.setProgress(0.75);
|
|
||||||
}
|
|
||||||
val iconResp = client.get(absIconUrl);
|
val iconResp = client.get(absIconUrl);
|
||||||
if(iconResp.isOk)
|
if(iconResp.isOk)
|
||||||
return@let iconResp.body?.byteStream()?.use { it.readBytes() };
|
return@let iconResp.body?.byteStream()?.use { it.readBytes() };
|
||||||
return@let null;
|
return@let null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
withContext(Dispatchers.Main) {
|
||||||
|
it.setText("Saving plugin...");
|
||||||
|
it.setProgress(0.75);
|
||||||
|
}
|
||||||
|
|
||||||
val installEx = StatePlugins.instance.createPlugin(config, script, icon, reinstall);
|
val installEx = StatePlugins.instance.createPlugin(config, script, icon, reinstall);
|
||||||
if(installEx != null)
|
if(installEx != null)
|
||||||
throw installEx;
|
throw installEx;
|
||||||
|
|
||||||
|
withContext(Dispatchers.Main) {
|
||||||
|
it.setText("Reloading available plugins...");
|
||||||
|
it.setProgress(0.9);
|
||||||
|
}
|
||||||
StatePlatform.instance.updateAvailableClients(context);
|
StatePlatform.instance.updateAvailableClients(context);
|
||||||
|
|
||||||
withContext(Dispatchers.Main) {
|
withContext(Dispatchers.Main) {
|
||||||
|
@ -522,9 +529,7 @@ class StatePlugins {
|
||||||
if(id == StateDeveloper.DEV_ID)
|
if(id == StateDeveloper.DEV_ID)
|
||||||
throw IllegalStateException("Attempted to retrieve a persistent developer plugin, this is not allowed");
|
throw IllegalStateException("Attempted to retrieve a persistent developer plugin, this is not allowed");
|
||||||
|
|
||||||
synchronized(_plugins) {
|
return _plugins.findItem { it.config.id == id };
|
||||||
return _plugins.findItem { it.config.id == id };
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
fun getPlugins(): List<SourcePluginDescriptor> {
|
fun getPlugins(): List<SourcePluginDescriptor> {
|
||||||
return _plugins.getItems();
|
return _plugins.getItems();
|
||||||
|
@ -533,12 +538,10 @@ class StatePlugins {
|
||||||
|
|
||||||
fun deletePlugin(id: String) {
|
fun deletePlugin(id: String) {
|
||||||
synchronized(_pluginScripts) {
|
synchronized(_pluginScripts) {
|
||||||
synchronized(_plugins) {
|
_pluginScripts.deleteFile(id);
|
||||||
_pluginScripts.deleteFile(id);
|
val plugins = _plugins.findItems { it.config.id == id };
|
||||||
val plugins = _plugins.findItems { it.config.id == id };
|
for(plugin in plugins)
|
||||||
for(plugin in plugins)
|
_plugins.delete(plugin);
|
||||||
_plugins.delete(plugin);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fun createPlugin(config: SourcePluginConfig, script: String, icon: ByteArray? = null, reinstall: Boolean = false, flags: List<String> = listOf()) : Throwable? {
|
fun createPlugin(config: SourcePluginConfig, script: String, icon: ByteArray? = null, reinstall: Boolean = false, flags: List<String> = listOf()) : Throwable? {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue