mirror of
https://github.com/lebr0nli/slader-extension.git
synced 2025-05-10 12:42:19 +00:00
52 lines
1.6 KiB
Swift
52 lines
1.6 KiB
Swift
//
|
|
// ViewController.swift
|
|
// Quizlet bypass
|
|
//
|
|
// Created by Alan Li on 2021/8/13.
|
|
//
|
|
|
|
import Cocoa
|
|
import SafariServices.SFSafariApplication
|
|
import SafariServices.SFSafariExtensionManager
|
|
|
|
let appName = "Quizlet bypass"
|
|
let extensionBundleIdentifier = "com.alanli.Quizlet-bypass.Extension"
|
|
|
|
class ViewController: NSViewController {
|
|
|
|
@IBOutlet var appNameLabel: NSTextField!
|
|
|
|
override func viewDidLoad() {
|
|
super.viewDidLoad()
|
|
self.appNameLabel.stringValue = appName
|
|
SFSafariExtensionManager.getStateOfSafariExtension(withIdentifier: extensionBundleIdentifier) { (state, error) in
|
|
guard let state = state, error == nil else {
|
|
// Insert code to inform the user that something went wrong.
|
|
return
|
|
}
|
|
|
|
DispatchQueue.main.async {
|
|
if (state.isEnabled) {
|
|
self.appNameLabel.stringValue = "\(appName)'s extension is currently on."
|
|
} else {
|
|
self.appNameLabel.stringValue = "\(appName)'s extension is currently off. You can turn it on in Safari Extensions preferences."
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
@IBAction func openSafariExtensionPreferences(_ sender: AnyObject?) {
|
|
SFSafariApplication.showPreferencesForExtension(withIdentifier: extensionBundleIdentifier) { error in
|
|
guard error == nil else {
|
|
// Insert code to inform the user that something went wrong.
|
|
return
|
|
}
|
|
|
|
DispatchQueue.main.async {
|
|
NSApplication.shared.terminate(nil)
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|