generated from KyuubiRan/EzXHepler-template
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Download Eruda to SharedPreference for offline
Except that CSP policy might stop loading fonts, everything else works well.
- Loading branch information
1 parent
9ea99ee
commit 3a8295e
Showing
7 changed files
with
133 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
app/src/main/java/org/matrix/chromext/settings/DownloadEruda.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package org.matrix.chromext.settings | ||
|
||
import android.app.DownloadManager | ||
import android.app.DownloadManager.Request | ||
import android.content.BroadcastReceiver | ||
import android.content.Context | ||
import android.content.Intent | ||
import android.content.IntentFilter | ||
import android.net.Uri | ||
import android.os.Environment | ||
import android.view.View | ||
import android.view.View.OnClickListener | ||
import android.widget.Toast | ||
import java.io.FileReader | ||
|
||
class DownloadEruda(ctx: Context) : OnClickListener { | ||
|
||
var context: Context? = null | ||
|
||
companion object { | ||
var id: Long? = null | ||
} | ||
|
||
init { | ||
context = ctx | ||
} | ||
|
||
override fun onClick(v: View) { | ||
|
||
context!!.registerReceiver( | ||
writeSharedPreference, IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)) | ||
|
||
val request = Request(Uri.parse("https://cdn.jsdelivr.net/npm/eruda")) | ||
request.setDescription("Console for mobile browsers") | ||
request.setTitle("Eruda.js") | ||
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "Eruda.js") | ||
val downloadManager = context!!.getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager | ||
id = downloadManager.enqueue(request) | ||
} | ||
|
||
object writeSharedPreference : BroadcastReceiver() { | ||
override fun onReceive(ctx: Context, intent: Intent) { | ||
if (intent.getAction() == DownloadManager.ACTION_DOWNLOAD_COMPLETE) { | ||
val downloadId = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, 0) | ||
if (downloadId == id) { | ||
val downloadManager = ctx.getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager | ||
val fd = downloadManager.openDownloadedFile(downloadId).getFileDescriptor() | ||
val eruda = FileReader(fd).use { it.readText() } | ||
val sharedPref = ctx.getSharedPreferences("ChromeXt", Context.MODE_PRIVATE) | ||
with(sharedPref!!.edit()) { | ||
putString("eruda", eruda) | ||
apply() | ||
val text = "Updated to the lastest Eruda" | ||
val duration = Toast.LENGTH_SHORT | ||
val toast = Toast.makeText(ctx, text, duration) | ||
toast.show() | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
28 changes: 24 additions & 4 deletions
28
app/src/main/java/org/matrix/chromext/settings/ExitDevMode.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,28 @@ | ||
package org.matrix.chromext.settings | ||
|
||
import android.os.Bundle | ||
import androidx.preference.PreferenceFragmentCompat | ||
import android.content.Context | ||
import android.view.View | ||
import android.view.View.OnClickListener | ||
import android.widget.Toast | ||
|
||
class ExitDevMode : PreferenceFragmentCompat() { | ||
override fun onCreatePreferences(p0: Bundle?, p1: String?) {} | ||
class ExitDevMode(ctx: Context) : OnClickListener { | ||
|
||
var context: Context? = null | ||
|
||
init { | ||
context = ctx | ||
} | ||
|
||
override fun onClick(v: View) { | ||
val sharedPref = | ||
context!!.getSharedPreferences("com.android.chrome_preferences", Context.MODE_PRIVATE) | ||
with(sharedPref!!.edit()) { | ||
putBoolean("developer", false) | ||
apply() | ||
val text = "Please restart Chrome to apply the changes" | ||
val duration = Toast.LENGTH_SHORT | ||
val toast = Toast.makeText(context, text, duration) | ||
toast.show() | ||
} | ||
} | ||
} |