Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add user styles (corrected) #100

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions Fastmate/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {

DispatchQueue.global().async {
self.createUserScriptsFolderIfNeeded()
self.createUserStylesFolderIfNeeded()
}
}

Expand Down Expand Up @@ -97,6 +98,19 @@ class AppDelegate: NSObject, NSApplicationDelegate {
addUserScriptsREADMEInFolder(path)
}

func createUserStylesFolderIfNeeded() {
let path = (NSHomeDirectory() as NSString).appendingPathComponent("userstyles")
var folderExists: ObjCBool = false
FileManager.default.fileExists(atPath: path, isDirectory: &folderExists)

guard folderExists.boolValue == false else {
return
}

try? FileManager.default.createDirectory(atPath: path, withIntermediateDirectories: false, attributes: nil)
addUserStylesREADMEInFolder(path)
}

func addUserScriptsREADMEInFolder(_ path: String) {
let readmeFilePath = (path as NSString).appendingPathComponent("README.txt")
let text = """
Expand All @@ -112,6 +126,21 @@ class AppDelegate: NSObject, NSApplicationDelegate {
FileManager.default.createFile(atPath: readmeFilePath, contents: text.data(using: .utf8), attributes: nil)
}

func addUserStylesREADMEInFolder(_ path: String) {
let readmeFilePath = (path as NSString).appendingPathComponent("README.txt")
let text = """
Fastmate user styles

Put CSS files in this folder (.css), and Fastmate will load them after loading the Fastmail website.

Example:

// fastmate.css
body { background-color: yellow !important; }
"""
FileManager.default.createFile(atPath: readmeFilePath, contents: text.data(using: .utf8), attributes: nil)
}

func application(_ application: NSApplication, open urls: [URL]) {
if let route = router.route(for: urls.first) {
mainWebViewController?.webView?.load(URLRequest(url: route))
Expand Down
Loading