mirror of
https://github.com/kiwix/kiwix-apple.git
synced 2025-09-24 04:03:03 -04:00
Merge pull request #800 from kiwix/775-pdf-title-and-new-tab
Fix PDF tab title and opening _blank in new tab on iOS
This commit is contained in:
commit
d7cd18d3ed
@ -155,6 +155,7 @@ class Tab: NSManagedObject, Identifiable {
|
||||
struct URLContentMetaData {
|
||||
let mime: String
|
||||
let size: UInt
|
||||
let zimTitle: String
|
||||
var httpContentType: String {
|
||||
if mime == "text/plain" {
|
||||
return "text/plain;charset=UTf-8"
|
||||
|
@ -178,7 +178,8 @@
|
||||
zim::Item item = [self itemIn:zimFileID contentPath:contentPath];
|
||||
return @{
|
||||
@"mime": [NSString stringWithUTF8String:item.getMimetype().c_str()],
|
||||
@"size": [NSNumber numberWithUnsignedLongLong:item.getSize()]
|
||||
@"size": [NSNumber numberWithUnsignedLongLong:item.getSize()],
|
||||
@"title": [NSString stringWithUTF8String:item.getTitle().c_str()]
|
||||
};
|
||||
} catch (std::exception) {
|
||||
return nil;
|
||||
|
@ -138,8 +138,9 @@ extension ZimFileService {
|
||||
let zimFileUUID = UUID(uuidString: zimFileID),
|
||||
let content = __getMetaData(zimFileUUID, contentPath: url.path),
|
||||
let mime = content["mime"] as? String,
|
||||
let size = content["size"] as? UInt else { return nil }
|
||||
return URLContentMetaData(mime: mime, size: size)
|
||||
let size = content["size"] as? UInt,
|
||||
let title = content["title"] as? String else { return nil }
|
||||
return URLContentMetaData(mime: mime, size: size, zimTitle: title)
|
||||
}
|
||||
|
||||
func getURLContent(zimFileID: String, contentPath: String, start: UInt = 0, end: UInt = 0) -> URLContent? {
|
||||
|
@ -164,7 +164,11 @@ final class BrowserViewModel: NSObject, ObservableObject,
|
||||
}()
|
||||
|
||||
// update view model
|
||||
articleTitle = title
|
||||
if title.isEmpty {
|
||||
articleTitle = ZimFileService.shared.getContentMetaData(url: url)?.zimTitle ?? ""
|
||||
} else {
|
||||
articleTitle = title
|
||||
}
|
||||
zimFileName = zimFile?.name ?? ""
|
||||
Task {
|
||||
await MainActor.run {
|
||||
@ -177,7 +181,7 @@ final class BrowserViewModel: NSObject, ObservableObject,
|
||||
|
||||
// update tab data
|
||||
if let tab = try? Database.viewContext.existingObject(with: currentTabID) as? Tab {
|
||||
tab.title = title
|
||||
tab.title = articleTitle
|
||||
tab.zimFile = zimFile
|
||||
}
|
||||
}
|
||||
@ -408,7 +412,7 @@ final class BrowserViewModel: NSObject, ObservableObject,
|
||||
externalURL = newURL
|
||||
return nil
|
||||
}
|
||||
webView.load(navigationAction.request)
|
||||
NotificationCenter.openURL(newURL, inNewTab: true)
|
||||
return nil
|
||||
}
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user