Skip to content
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
149 changes: 149 additions & 0 deletions OctoPod Mac/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
//
// AppDelegate.swift
// OctoPod Mac
//
// Created by Arijit Banerjee on 6/26/20.
// Copyright © 2020 Gaston Dombiak. All rights reserved.
//

import Cocoa
import UserNotifications

@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {

lazy var preferencesWindowController = { () -> NSWindowController in
let storyBoard = NSStoryboard(name: "Main", bundle: nil)
guard let pwc = storyBoard.instantiateController(withIdentifier: "PreferencesWindowController") as? NSWindowController else{
fatalError("Unable to instantiate view controller")
}
(pwc.contentViewController as! PreferencesViewController).delegate = popoverViewController
return pwc
}()

let statusItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.squareLength)

lazy var popoverViewController = { () -> PopoverViewController in
let storyBoard = NSStoryboard(name: "Main", bundle: nil)
guard let vc = storyBoard.instantiateController(withIdentifier: "PopoverViewController") as? PopoverViewController
else{
fatalError("Unable to instantiate view controller")
}
return vc
}()

func applicationDidFinishLaunching(_ aNotification: Notification) {
if #available(OSX 10.14, *) {
registerForPushNotifications()
} else {
// Fallback on earlier versions
}
let itemImage = NSImage(named: NSImage.Name("Status-Icon"))
itemImage?.size = NSMakeSize(20.0, 20.0);
itemImage?.isTemplate = true
statusItem.button?.image = itemImage
statusItem.button?.sendAction(on: [.leftMouseUp, .rightMouseUp])
statusItem.button?.target = self
statusItem.button?.action = #selector(statusBarButtonClicked)
statusItem.button?.toolTip = "OctoPod for OctoPrint"
}

func applicationWillTerminate(_ aNotification: Notification) {
// Insert code here to tear down your application
}
lazy var appConfiguration: AppConfiguration = {
return AppConfiguration()
}()
func showQuickView() {
guard let button = statusItem.button else {
fatalError("Cannot get status button")
}
let popoverView = NSPopover()
popoverView.contentViewController = popoverViewController
popoverView.behavior = .transient
popoverView.show(relativeTo: button.bounds, of: button, preferredEdge: .maxY)
}

@objc func showPreferences() {
preferencesWindowController.showWindow(self)
}

lazy var menu = getMenu()
private func getMenu() -> NSMenu {
let menu = NSMenu()
menu.addItem(NSMenuItem(title: "About OctoPod Mac", action: #selector(NSApplication.orderFrontStandardAboutPanel(_:)), keyEquivalent: ""))
menu.addItem(NSMenuItem(title: "Preferences", action: #selector(showPreferences), keyEquivalent: "P"))
menu.addItem(NSMenuItem.separator())
menu.addItem(NSMenuItem(title: "Quit OctoPod Mac", action: #selector(NSApplication.terminate(_:)), keyEquivalent: "q"))
return menu
}

@objc func statusBarButtonClicked(sender: NSStatusBarButton) {
let event = NSApp.currentEvent!
if event.type == NSEvent.EventType.rightMouseUp {
NSMenu.popUpContextMenu(menu, with: event, for: sender)
} else {
showQuickView()
}
}
@available(OSX 10.14, *)
func registerForPushNotifications() {
UNUserNotificationCenter.current() // 1
.requestAuthorization(options: [.alert, .sound, .badge]) { // 2
granted, error in
guard granted else { return }
self.getNotificationSettings()
}
}

@available(OSX 10.14, *)
func getNotificationSettings() {
UNUserNotificationCenter.current().getNotificationSettings { settings in
NSLog("Notification settings: \(settings)")
}
}

lazy var printerManager: PrinterManager? = {
let context = persistentContainer.viewContext
context.mergePolicy = NSMergeByPropertyObjectTrumpMergePolicy
var printerManager = PrinterManager()
printerManager.managedObjectContext = context
return printerManager
}()

// MARK: - Core Data stack

lazy var persistentContainer: SharedPersistentContainer = {
/*
The persistent container for the application. This implementation
creates and returns a container, having loaded the store for the
application to it. This property is optional since there are legitimate
error conditions that could cause the creation of the store to fail.
*/
let container = SharedPersistentContainer(name: "OctoPod")
container.loadPersistentStores(completionHandler: { (storeDescription, error) in
if let error = error as NSError? {
// Replace this implementation with code to handle the error appropriately.
// fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.

/*
Typical reasons for an error here include:
* The parent directory does not exist, cannot be created, or disallows writing.
* The persistent store is not accessible, due to permissions or data protection when the device is locked.
* The device is out of space.
* The store could not be migrated to the current model version.
Check the error message to determine what the actual problem was.
*/
fatalError("Unresolved error \(error), \(error.userInfo)")
}
})
return container
}()

@IBAction func preferencesFromMainMenuClicked(_ sender: Any) {
showPreferences()
}

}


Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
68 changes: 68 additions & 0 deletions OctoPod Mac/Assets.xcassets/AppIcon-Mac.appiconset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{
"images" : [
{
"filename" : "16.png",
"idiom" : "mac",
"scale" : "1x",
"size" : "16x16"
},
{
"filename" : "32.png",
"idiom" : "mac",
"scale" : "2x",
"size" : "16x16"
},
{
"filename" : "32-1.png",
"idiom" : "mac",
"scale" : "1x",
"size" : "32x32"
},
{
"filename" : "64.png",
"idiom" : "mac",
"scale" : "2x",
"size" : "32x32"
},
{
"filename" : "128.png",
"idiom" : "mac",
"scale" : "1x",
"size" : "128x128"
},
{
"filename" : "256.png",
"idiom" : "mac",
"scale" : "2x",
"size" : "128x128"
},
{
"filename" : "256-1.png",
"idiom" : "mac",
"scale" : "1x",
"size" : "256x256"
},
{
"filename" : "512.png",
"idiom" : "mac",
"scale" : "2x",
"size" : "256x256"
},
{
"filename" : "512-1.png",
"idiom" : "mac",
"scale" : "1x",
"size" : "512x512"
},
{
"filename" : "1024.png",
"idiom" : "mac",
"scale" : "2x",
"size" : "512x512"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
6 changes: 6 additions & 0 deletions OctoPod Mac/Assets.xcassets/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions OctoPod Mac/Assets.xcassets/Octopod.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"filename" : "128.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "256.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "512.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"images" : [
{
"filename" : "cancel_32.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "cancel_64.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions OctoPod Mac/Assets.xcassets/Print Job/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
22 changes: 22 additions & 0 deletions OctoPod Mac/Assets.xcassets/Print Job/Pause.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"images" : [
{
"filename" : "pause_32.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "pause_64.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions OctoPod Mac/Assets.xcassets/Print Job/Print.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"images" : [
{
"filename" : "play_32.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "play_64.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"images" : [
{
"filename" : "restart_32.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "restart_64.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions OctoPod Mac/Assets.xcassets/Status-Icon.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"images" : [
{
"filename" : "Octopod-48x48.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "Octopod-48x48-1.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading