mirror of
https://github.com/morgan9e/macos-stats
synced 2026-04-14 00:04:15 +09:00
feat: rename Memory module to RAM
This commit is contained in:
88
Modules/RAM/settings.swift
Normal file
88
Modules/RAM/settings.swift
Normal file
@@ -0,0 +1,88 @@
|
||||
//
|
||||
// settings.swift
|
||||
// Memory
|
||||
//
|
||||
// Created by Serhiy Mytrovtsiy on 11/07/2020.
|
||||
// Using Swift 5.0.
|
||||
// Running on macOS 10.15.
|
||||
//
|
||||
// Copyright © 2020 Serhiy Mytrovtsiy. All rights reserved.
|
||||
//
|
||||
|
||||
import Cocoa
|
||||
import StatsKit
|
||||
import ModuleKit
|
||||
|
||||
internal class Settings: NSView, Settings_v {
|
||||
private var updateIntervalValue: Int = 1
|
||||
private var numberOfProcesses: Int = 8
|
||||
|
||||
private let title: String
|
||||
private let store: UnsafePointer<Store>
|
||||
|
||||
public var callback: (() -> Void) = {}
|
||||
public var callbackWhenUpdateNumberOfProcesses: (() -> Void) = {}
|
||||
public var setInterval: ((_ value: Int) -> Void) = {_ in }
|
||||
|
||||
public init(_ title: String, store: UnsafePointer<Store>) {
|
||||
self.title = title
|
||||
self.store = store
|
||||
self.updateIntervalValue = store.pointee.int(key: "\(self.title)_updateInterval", defaultValue: self.updateIntervalValue)
|
||||
self.numberOfProcesses = store.pointee.int(key: "\(self.title)_processes", defaultValue: self.numberOfProcesses)
|
||||
|
||||
super.init(frame: CGRect(
|
||||
x: 0,
|
||||
y: 0,
|
||||
width: Constants.Settings.width - (Constants.Settings.margin*2),
|
||||
height: 0
|
||||
))
|
||||
|
||||
self.wantsLayer = true
|
||||
self.canDrawConcurrently = true
|
||||
}
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
public func load(widget: widget_t) {
|
||||
self.subviews.forEach{ $0.removeFromSuperview() }
|
||||
|
||||
let rowHeight: CGFloat = 30
|
||||
let num: CGFloat = 1
|
||||
|
||||
self.addSubview(SelectTitleRow(
|
||||
frame: NSRect(x: Constants.Settings.margin, y: Constants.Settings.margin + (rowHeight + Constants.Settings.margin) * num, width: self.frame.width - (Constants.Settings.margin*2), height: rowHeight),
|
||||
title: LocalizedString("Update interval"),
|
||||
action: #selector(changeUpdateInterval),
|
||||
items: ReaderUpdateIntervals.map{ "\($0) sec" },
|
||||
selected: "\(self.updateIntervalValue) sec"
|
||||
))
|
||||
|
||||
self.addSubview(SelectTitleRow(
|
||||
frame: NSRect(x: Constants.Settings.margin, y: Constants.Settings.margin, width: self.frame.width - (Constants.Settings.margin*2), height: rowHeight),
|
||||
title: LocalizedString("Number of top processes"),
|
||||
action: #selector(changeNumberOfProcesses),
|
||||
items: NumbersOfProcesses.map{ "\($0)" },
|
||||
selected: "\(self.numberOfProcesses)"
|
||||
))
|
||||
|
||||
self.setFrameSize(NSSize(width: self.frame.width, height: (rowHeight*(num+1)) + (Constants.Settings.margin*(2+num))))
|
||||
}
|
||||
|
||||
@objc private func changeUpdateInterval(_ sender: NSMenuItem) {
|
||||
if let value = Int(sender.title.replacingOccurrences(of: " sec", with: "")) {
|
||||
self.updateIntervalValue = value
|
||||
self.store.pointee.set(key: "\(self.title)_updateInterval", value: value)
|
||||
self.setInterval(value)
|
||||
}
|
||||
}
|
||||
|
||||
@objc private func changeNumberOfProcesses(_ sender: NSMenuItem) {
|
||||
if let value = Int(sender.title) {
|
||||
self.numberOfProcesses = value
|
||||
self.store.pointee.set(key: "\(self.title)_processes", value: value)
|
||||
self.callbackWhenUpdateNumberOfProcesses()
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user