mirror of
https://github.com/nicoverbruggen/phpmon.git
synced 2025-08-08 04:20:07 +02:00
👌 Fix busy status and fix notifications when app is active
This commit is contained in:
@ -9,7 +9,7 @@ import Cocoa
|
|||||||
import UserNotifications
|
import UserNotifications
|
||||||
|
|
||||||
@NSApplicationMain
|
@NSApplicationMain
|
||||||
class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDelegate {
|
class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCenterDelegate {
|
||||||
|
|
||||||
// MARK: - Variables
|
// MARK: - Variables
|
||||||
|
|
||||||
@ -70,9 +70,14 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
|
|||||||
*/
|
*/
|
||||||
func applicationDidFinishLaunching(_ aNotification: Notification) {
|
func applicationDidFinishLaunching(_ aNotification: Notification) {
|
||||||
LocalNotification.askForPermission()
|
LocalNotification.askForPermission()
|
||||||
|
UNUserNotificationCenter.current().delegate = self
|
||||||
self.menu.startup()
|
self.menu.startup()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
|
||||||
|
completionHandler([.banner])
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: - Menu Interactions
|
// MARK: - Menu Interactions
|
||||||
|
|
||||||
@IBAction func reloadSiteListPressed(_ sender: Any) {
|
@IBAction func reloadSiteListPressed(_ sender: Any) {
|
||||||
|
@ -586,17 +586,17 @@ Gw
|
|||||||
<objects>
|
<objects>
|
||||||
<viewController storyboardIdentifier="siteList" id="JZI-Vd-9oq" customClass="SiteListVC" customModule="PHP_Monitor" customModuleProvider="target" sceneMemberID="viewController">
|
<viewController storyboardIdentifier="siteList" id="JZI-Vd-9oq" customClass="SiteListVC" customModule="PHP_Monitor" customModuleProvider="target" sceneMemberID="viewController">
|
||||||
<view key="view" misplaced="YES" id="rIZ-4U-bhj">
|
<view key="view" misplaced="YES" id="rIZ-4U-bhj">
|
||||||
<rect key="frame" x="0.0" y="0.0" width="550" height="327"/>
|
<rect key="frame" x="0.0" y="0.0" width="550" height="320"/>
|
||||||
<autoresizingMask key="autoresizingMask"/>
|
<autoresizingMask key="autoresizingMask"/>
|
||||||
<subviews>
|
<subviews>
|
||||||
<scrollView autohidesScrollers="YES" horizontalLineScroll="69" horizontalPageScroll="10" verticalLineScroll="69" verticalPageScroll="10" usesPredominantAxisScrolling="NO" translatesAutoresizingMaskIntoConstraints="NO" id="p0j-eB-I2i">
|
<scrollView autohidesScrollers="YES" horizontalLineScroll="69" horizontalPageScroll="10" verticalLineScroll="69" verticalPageScroll="10" usesPredominantAxisScrolling="NO" translatesAutoresizingMaskIntoConstraints="NO" id="p0j-eB-I2i">
|
||||||
<rect key="frame" x="0.0" y="0.0" width="550" height="325"/>
|
<rect key="frame" x="0.0" y="0.0" width="550" height="317"/>
|
||||||
<clipView key="contentView" id="6IL-DW-37w">
|
<clipView key="contentView" id="6IL-DW-37w">
|
||||||
<rect key="frame" x="1" y="1" width="548" height="323"/>
|
<rect key="frame" x="1" y="1" width="548" height="315"/>
|
||||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||||
<subviews>
|
<subviews>
|
||||||
<tableView verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="lastColumnOnly" multipleSelection="NO" autosaveColumns="NO" rowHeight="69" rowSizeStyle="automatic" viewBased="YES" id="cp3-34-pQj">
|
<tableView verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="lastColumnOnly" multipleSelection="NO" autosaveColumns="NO" rowHeight="69" rowSizeStyle="automatic" viewBased="YES" id="cp3-34-pQj">
|
||||||
<rect key="frame" x="0.0" y="0.0" width="548" height="323"/>
|
<rect key="frame" x="0.0" y="0.0" width="548" height="315"/>
|
||||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||||
<size key="intercellSpacing" width="17" height="0.0"/>
|
<size key="intercellSpacing" width="17" height="0.0"/>
|
||||||
<color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
|
<color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
|
||||||
@ -732,15 +732,19 @@ Gw
|
|||||||
<autoresizingMask key="autoresizingMask"/>
|
<autoresizingMask key="autoresizingMask"/>
|
||||||
</scroller>
|
</scroller>
|
||||||
</scrollView>
|
</scrollView>
|
||||||
<progressIndicator maxValue="100" displayedWhenStopped="NO" indeterminate="YES" controlSize="small" style="spinning" translatesAutoresizingMaskIntoConstraints="NO" id="ZiS-Gq-TLQ">
|
<progressIndicator maxValue="100" displayedWhenStopped="NO" indeterminate="YES" style="spinning" translatesAutoresizingMaskIntoConstraints="NO" id="ZiS-Gq-TLQ">
|
||||||
<rect key="frame" x="267" y="155" width="16" height="16"/>
|
<rect key="frame" x="260" y="154" width="30" height="30"/>
|
||||||
|
<constraints>
|
||||||
|
<constraint firstAttribute="width" constant="30" id="XK3-AR-Oc0"/>
|
||||||
|
<constraint firstAttribute="height" constant="30" id="lfW-dB-Eu3"/>
|
||||||
|
</constraints>
|
||||||
</progressIndicator>
|
</progressIndicator>
|
||||||
</subviews>
|
</subviews>
|
||||||
<constraints>
|
<constraints>
|
||||||
<constraint firstItem="p0j-eB-I2i" firstAttribute="leading" secondItem="rIZ-4U-bhj" secondAttribute="leading" id="2Tx-yb-xrv"/>
|
<constraint firstItem="p0j-eB-I2i" firstAttribute="leading" secondItem="rIZ-4U-bhj" secondAttribute="leading" id="2Tx-yb-xrv"/>
|
||||||
<constraint firstItem="p0j-eB-I2i" firstAttribute="top" secondItem="rIZ-4U-bhj" secondAttribute="top" id="Pst-5A-dI0"/>
|
<constraint firstItem="p0j-eB-I2i" firstAttribute="top" secondItem="rIZ-4U-bhj" secondAttribute="top" id="Pst-5A-dI0"/>
|
||||||
<constraint firstAttribute="bottom" secondItem="p0j-eB-I2i" secondAttribute="bottom" id="QEw-5m-u1s"/>
|
<constraint firstAttribute="bottom" secondItem="p0j-eB-I2i" secondAttribute="bottom" id="QEw-5m-u1s"/>
|
||||||
<constraint firstItem="ZiS-Gq-TLQ" firstAttribute="centerY" secondItem="rIZ-4U-bhj" secondAttribute="centerY" id="XqX-Tf-8ck"/>
|
<constraint firstItem="ZiS-Gq-TLQ" firstAttribute="centerY" secondItem="rIZ-4U-bhj" secondAttribute="centerY" constant="-10" id="XqX-Tf-8ck"/>
|
||||||
<constraint firstItem="ZiS-Gq-TLQ" firstAttribute="centerX" secondItem="rIZ-4U-bhj" secondAttribute="centerX" id="eD8-TV-7dF"/>
|
<constraint firstItem="ZiS-Gq-TLQ" firstAttribute="centerX" secondItem="rIZ-4U-bhj" secondAttribute="centerX" id="eD8-TV-7dF"/>
|
||||||
<constraint firstAttribute="trailing" secondItem="p0j-eB-I2i" secondAttribute="trailing" id="zWH-TD-RZv"/>
|
<constraint firstAttribute="trailing" secondItem="p0j-eB-I2i" secondAttribute="trailing" id="zWH-TD-RZv"/>
|
||||||
</constraints>
|
</constraints>
|
||||||
@ -752,7 +756,7 @@ Gw
|
|||||||
</viewController>
|
</viewController>
|
||||||
<customObject id="HgD-aB-bQb" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
|
<customObject id="HgD-aB-bQb" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
|
||||||
</objects>
|
</objects>
|
||||||
<point key="canvasLocation" x="288" y="766"/>
|
<point key="canvasLocation" x="288" y="765.5"/>
|
||||||
</scene>
|
</scene>
|
||||||
</scenes>
|
</scenes>
|
||||||
<resources>
|
<resources>
|
||||||
|
@ -73,8 +73,8 @@ class SiteListVC: NSViewController, NSTableViewDelegate, NSTableViewDataSource {
|
|||||||
func reloadSites() {
|
func reloadSites() {
|
||||||
// Start spinner and reset view (no items)
|
// Start spinner and reset view (no items)
|
||||||
self.progressIndicator.startAnimation(nil)
|
self.progressIndicator.startAnimation(nil)
|
||||||
self.sites = []
|
self.tableView.alphaValue = 0.3
|
||||||
self.tableView.reloadData()
|
self.tableView.isEnabled = false
|
||||||
|
|
||||||
DispatchQueue.global(qos: .userInitiated).async { [unowned self] in
|
DispatchQueue.global(qos: .userInitiated).async { [unowned self] in
|
||||||
// Reload site information
|
// Reload site information
|
||||||
@ -86,6 +86,8 @@ class SiteListVC: NSViewController, NSTableViewDelegate, NSTableViewDataSource {
|
|||||||
|
|
||||||
// Stop spinner
|
// Stop spinner
|
||||||
self.progressIndicator.stopAnimation(nil)
|
self.progressIndicator.stopAnimation(nil)
|
||||||
|
self.tableView.alphaValue = 1.0
|
||||||
|
self.tableView.isEnabled = true
|
||||||
|
|
||||||
// Re-apply any existing search
|
// Re-apply any existing search
|
||||||
self.searchedFor(text: lastSearchedFor)
|
self.searchedFor(text: lastSearchedFor)
|
||||||
@ -193,26 +195,38 @@ class SiteListVC: NSViewController, NSTableViewDelegate, NSTableViewDataSource {
|
|||||||
let previous = site.secured
|
let previous = site.secured
|
||||||
let action = site.secured ? "unsecure" : "secure"
|
let action = site.secured ? "unsecure" : "secure"
|
||||||
|
|
||||||
let command = "cd \(site.absolutePath!) && sudo \(Paths.valet) \(action) && exit;"
|
self.progressIndicator.startAnimation(nil)
|
||||||
let _ = Shell.pipe(command, requiresPath: true)
|
self.tableView.alphaValue = 0.3
|
||||||
|
self.tableView.isEnabled = false
|
||||||
|
|
||||||
site.determineSecured(Valet.shared.config.tld)
|
DispatchQueue.global(qos: .userInitiated).async { [unowned self] in
|
||||||
|
let command = "cd \(site.absolutePath!) && sudo \(Paths.valet) \(action) && exit;"
|
||||||
if site.secured == previous {
|
let _ = Shell.pipe(command, requiresPath: true)
|
||||||
Alert.notify(
|
|
||||||
message: "SSL status not changed",
|
site.determineSecured(Valet.shared.config.tld)
|
||||||
info: "Something went wrong. Try running the command in your terminal manually: `\(command)`")
|
|
||||||
} else {
|
DispatchQueue.main.async { [self] in
|
||||||
let newState = site.secured ? "secured" : "unsecured"
|
if site.secured == previous {
|
||||||
LocalNotification.send(
|
Alert.notify(
|
||||||
title: "SSL status changed",
|
message: "SSL status not changed",
|
||||||
subtitle: "The domain '\(site.name!).\(Valet.shared.config.tld)' is now \(newState)."
|
info: "Something went wrong. Try running the command in your terminal manually: `\(command)`")
|
||||||
)
|
} else {
|
||||||
|
let newState = site.secured ? "secured" : "unsecured"
|
||||||
|
LocalNotification.send(
|
||||||
|
title: "SSL status changed",
|
||||||
|
subtitle: "The domain '\(site.name!).\(Valet.shared.config.tld)' is now \(newState)."
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
progressIndicator.stopAnimation(nil)
|
||||||
|
self.tableView.alphaValue = 1
|
||||||
|
self.tableView.isEnabled = true
|
||||||
|
|
||||||
|
tableView.reloadData(forRowIndexes: [rowToReload], columnIndexes: [0])
|
||||||
|
tableView.deselectRow(rowToReload)
|
||||||
|
tableView.selectRowIndexes([rowToReload], byExtendingSelection: true)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tableView.reloadData(forRowIndexes: [rowToReload], columnIndexes: [0])
|
|
||||||
tableView.deselectRow(rowToReload)
|
|
||||||
tableView.selectRowIndexes([rowToReload], byExtendingSelection: true)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: Open with IDE / Editor
|
// MARK: Open with IDE / Editor
|
||||||
|
Reference in New Issue
Block a user