Reset // Beautifying the Notifier Window.

This commit is contained in:
ShikiSuen 2022-02-07 00:07:42 +08:00
parent 8555939c77
commit 7ccd0335e1
1 changed files with 27 additions and 11 deletions

View File

@ -1,3 +1,10 @@
/*
* NotifierController.swift
*
* Copyright 2021-2022 vChewing Project (3-Clause BSD License).
* Derived from 2011-2022 OpenVanilla Project (MIT License).
* Some rights reserved. See "LICENSE.TXT" for details.
*/
import Cocoa import Cocoa
@ -13,8 +20,8 @@ private class NotifierWindow: NSWindow {
} }
} }
private let kWindowWidth: CGFloat = 160.0 private let kWindowWidth: CGFloat = 213.0
private let kWindowHeight: CGFloat = 80.0 private let kWindowHeight: CGFloat = 60.0
public class NotifierController: NSWindowController, NotifierWindowDelegate { public class NotifierController: NSWindowController, NotifierWindowDelegate {
private var messageTextField: NSTextField private var messageTextField: NSTextField
@ -26,7 +33,7 @@ public class NotifierController: NSWindowController, NotifierWindowDelegate {
paraStyle.alignment = .center paraStyle.alignment = .center
let attr: [NSAttributedString.Key: AnyObject] = [ let attr: [NSAttributedString.Key: AnyObject] = [
.foregroundColor: foregroundColor, .foregroundColor: foregroundColor,
.font: NSFont.systemFont(ofSize: NSFont.systemFontSize(for: .regular)), .font: NSFont.boldSystemFont(ofSize: NSFont.systemFontSize(for: .regular)),
.paragraphStyle: paraStyle .paragraphStyle: paraStyle
] ]
let attrString = NSAttributedString(string: message, attributes: attr) let attrString = NSAttributedString(string: message, attributes: attr)
@ -41,13 +48,12 @@ public class NotifierController: NSWindowController, NotifierWindowDelegate {
} }
} }
private var shouldStay: Bool = false private var shouldStay: Bool = false
private var backgroundColor: NSColor = .black { private var backgroundColor: NSColor = .textBackgroundColor {
didSet { didSet {
self.window?.backgroundColor = backgroundColor self.window?.backgroundColor = backgroundColor
self.messageTextField.backgroundColor = backgroundColor
} }
} }
private var foregroundColor: NSColor = .white { private var foregroundColor: NSColor = .controlTextColor {
didSet { didSet {
self.messageTextField.textColor = foregroundColor self.messageTextField.textColor = foregroundColor
} }
@ -82,11 +88,22 @@ public class NotifierController: NSWindowController, NotifierWindowDelegate {
var windowRect = contentRect var windowRect = contentRect
windowRect.origin.x = screenRect.maxX - windowRect.width - 10 windowRect.origin.x = screenRect.maxX - windowRect.width - 10
windowRect.origin.y = screenRect.maxY - windowRect.height - 10 windowRect.origin.y = screenRect.maxY - windowRect.height - 10
let styleMask: NSWindow.StyleMask = [.borderless] let styleMask: NSWindow.StyleMask = [.fullSizeContentView, .titled]
let panel = NotifierWindow(contentRect: windowRect, styleMask: styleMask, backing: .buffered, defer: false) let panel = NotifierWindow(contentRect: windowRect, styleMask: styleMask, backing: .buffered, defer: false)
panel.level = NSWindow.Level(Int(kCGPopUpMenuWindowLevel)) panel.level = NSWindow.Level(Int(kCGPopUpMenuWindowLevel))
panel.hasShadow = true panel.hasShadow = true
panel.backgroundColor = backgroundColor panel.backgroundColor = backgroundColor
panel.title = ""
panel.titlebarAppearsTransparent = true
panel.titleVisibility = .hidden
panel.showsToolbarButton = false
panel.standardWindowButton(NSWindow.ButtonType.fullScreenButton)?.isHidden = true
panel.standardWindowButton(NSWindow.ButtonType.miniaturizeButton)?.isHidden = true
panel.standardWindowButton(NSWindow.ButtonType.closeButton)?.isHidden = true
panel.standardWindowButton(NSWindow.ButtonType.zoomButton)?.isHidden = true
messageTextField = NSTextField() messageTextField = NSTextField()
messageTextField.frame = contentRect messageTextField.frame = contentRect
@ -94,9 +111,8 @@ public class NotifierController: NSWindowController, NotifierWindowDelegate {
messageTextField.isSelectable = false messageTextField.isSelectable = false
messageTextField.isBezeled = false messageTextField.isBezeled = false
messageTextField.textColor = foregroundColor messageTextField.textColor = foregroundColor
messageTextField.drawsBackground = true messageTextField.drawsBackground = false
messageTextField.backgroundColor = backgroundColor messageTextField.font = .boldSystemFont(ofSize: NSFont.systemFontSize(for: .regular))
messageTextField.font = .systemFont(ofSize: NSFont.systemFontSize(for: .small))
panel.contentView?.addSubview(messageTextField) panel.contentView?.addSubview(messageTextField)
super.init(window: panel) super.init(window: panel)
@ -155,7 +171,7 @@ public class NotifierController: NSWindowController, NotifierWindowDelegate {
waitTimer?.invalidate() waitTimer?.invalidate()
waitTimer = nil waitTimer = nil
NotifierController.decreaseInstanceCount() NotifierController.decreaseInstanceCount()
fadeTimer = Timer.scheduledTimer(timeInterval: 0.1, target: self, selector: #selector(doFadeOut(_:)), userInfo: nil, repeats: true) fadeTimer = Timer.scheduledTimer(timeInterval: 0.01, target: self, selector: #selector(doFadeOut(_:)), userInfo: nil, repeats: true)
} }
public override func close() { public override func close() {