mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-10 02:08:38 +09:00
Dactyloidae iOS initial commit
This commit is contained in:
parent
daa6179d22
commit
7154a0497e
2123 changed files with 197052 additions and 0 deletions
58
mobile/ios/Client/Frontend/Browser/NightModeHelper.swift
Normal file
58
mobile/ios/Client/Frontend/Browser/NightModeHelper.swift
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
/* 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 WebKit
|
||||
import Shared
|
||||
|
||||
struct NightModePrefsKey {
|
||||
static let NightModeButtonIsInMenu = PrefsKeys.KeyNightModeButtonIsInMenu
|
||||
static let NightModeStatus = PrefsKeys.KeyNightModeStatus
|
||||
}
|
||||
|
||||
class NightModeHelper: TabContentScript {
|
||||
fileprivate weak var tab: Tab?
|
||||
|
||||
required init(tab: Tab) {
|
||||
self.tab = tab
|
||||
if let path = Bundle.main.path(forResource: "NightModeHelper", ofType: "js"), let source = try? NSString(contentsOfFile: path, encoding: String.Encoding.utf8.rawValue) as String {
|
||||
let userScript = WKUserScript(source: source, injectionTime: WKUserScriptInjectionTime.atDocumentStart, forMainFrameOnly: true)
|
||||
tab.webView!.configuration.userContentController.addUserScript(userScript)
|
||||
}
|
||||
}
|
||||
|
||||
static func name() -> String {
|
||||
return "NightMode"
|
||||
}
|
||||
|
||||
func scriptMessageHandlerName() -> String? {
|
||||
return "NightMode"
|
||||
}
|
||||
|
||||
func userContentController(_ userContentController: WKUserContentController, didReceiveScriptMessage message: WKScriptMessage) {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
static func toggle(_ prefs: Prefs, tabManager: TabManager) {
|
||||
let isActive = prefs.boolForKey(NightModePrefsKey.NightModeStatus) ?? false
|
||||
setNightMode(prefs, tabManager: tabManager, enabled: !isActive)
|
||||
}
|
||||
|
||||
static func setNightMode(_ prefs: Prefs, tabManager: TabManager, enabled: Bool) {
|
||||
prefs.setBool(enabled, forKey: NightModePrefsKey.NightModeStatus)
|
||||
for tab in tabManager.tabs {
|
||||
tab.setNightMode(enabled)
|
||||
}
|
||||
}
|
||||
|
||||
static func isActivated(_ prefs: Prefs) -> Bool {
|
||||
return prefs.boolForKey(NightModePrefsKey.NightModeStatus) ?? false
|
||||
}
|
||||
}
|
||||
|
||||
class NightModeAccessors {
|
||||
static func isNightMode(_ prefs: Prefs) -> Bool {
|
||||
return prefs.boolForKey(NightModePrefsKey.NightModeStatus) ?? false
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue