mirror of
https://github.com/tachiyomiorg/tachiyomi-extensions-inspector.git
synced 2024-11-01 15:05:06 +01:00
uninstalling extensions implemented
This commit is contained in:
parent
99316f4bd5
commit
832c224ed4
@ -17,6 +17,7 @@ import ir.armor.tachidesk.util.getSource
|
||||
import ir.armor.tachidesk.util.getSourceList
|
||||
import ir.armor.tachidesk.util.getThumbnail
|
||||
import ir.armor.tachidesk.util.installAPK
|
||||
import ir.armor.tachidesk.util.removeExtension
|
||||
import ir.armor.tachidesk.util.sourceFilters
|
||||
import ir.armor.tachidesk.util.sourceGlobalSearch
|
||||
import ir.armor.tachidesk.util.sourceSearch
|
||||
@ -79,11 +80,20 @@ class Main {
|
||||
|
||||
app.get("/api/v1/extension/install/:apkName") { ctx ->
|
||||
val apkName = ctx.pathParam("apkName")
|
||||
println(apkName)
|
||||
println("installing $apkName")
|
||||
|
||||
ctx.status(
|
||||
installAPK(apkName)
|
||||
)
|
||||
}
|
||||
|
||||
app.get("/api/v1/extension/uninstall/:apkName") { ctx ->
|
||||
val apkName = ctx.pathParam("apkName")
|
||||
println("uninstalling $apkName")
|
||||
removeExtension(apkName)
|
||||
ctx.status(200)
|
||||
}
|
||||
|
||||
app.get("/api/v1/source/list") { ctx ->
|
||||
ctx.json(getSourceList())
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ import kotlinx.coroutines.runBlocking
|
||||
import okhttp3.Request
|
||||
import okio.buffer
|
||||
import okio.sink
|
||||
import org.jetbrains.exposed.sql.deleteWhere
|
||||
import org.jetbrains.exposed.sql.insert
|
||||
import org.jetbrains.exposed.sql.select
|
||||
import org.jetbrains.exposed.sql.transactions.transaction
|
||||
@ -32,8 +33,8 @@ fun installAPK(apkName: String): Int {
|
||||
val dirPathWithoutType = "${Config.extensionsRoot}/$fileNameWithoutType"
|
||||
|
||||
// check if we don't have the dex file already downloaded
|
||||
val dexPath = "${Config.extensionsRoot}/$fileNameWithoutType.jar"
|
||||
if (!File(dexPath).exists()) {
|
||||
val jarPath = "${Config.extensionsRoot}/$fileNameWithoutType.jar"
|
||||
if (!File(jarPath).exists()) {
|
||||
runBlocking {
|
||||
val api = ExtensionGithubApi()
|
||||
val apkToDownload = api.getApkUrl(extensionRecord)
|
||||
@ -130,3 +131,21 @@ private fun downloadAPKFile(url: String, apkPath: String) {
|
||||
sink.writeAll(response.body!!.source())
|
||||
sink.close()
|
||||
}
|
||||
|
||||
fun removeExtension(pkgName: String) {
|
||||
val extensionRecord = getExtensionList(true).first { it.apkName == pkgName }
|
||||
val fileNameWithoutType = pkgName.substringBefore(".apk")
|
||||
val jarPath = "${Config.extensionsRoot}/$fileNameWithoutType.jar"
|
||||
transaction {
|
||||
val extensionId = ExtensionsTable.select { ExtensionsTable.name eq extensionRecord.name }.first()[ExtensionsTable.id]
|
||||
|
||||
SourceTable.deleteWhere { SourceTable.extension eq extensionId }
|
||||
ExtensionsTable.update({ ExtensionsTable.name eq extensionRecord.name }) {
|
||||
it[ExtensionsTable.installed] = false
|
||||
}
|
||||
}
|
||||
|
||||
if (File(jarPath).exists()) {
|
||||
File(jarPath).delete()
|
||||
}
|
||||
}
|
@ -46,7 +46,7 @@ export default function ExtensionCard(props: IProps) {
|
||||
name, lang, versionName, iconUrl, installed, apkName,
|
||||
},
|
||||
} = props;
|
||||
const [installedState, setInstalledState] = useState<string>((installed ? 'installed' : 'install'));
|
||||
const [installedState, setInstalledState] = useState<string>((installed ? 'uninstall' : 'install'));
|
||||
|
||||
const classes = useStyles();
|
||||
const langPress = lang === 'all' ? 'All' : lang.toUpperCase();
|
||||
@ -54,10 +54,25 @@ export default function ExtensionCard(props: IProps) {
|
||||
function install() {
|
||||
setInstalledState('installing');
|
||||
fetch(`http://127.0.0.1:4567/api/v1/extension/install/${apkName}`).then(() => {
|
||||
setInstalledState('installed');
|
||||
setInstalledState('uninstall');
|
||||
});
|
||||
}
|
||||
|
||||
function uninstall() {
|
||||
setInstalledState('uninstalling');
|
||||
fetch(`http://127.0.0.1:4567/api/v1/extension/uninstall/${apkName}`).then(() => {
|
||||
setInstalledState('install');
|
||||
});
|
||||
}
|
||||
|
||||
function handleButtonClick() {
|
||||
if (installedState === 'install') {
|
||||
install();
|
||||
} else {
|
||||
uninstall();
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<Card>
|
||||
<CardContent className={classes.root}>
|
||||
@ -80,7 +95,7 @@ export default function ExtensionCard(props: IProps) {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<Button variant="outlined" onClick={() => install()}>{installedState}</Button>
|
||||
<Button variant="outlined" onClick={() => handleButtonClick()}>{installedState}</Button>
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user