Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: stroage 관련 UI view를 추가합니다. #113

Merged
Merged
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
26 changes: 23 additions & 3 deletions Box42.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
DE9457312A9FB01400B0B768 /* PreferencesTableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE9457302A9FB01400B0B768 /* PreferencesTableView.swift */; };
DE9457342A9FB1D300B0B768 /* RequestAccessView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE9457332A9FB1D300B0B768 /* RequestAccessView.swift */; };
DE9457372A9FC0A800B0B768 /* SecurityScopedResourceAccess.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE9457362A9FC0A800B0B768 /* SecurityScopedResourceAccess.swift */; };
DE94573D2A9FD33400B0B768 /* StorageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE94573C2A9FD33400B0B768 /* StorageView.swift */; };
DE97CA692A9A6364001073DE /* PixelConversion+CGFloat.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE97CA682A9A6364001073DE /* PixelConversion+CGFloat.swift */; };
DE97CA792A9A6F6A001073DE /* QuickSlotHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE97CA782A9A6F6A001073DE /* QuickSlotHeaderView.swift */; };
DE97CA7C2A9A7199001073DE /* QuickSlotGroupView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE97CA7B2A9A7199001073DE /* QuickSlotGroupView.swift */; };
Expand Down Expand Up @@ -207,6 +208,7 @@
DE9457302A9FB01400B0B768 /* PreferencesTableView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreferencesTableView.swift; sourceTree = "<group>"; };
DE9457332A9FB1D300B0B768 /* RequestAccessView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RequestAccessView.swift; sourceTree = "<group>"; };
DE9457362A9FC0A800B0B768 /* SecurityScopedResourceAccess.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SecurityScopedResourceAccess.swift; sourceTree = "<group>"; };
DE94573C2A9FD33400B0B768 /* StorageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StorageView.swift; sourceTree = "<group>"; };
DE97CA682A9A6364001073DE /* PixelConversion+CGFloat.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "PixelConversion+CGFloat.swift"; sourceTree = "<group>"; };
DE97CA6E2A9A6EFC001073DE /* QuickSlotViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QuickSlotViewModel.swift; sourceTree = "<group>"; };
DE97CA712A9A6F0D001073DE /* QuickSlotButtonModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QuickSlotButtonModel.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -522,9 +524,8 @@
DE78862B2A9D1A9E00FE21DD /* View */ = {
isa = PBXGroup;
children = (
DE78862C2A9D1ADE00FE21DD /* PreferencesCell.swift */,
DE9457302A9FB01400B0B768 /* PreferencesTableView.swift */,
DE9457332A9FB1D300B0B768 /* RequestAccessView.swift */,
DE9457412A9FD69800B0B768 /* Table */,
DE94573F2A9FD68C00B0B768 /* Funtion */,
);
path = View;
sourceTree = "<group>";
Expand Down Expand Up @@ -589,6 +590,24 @@
path = Table;
sourceTree = "<group>";
};
DE94573F2A9FD68C00B0B768 /* Funtion */ = {
isa = PBXGroup;
children = (
DE9457332A9FB1D300B0B768 /* RequestAccessView.swift */,
DE94573C2A9FD33400B0B768 /* StorageView.swift */,
);
path = Funtion;
sourceTree = "<group>";
};
DE9457412A9FD69800B0B768 /* Table */ = {
isa = PBXGroup;
children = (
DE78862C2A9D1ADE00FE21DD /* PreferencesCell.swift */,
DE9457302A9FB01400B0B768 /* PreferencesTableView.swift */,
);
path = Table;
sourceTree = "<group>";
};
DE98E8382A98D48700F8744A /* QuickSlot */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -853,6 +872,7 @@
DE97CA862A9A7404001073DE /* QuickSlotViewModel.swift in Sources */,
DE3FF3762A978AB8009C88EF /* WindowCloseButton.swift in Sources */,
DE9457092A9E69D100B0B768 /* ScriptDescriptionsLabel.swift in Sources */,
DE94573D2A9FD33400B0B768 /* StorageView.swift in Sources */,
DE9457282A9F6E4400B0B768 /* GetUserMeScripts.swift in Sources */,
DE77BBD22A9E0AE8006CC98B /* WebViewUI.swift in Sources */,
DE3FF3772A978AB8009C88EF /* WindowMinimizeButton.swift in Sources */,
Expand Down
4 changes: 4 additions & 0 deletions Box42/Main/keyDown+BoxBaseContainerViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ extension BoxBaseContainerViewController {
StorageConfig.shared.setPeriod(.period1s)
}

if event.modifierFlags.contains(.command) && event.keyCode == 15 {
print("Cmd + R pressed, reloading...")
WebViewManager.shared.hostingWebView?.reload()
}

