Skip to content

Commit

Permalink
Fix cookies deletion
Browse files Browse the repository at this point in the history
Close #566.
  • Loading branch information
Slion committed Jan 21, 2024
1 parent 6c4b5d1 commit 5041ebd
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,12 @@ class PrivacySettingsFragment : AbstractSettingsFragment() {
title = R.string.title_clear_cookies,
message = R.string.dialog_cookies,
positiveButton = DialogItem(title = R.string.action_yes) {
clearCookies()
.subscribeOn(databaseScheduler)
.observeOn(mainScheduler)
.subscribe {
(activity as Activity).snackbar(R.string.message_cookies_cleared)
WebUtils.clearCookies {
if (it) {
(activity as Activity).snackbar(R.string.message_cookies_cleared)
} else {
(activity as Activity).snackbar(R.string.message_cookies_clear_error)
}
}
},
negativeButton = DialogItem(title = R.string.action_no) {},
Expand All @@ -183,15 +184,6 @@ class PrivacySettingsFragment : AbstractSettingsFragment() {
}
}

private fun clearCookies(): Completable = Completable.fromAction {
val activity = activity
if (activity != null) {
WebUtils.clearCookies()
} else {
throw RuntimeException("Activity was null in clearCookies")
}
}

private fun clearWebStorage() {
WebUtils.clearWebStorage()
(activity as Activity).snackbar(R.string.message_web_storage_cleared)
Expand Down
34 changes: 31 additions & 3 deletions app/src/main/java/fulguris/utils/WebUtils.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
/*
* The contents of this file are subject to the Common Public Attribution License Version 1.0.
* (the "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
* https://github.com/Slion/Fulguris/blob/main/LICENSE.CPAL-1.0.
* The License is based on the Mozilla Public License Version 1.1, but Sections 14 and 15 have been
* added to cover use of software over a computer network and provide for limited attribution for
* the Original Developer. In addition, Exhibit A has been modified to be consistent with Exhibit B.
*
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
* ANY KIND, either express or implied. See the License for the specific language governing rights
* and limitations under the License.
*
* The Original Code is Fulguris.
*
* The Original Developer is the Initial Developer.
* The Initial Developer of the Original Code is Stéphane Lenclud.
*
* All portions of the code written by Stéphane Lenclud are Copyright © 2024 Stéphane Lenclud.
* All Rights Reserved.
*
* Copyright 8/4/2015 Anthony Restaino
*/

package fulguris.utils

import fulguris.database.history.HistoryRepository
Expand All @@ -9,12 +33,16 @@ import timber.log.Timber
import java.io.File

/**
* Copyright 8/4/2015 Anthony Restaino
* Some web utility functions
*/
object WebUtils {
fun clearCookies() {

fun clearCookies(callback: ValueCallback<Boolean>? = null) {
val c = CookieManager.getInstance()
c.removeAllCookies { Timber.i("removeAllCookies: $it") }
c.removeAllCookies {
Timber.i("removeAllCookies: $it")
callback?.onReceiveValue(it)
}
}

fun clearWebStorage() {
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@
<string name="message_import">Bookmarks were imported</string>
<string name="message_clear_history">History cleared</string>
<string name="message_cookies_cleared">Cookies cleared</string>
<string name="message_cookies_clear_error">Could not clear cookies</string>
<string name="max_tabs">Max tabs reached. Unlock more by purchasing a subscription.</string>
<string name="message_text_copied">Text copied to clipboard</string>
<string name="message_link_copied">Link copied to clipboard</string>
Expand Down

0 comments on commit 5041ebd

Please sign in to comment.