Skip to content

Commit

Permalink
Update error handling and add more comments
Browse files Browse the repository at this point in the history
  • Loading branch information
soffes committed Mar 31, 2020
1 parent 2181a6b commit 27789c3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
20 changes: 18 additions & 2 deletions Modules/ZoomIn/Sources/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,24 @@ import SafariServices.SFSafariApplication
class ViewController: NSViewController {
@IBAction func openSafariExtensionPreferences(_ sender: AnyObject?) {
SFSafariApplication.showPreferencesForExtension(withIdentifier: "com.nothingmagical.zoom-in.extension") { error in
if let error = error {
print("Dang: \(error)")
guard let error = error else {
return
}

// This callback is called on a background thread. Switch to the main thread.
DispatchQueue.main.async { [weak self] in
// Setup the error
let alert = NSAlert(error: error)

// Add some more information
alert.informativeText = "Failed to open Safari preferences."

// Show it from our window (or fallback to just showing on its own)
if let window = self?.view.window {
alert.beginSheetModal(for: window, completionHandler: nil)
} else {
alert.runModal()
}
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions Modules/ZoomIn/Sources/WindowController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ import AppKit
final class WindowController: NSWindowController, NSWindowDelegate {
override func windowDidLoad() {
super.windowDidLoad()

// Center the window on the screen when it loads
window?.center()
}

func windowWillClose(_ notification: Notification) {
// When the window closes, quit the app
NSApp.terminate(notification)
}
}
4 changes: 4 additions & 0 deletions Modules/ZoomInExtension/Resources/script.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
// Wait for the page to load
document.addEventListener("DOMContentLoaded", function(event) {
// Get the URL from Zoom’s page
const url = document.getElementById('scheme_url')['value'];

// Tell the native extension about the URL
safari.extension.dispatchMessage('open', { url: url });
});

0 comments on commit 27789c3

Please sign in to comment.