refactor: get the bookmark image from status-go instead
This commit is contained in:
parent
ea436e79c6
commit
724b73072f
|
@ -1,7 +1,7 @@
|
||||||
import NimQml, json, chronicles
|
import NimQml, json, chronicles
|
||||||
import ../../status/status
|
import ../../status/status
|
||||||
import ../../status/libstatus/types as status_types
|
import ../../status/libstatus/browser as status_browser
|
||||||
import ../../status/libstatus/settings as status_settings
|
import ../../status/libstatus/types
|
||||||
import views/bookmark_list
|
import views/bookmark_list
|
||||||
|
|
||||||
QtObject:
|
QtObject:
|
||||||
|
@ -25,9 +25,10 @@ QtObject:
|
||||||
proc init*(self: BrowserView) =
|
proc init*(self: BrowserView) =
|
||||||
var bookmarks: seq[Bookmark] = @[]
|
var bookmarks: seq[Bookmark] = @[]
|
||||||
try:
|
try:
|
||||||
let bookmarksJSON = status_settings.getSetting[string](Setting.Bookmarks, "[]").parseJson
|
let responseResult = status_browser.getBookmarks().parseJson["result"]
|
||||||
for bookmark in bookmarksJSON:
|
if responseResult.kind != JNull:
|
||||||
bookmarks.add(Bookmark(url: bookmark["url"].getStr, name: bookmark["name"].getStr))
|
for bookmark in responseResult:
|
||||||
|
bookmarks.add(Bookmark(url: bookmark["url"].getStr, name: bookmark["name"].getStr, imageUrl: bookmark["imageUrl"].getStr))
|
||||||
except:
|
except:
|
||||||
# Bad JSON. Just use the empty array
|
# Bad JSON. Just use the empty array
|
||||||
discard
|
discard
|
||||||
|
@ -43,8 +44,8 @@ QtObject:
|
||||||
notify = bookmarksChanged
|
notify = bookmarksChanged
|
||||||
|
|
||||||
proc addBookmark*(self: BrowserView, url: string, name: string) {.slot.} =
|
proc addBookmark*(self: BrowserView, url: string, name: string) {.slot.} =
|
||||||
self.bookmarks.addBookmarkItemToList(Bookmark(url: url, name: name))
|
let bookmark = status_browser.storeBookmark(url, name)
|
||||||
discard status_settings.saveSetting(Setting.Bookmarks, $(%self.bookmarks.bookmarks))
|
self.bookmarks.addBookmarkItemToList(bookmark)
|
||||||
self.bookmarksChanged()
|
self.bookmarksChanged()
|
||||||
|
|
||||||
proc removeBookmark*(self: BrowserView, url: string) {.slot.} =
|
proc removeBookmark*(self: BrowserView, url: string) {.slot.} =
|
||||||
|
@ -52,7 +53,7 @@ QtObject:
|
||||||
if index == -1:
|
if index == -1:
|
||||||
return
|
return
|
||||||
self.bookmarks.removeBookmarkItemFromList(index)
|
self.bookmarks.removeBookmarkItemFromList(index)
|
||||||
discard status_settings.saveSetting(Setting.Bookmarks, $(%self.bookmarks.bookmarks))
|
status_browser.deleteBookmark(url)
|
||||||
self.bookmarksChanged()
|
self.bookmarksChanged()
|
||||||
|
|
||||||
proc modifyBookmark*(self: BrowserView, ogUrl: string, newUrl: string, newName: string) {.slot.} =
|
proc modifyBookmark*(self: BrowserView, ogUrl: string, newUrl: string, newName: string) {.slot.} =
|
||||||
|
@ -62,5 +63,5 @@ QtObject:
|
||||||
self.addBookmark(newUrl, newName)
|
self.addBookmark(newUrl, newName)
|
||||||
return
|
return
|
||||||
self.bookmarks.modifyBookmarkItemFromList(index, newUrl, newName)
|
self.bookmarks.modifyBookmarkItemFromList(index, newUrl, newName)
|
||||||
discard status_settings.saveSetting(Setting.Bookmarks, $(%self.bookmarks.bookmarks))
|
status_browser.updateBookmark(ogUrl, newUrl, newName)
|
||||||
self.bookmarksChanged()
|
self.bookmarksChanged()
|
||||||
|
|
|
@ -1,15 +1,12 @@
|
||||||
import NimQml, Tables, chronicles
|
import NimQml, Tables, chronicles
|
||||||
import sequtils as sequtils
|
import sequtils as sequtils
|
||||||
|
import ../../../status/libstatus/types
|
||||||
|
|
||||||
type Bookmark* = ref object
|
|
||||||
name*: string
|
|
||||||
url*: string
|
|
||||||
|
|
||||||
type
|
type
|
||||||
BookmarkRoles {.pure.} = enum
|
BookmarkRoles {.pure.} = enum
|
||||||
Name = UserRole + 1
|
Name = UserRole + 1
|
||||||
Url = UserRole + 2
|
Url = UserRole + 2
|
||||||
|
ImageUrl = UserRole + 3
|
||||||
|
|
||||||
QtObject:
|
QtObject:
|
||||||
type
|
type
|
||||||
|
@ -36,6 +33,7 @@ QtObject:
|
||||||
case column:
|
case column:
|
||||||
of "name": result = bookmark.name
|
of "name": result = bookmark.name
|
||||||
of "url": result = bookmark.url
|
of "url": result = bookmark.url
|
||||||
|
of "imageUrl": result = bookmark.imageUrl
|
||||||
|
|
||||||
method data(self: BookmarkList, index: QModelIndex, role: int): QVariant =
|
method data(self: BookmarkList, index: QModelIndex, role: int): QVariant =
|
||||||
if not index.isValid:
|
if not index.isValid:
|
||||||
|
@ -49,10 +47,12 @@ QtObject:
|
||||||
case bookmarkItemRole:
|
case bookmarkItemRole:
|
||||||
of BookmarkRoles.Name: result = newQVariant(bookmarkItem.name)
|
of BookmarkRoles.Name: result = newQVariant(bookmarkItem.name)
|
||||||
of BookmarkRoles.Url: result = newQVariant(bookmarkItem.url)
|
of BookmarkRoles.Url: result = newQVariant(bookmarkItem.url)
|
||||||
|
of BookmarkRoles.ImageUrl: result = newQVariant(bookmarkItem.imageUrl)
|
||||||
|
|
||||||
method roleNames(self: BookmarkList): Table[int, string] =
|
method roleNames(self: BookmarkList): Table[int, string] =
|
||||||
{
|
{
|
||||||
BookmarkRoles.Name.int:"name",
|
BookmarkRoles.Name.int:"name",
|
||||||
|
BookmarkRoles.ImageUrl.int:"imageUrl",
|
||||||
BookmarkRoles.Url.int:"url"
|
BookmarkRoles.Url.int:"url"
|
||||||
}.toTable
|
}.toTable
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
import core, types, utils, strutils, strformat, json, chronicles
|
||||||
|
|
||||||
|
proc storeBookmark*(url: string, name: string): Bookmark =
|
||||||
|
let payload = %* [{"url": url, "name": name}]
|
||||||
|
result = Bookmark(name: name, url: url)
|
||||||
|
try:
|
||||||
|
let resp = callPrivateRPC("browsers_storeBookmark", payload).parseJson["result"]
|
||||||
|
result.imageUrl = resp["imageUrl"].getStr
|
||||||
|
except:
|
||||||
|
discard
|
||||||
|
|
||||||
|
proc updateBookmark*(ogUrl: string, url: string, name: string) =
|
||||||
|
let payload = %* [ogUrl, {"url": url, "name": name}]
|
||||||
|
discard callPrivateRPC("browsers_updateBookmark", payload)
|
||||||
|
|
||||||
|
proc getBookmarks*(): string =
|
||||||
|
let payload = %* []
|
||||||
|
result = callPrivateRPC("browsers_getBookmarks", payload)
|
||||||
|
|
||||||
|
proc deleteBookmark*(url: string) =
|
||||||
|
let payload = %* [url]
|
||||||
|
discard callPrivateRPC("browsers_deleteBookmark", payload)
|
|
@ -192,6 +192,11 @@ type PendingTransactionType* {.pure.} = enum
|
||||||
BuyStickerPack = "BuyStickerPack"
|
BuyStickerPack = "BuyStickerPack"
|
||||||
WalletTransfer = "WalletTransfer"
|
WalletTransfer = "WalletTransfer"
|
||||||
|
|
||||||
|
type Bookmark* = ref object
|
||||||
|
name*: string
|
||||||
|
url*: string
|
||||||
|
imageUrl*: string
|
||||||
|
|
||||||
type
|
type
|
||||||
Fleet* {.pure.} = enum
|
Fleet* {.pure.} = enum
|
||||||
Prod = "eth.prod",
|
Prod = "eth.prod",
|
||||||
|
|
|
@ -80,7 +80,7 @@ Rectangle {
|
||||||
Connections {
|
Connections {
|
||||||
target: browserModel
|
target: browserModel
|
||||||
onBookmarksChanged: {
|
onBookmarksChanged: {
|
||||||
addressBar.currentFavorite = getCurrentFavorite(currentWebView.url)
|
addressBar.currentFavorite = Qt.binding(function () {return getCurrentFavorite(currentWebView.url)})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -99,15 +99,11 @@ Rectangle {
|
||||||
if (index === -1) {
|
if (index === -1) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
const currentFavicon = currentWebView.icon.toString().replace('image://favicon/', '')
|
|
||||||
if (!appSettings.bookmarkFavicons[url] || appSettings.bookmarkFavicons[url] !== currentFavicon) {
|
|
||||||
appSettings.bookmarkFavicons[url] = currentFavicon
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
url: url,
|
url: url,
|
||||||
name: browserModel.bookmarks.rowData(index, 'name'),
|
name: browserModel.bookmarks.rowData(index, 'name'),
|
||||||
image: appSettings.bookmarkFavicons[url] || ""
|
image: browserModel.bookmarks.rowData(index, 'imageUrl')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -664,7 +660,7 @@ Rectangle {
|
||||||
id: bookmarkBtn
|
id: bookmarkBtn
|
||||||
text: name
|
text: name
|
||||||
onClicked: currentWebView.url = url
|
onClicked: currentWebView.url = url
|
||||||
source: appSettings.bookmarkFavicons[url] || ""
|
source: imageUrl
|
||||||
onRightClicked: {
|
onRightClicked: {
|
||||||
favoriteMenu.url = url
|
favoriteMenu.url = url
|
||||||
favoriteMenu.x = bookmarkList.x + bookmarkBtn.x + mouse.x
|
favoriteMenu.x = bookmarkList.x + bookmarkBtn.x + mouse.x
|
||||||
|
|
|
@ -112,7 +112,6 @@ ApplicationWindow {
|
||||||
property int fontSize: Constants.fontSizeM
|
property int fontSize: Constants.fontSizeM
|
||||||
|
|
||||||
// Browser settings
|
// Browser settings
|
||||||
property var bookmarkFavicons: ({})
|
|
||||||
property bool autoLoadImages: true
|
property bool autoLoadImages: true
|
||||||
property bool javaScriptEnabled: true
|
property bool javaScriptEnabled: true
|
||||||
property bool errorPageEnabled: true
|
property bool errorPageEnabled: true
|
||||||
|
|
Loading…
Reference in New Issue