if event.keyCode == 53 { // Escape 키의 keyCode는 53입니다.
print("escape")
Expand Down
112 changes: 112 additions & 0 deletions Box42/Preferences/View/Funtion/StorageView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
//
// StorageView.swift
// Box42
//
// Created by Chanhee Kim on 8/31/23.
//
import AppKit
import SnapKit

class StorageView: NSView {

var currentStorageTextField: NSTextField = NSTextField()
var remainingStorageTextField: NSTextField = NSTextField()
var totalStorageTextField: NSTextField = NSTextField()
var thresholdTextField: NSTextField = NSTextField()
var intervalTextField: NSTextField = NSTextField()
var executeScriptButton: NSButton = NSButton()

override init(frame frameRect: NSRect) {
super.init(frame: frameRect)

// Add subviews
addSubview(currentStorageTextField)
addSubview(remainingStorageTextField)
addSubview(totalStorageTextField)
addSubview(thresholdTextField)
addSubview(intervalTextField)
addSubview(executeScriptButton)

// Initialize UI elements
initTextFields()
initButton()

// Set constraints
setConstraints()
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

func initTextFields() {
// Initialize textfields
currentStorageTextField.stringValue = "Current Storage: ?? GB"
remainingStorageTextField.stringValue = "Remaining Storage: ?? GB"
totalStorageTextField.stringValue = "Total Storage: ?? GB"
thresholdTextField.placeholderString = "Enter threshold (%)"
intervalTextField.placeholderString = "Enter interval (seconds)"

[currentStorageTextField, remainingStorageTextField, totalStorageTextField, thresholdTextField, intervalTextField].forEach { textField in
textField.isEditable = false
textField.isBordered = false
textField.backgroundColor = NSColor.clear
}

intervalTextField.isEditable = true
thresholdTextField.isEditable = true
}

func initButton() {
executeScriptButton.title = "Run Script"
executeScriptButton.target = self
executeScriptButton.action = #selector(runScript(_:))
}

func setConstraints() {
// Use SnapKit to set constraints
currentStorageTextField.snp.makeConstraints { make in
make.top.leading.equalToSuperview().offset(20)
}

remainingStorageTextField.snp.makeConstraints { make in
make.top.equalTo(currentStorageTextField.snp.bottom).offset(10)
make.leading.equalToSuperview().offset(20)
}

totalStorageTextField.snp.makeConstraints { make in
make.top.equalTo(remainingStorageTextField.snp.bottom).offset(10)
make.leading.equalToSuperview().offset(20)
}

thresholdTextField.snp.makeConstraints { make in
make.top.equalTo(totalStorageTextField.snp.bottom).offset(10)
make.leading.equalToSuperview().offset(20)
make.height.equalTo(30)
make.width.equalTo(100)
}

intervalTextField.snp.makeConstraints { make in
make.top.equalTo(thresholdTextField.snp.bottom).offset(10)
make.leading.equalToSuperview().offset(20)
make.height.equalTo(30)
make.width.equalTo(100)
}

executeScriptButton.snp.makeConstraints { make in
make.top.equalTo(intervalTextField.snp.bottom).offset(20)
make.leading.equalToSuperview().offset(20)
}
}

@objc func runScript(_ sender: NSButton) {
// Logic to run script
}

// Update storage information
func updateStorageInfo(current: String, remaining: String, total: String) {
currentStorageTextField.stringValue = "Current Storage: \(current) GB"
remainingStorageTextField.stringValue = "Remaining Storage: \(remaining) GB"
totalStorageTextField.stringValue = "Total Storage: \(total) GB"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,18 @@ import AppKit
import SnapKit
import Combine

enum PreferencesCellList: Int, CaseIterable {
case requestAccessView = 1
case cpu = 2
case my = 3
enum PreferencesCellList: CaseIterable {
case requestAccessView
case storage
case cpu
case my

var height: CGFloat {
switch self {
case .requestAccessView:
return 100.0
case .storage:
return 300.0
case .cpu:
return 40.0
case .my:
Expand All @@ -28,6 +31,7 @@ enum PreferencesCellList: Int, CaseIterable {

class PreferencesTableView: NSTableView {
let requestAccessView = RequestAccessView()
let storageView = StorageView()

func setup() {
self.delegate = self
Expand All @@ -37,6 +41,8 @@ class PreferencesTableView: NSTableView {
column1.width = 100.0
column1.title = "Preferences"
self.addTableColumn(column1)

self.selectionHighlightStyle = .none
}

}
Expand All @@ -48,6 +54,8 @@ extension PreferencesTableView: NSTableViewDelegate, NSTableViewDataSource {
switch allCases[row] {
case .requestAccessView:
return requestAccessView
case .storage:
return StorageView()
case .cpu:
// Return the view for the CPU cell
return NSView() // Placeholder
Expand Down