mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-08 08:48:39 +09:00
Dactyloidae iOS initial commit
This commit is contained in:
parent
daa6179d22
commit
7154a0497e
2123 changed files with 197052 additions and 0 deletions
50
mobile/ios/Client/Frontend/Browser/SessionData.swift
Normal file
50
mobile/ios/Client/Frontend/Browser/SessionData.swift
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
import Foundation
|
||||
|
||||
import Shared
|
||||
|
||||
class SessionData: NSObject, NSCoding {
|
||||
let currentPage: Int
|
||||
let urls: [URL]
|
||||
let lastUsedTime: Timestamp
|
||||
|
||||
var jsonDictionary: [String: Any] {
|
||||
return [
|
||||
"currentPage": String(self.currentPage),
|
||||
"lastUsedTime": String(self.lastUsedTime),
|
||||
"urls": urls.map { $0.absoluteString }
|
||||
]
|
||||
}
|
||||
|
||||
/**
|
||||
Creates a new SessionData object representing a serialized tab.
|
||||
|
||||
- parameter currentPage: The active page index. Must be in the range of (-N, 0],
|
||||
where 1-N is the first page in history, and 0 is the last.
|
||||
- parameter urls: The sequence of URLs in this tab's session history.
|
||||
- parameter lastUsedTime: The last time this tab was modified.
|
||||
**/
|
||||
init(currentPage: Int, urls: [URL], lastUsedTime: Timestamp) {
|
||||
self.currentPage = currentPage
|
||||
self.urls = urls
|
||||
self.lastUsedTime = lastUsedTime
|
||||
|
||||
assert(urls.count > 0, "Session has at least one entry")
|
||||
assert(currentPage > -urls.count && currentPage <= 0, "Session index is valid")
|
||||
}
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
self.currentPage = coder.decodeAsInt(forKey: "currentPage")
|
||||
self.urls = coder.decodeObject(forKey: "urls") as? [URL] ?? []
|
||||
self.lastUsedTime = coder.decodeAsUInt64(forKey: "lastUsedTime")
|
||||
}
|
||||
|
||||
func encode(with coder: NSCoder) {
|
||||
coder.encode(currentPage, forKey: "currentPage")
|
||||
coder.encode(urls, forKey: "urls")
|
||||
coder.encode(Int64(lastUsedTime), forKey: "lastUsedTime")
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue