Skip to content

Commit

Permalink
feat: Improve code
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinperignon committed May 17, 2023
1 parent e1ada26 commit b3820e6
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Mail/Views/Thread/WebView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ struct WebView: UIViewRepresentable {

let messageUid: String

var webView: WKWebView {
private var webView: WKWebView {
return model.webView
}

Expand Down
2 changes: 1 addition & 1 deletion Mail/Views/Thread/WebViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import SwiftSoup
import SwiftUI
import WebKit

class WebViewModel: NSObject, ObservableObject {
final class WebViewModel: NSObject, ObservableObject {
@Published var webViewHeight: CGFloat = .zero

@Published var showBlockQuote = false
Expand Down
10 changes: 0 additions & 10 deletions MailCore/Utils/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,6 @@ public enum Constants {
public static let sizeChangeThreshold = 3
public static let viewportContent = "width=device-width, initial-scale=1.0"
public static let divWrapperId = "kmail-message-content"
public static let styleCSS = {
guard let style = Bundle.main.loadCSS(filename: "style") else { return "" }

let variables = """
:root {
--kmail-primary-color: \(UserDefaults.shared.accentColor.primary.swiftUIColor.hexRepresentation);
}
"""
return (variables + style).replacingOccurrences(of: "\n", with: "")
}()
public static let mungeEmailScript: String? = {
guard let mungeScript = Bundle.main.load(filename: "mungeEmail", withExtension: "js") else { return nil }
return "const MESSAGE_SELECTOR = \"#\(divWrapperId)\"; \(mungeScript)"
Expand Down
11 changes: 10 additions & 1 deletion MailCore/Utils/MessageWebViewUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,16 @@ public enum MessageWebViewUtils {
}

public static func generateCSS(for target: WebViewTarget) -> String {
var resources = "<style>\(Constants.styleCSS)</style>"
var resources = ""

if let style = Bundle.main.loadCSS(filename: "style") {
let variables = """
:root {
--kmail-primary-color: \(UserDefaults.shared.accentColor.primary.swiftUIColor.hexRepresentation);
}
"""
resources += "<style>\(variables + style)</style>".replacingOccurrences(of: "\n", with: "")
}

if let fixDisplayCSS = Bundle.main.loadCSS(filename: "improveRendering") {
resources += "<style>\(fixDisplayCSS)</style>"
Expand Down

0 comments on commit b3820e6

Please sign in to comment.