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

Merge: 2.5 Week Release #99

Merged
merged 23 commits into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
f0568ce
refactor: 파일구조를 변경하였습니다.
chanhihi Aug 28, 2023
5b1e4a4
feat: icon 변경을 front와의 endpoint url 통신을 통해 구현하였습니다.
chanhihi Aug 28, 2023
3d348aa
chore: 필요없어진 icon 모델을 삭제합니다.
chanhihi Aug 28, 2023
bc394eb
feat: icon을 userprofile과 동기화합니다.
chanhihi Aug 28, 2023
e69f834
chore: 잘못된 함수명을 수정합니다.
chanhihi Aug 28, 2023
2c68cf0
Merge pull request #89 from 42Box/88-webview-의-icon-변경-기능을-구현합니다
chanhihi Aug 28, 2023
0fec852
refactor: QuickSlot안으로 preferenceView가 들어가는 구조로 변경함에 따라 파일구조도 변경합니다.
chanhihi Aug 28, 2023
e104f02
feat: QuickSlot에서 contents view의 전환을 돕습니다.
chanhihi Aug 28, 2023
fc6593b
build: pbxproj
chanhihi Aug 29, 2023
4b81cd2
feat: front <-> app 통신 (#93)
chanhihi Aug 29, 2023
dd601a2
Merge branch 'cluster_develop' of https://github.com/42Box/macOS into…
chanhihi Aug 29, 2023
fc8af6c
fix: 컴파일 오류 해결
chanhihi Aug 29, 2023
cb1b6e5
Merge pull request #95 from 42Box/90-preferenceview-re
chanhihi Aug 29, 2023
678a6de
feat: script파일을 다운로드하고 실행합니다.
chanhihi Aug 29, 2023
53c9c56
feat: client 통신과 유저 정보의 동기화 기능을 추가합니다.
chanhihi Aug 29, 2023
e78695c
feat: quickSlot에서 scripts view가 보일 수 있게 됩니다.
chanhihi Aug 29, 2023
c6606dc
feat: script 기능을 구성하기 위한 요소들을 채워넣습니다.
chanhihi Aug 29, 2023
fb00e09
feat: scripts 기능을 mvvm구조로 설계합니다.
chanhihi Aug 29, 2023
7b10115
feat: script 기능의 뷰 구조를 Table View로 구성합니다.
chanhihi Aug 29, 2023
d0ff889
feat: 스크립트 파일들을 파일매니저로 다루는 클래스를 만듭니다.
chanhihi Aug 29, 2023
d46ac0e
feat: custom button 구현
chanhihi Aug 29, 2023
1f5f73a
chore: 🛠
chanhihi Aug 29, 2023
6d4c188
Merge pull request #98 from 42Box/96-scriptview
chanhihi Aug 29, 2023
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
225 changes: 195 additions & 30 deletions Box42.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion Box42/ButtonGroup/ButtonGroupViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Cocoa

class ButtonGroupViewController: NSViewController {
override func loadView() {
// let ButtonViewGroup = BoxButtonViewGroup()
// let ButtonViewGroup = BoxButtonViewGroup(clickAction: clickAction)
let ButtonViewGroup = NSView()
ButtonViewGroup.wantsLayer = true
ButtonViewGroup.layer?.backgroundColor = NSColor.black.cgColor
Expand All @@ -20,6 +20,10 @@ class ButtonGroupViewController: NSViewController {
super.viewDidLoad()
}

func clickAction(_ sender: NSButton?) {
print("click Action")
}

func preference() {
print("preference")
}
Expand Down
26 changes: 26 additions & 0 deletions Box42/Icon/IconController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
// IconController.swift
// Box42
//
// Created by Chanhee Kim on 8/30/23.
//

import Foundation

class IconController {
let icon = MenubarViewController()

init() {
NotificationCenter.default.addObserver(self,
selector: #selector(handleUserProfileIconUpdate),
name: .didUpdateUserProfile,
object: nil)
}

@objc private func handleUserProfileIconUpdate() {
DispatchQueue.main.async {
self.icon.buttonImageChange(UserManager.shared.getUserProfile()?.icon ?? "fox")
}
print("Icon Changed")
}
}
35 changes: 35 additions & 0 deletions Box42/Main/BoxBaseContainerViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Cocoa
import SnapKit

class BoxBaseContainerViewController: NSViewController {
// MARK: - LeftContainer
var splitView: BoxBaseSplitView = BoxBaseSplitView()
var contentGroup: BoxContentsViewGroup = BoxContentsViewGroup()
var toolbarGroupVC: ToolbarViewController = ToolbarViewController()
Expand All @@ -17,6 +18,11 @@ class BoxBaseContainerViewController: NSViewController {
let windowViewGroupVC: WindowButtonViewController = WindowButtonViewController()
var leftContainer: MovableContainerView = MovableContainerView()
var buttonGroupVC: ButtonGroupViewController = ButtonGroupViewController()

// MARK: - QuickSlot
var preferenceVC: PreferencesViewController = PreferencesViewController()
var scriptsVC: ScriptsViewController = ScriptsViewController()

weak var menubarVCDelegate: MenubarViewControllerDelegate? // extension

override func loadView() {
Expand All @@ -32,8 +38,11 @@ class BoxBaseContainerViewController: NSViewController {

override func viewDidLoad() {
self.view.wantsLayer = true

// self.view.layer?.backgroundColor = NSColor(hex: "#FF9548").cgColor
self.view.layer?.backgroundColor = NSColor(hex: "#E7E7E7").cgColor

NotificationCenter.default.addObserver(self, selector: #selector(handleButtonTapped), name: .collectionButtonTapped, object: nil)
}

func BoxButtonViewGroupInit() -> BoxButtonViewGroup {
Expand Down Expand Up @@ -171,3 +180,29 @@ extension BoxBaseContainerViewController: BoxFunctionViewControllerDelegate {
clickBtn(sender: "box")
}
}

extension BoxBaseContainerViewController {
@objc func handleButtonTapped(notification: NSNotification) {
if let button = notification.object as? NSButton {
if button.title == QuickSlotUI.title.preferences {
print("Button with title \(button.title) was tapped in BaseVC")
contentGroup.showPreferences()
}

if button.title == QuickSlotUI.title.scripts {
print("Button with title \(button.title) was tapped in BaseVC")
contentGroup.showScripts()
}

if button.title == QuickSlotUI.title.user {
print("Button with title \(button.title) was tapped in BaseVC")
contentGroup.removeAllSubviews()
print(WebViewManager.shared.hostingWebView!)
contentGroup.addSubview(WebViewManager.shared.hostingWebView!)
WebViewManager.shared.hostingWebView!.snp.makeConstraints { make in
make.top.bottom.left.right.equalToSuperview()
}
}
}
}
}
4 changes: 3 additions & 1 deletion Box42/Menubar/MenubarModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ class StatusBar {
var isRunning: Bool
var interval: Double
var alertCount: Int

var version: Int

init() {
self.statusItem = NSStatusItem()
self.frames = [NSImage]()
self.cnt = 0
self.isRunning = false
self.interval = 1.0
self.alertCount = 0
self.version = 0
}
}
6 changes: 4 additions & 2 deletions Box42/Menubar/MenubarViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class MenubarViewController: NSViewController {
var statusBarVM = StatusBarViewModel()
lazy var eventMonitor: EventMonitor = self.setupEventMonitor()
var boxWindowController: BoxWindowController?

func menubarViewControllerInit() {
self.buttonInit()
}
Expand Down Expand Up @@ -47,7 +47,9 @@ class MenubarViewController: NSViewController {
}

func buttonImageChange(_ img: String) {
self.menubarStopRunning()
statusBarVM.changeStatusBarIcon(img)
self.menubarStartRunning()
}

func buttonActionInit() {
Expand Down Expand Up @@ -122,7 +124,7 @@ extension MenubarViewController: MenubarViewControllerDelegate {
}
window.level = .floating
}
boxWindowController?.showWindow(sender)
boxWindowController?.showWindow(sender)
}
}
}
Expand Down
44 changes: 30 additions & 14 deletions Box42/Menubar/MenubarViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class StatusBarViewModel {
let cpu: CPU
let statusBar: StatusBar
private var currentAnimationWorkItem: DispatchWorkItem?
private let scheduleQueue = DispatchQueue(label: "animation.scheduleQueue")

init () {
self.statusBar = StatusBar.shared
Expand All @@ -23,7 +24,13 @@ class StatusBarViewModel {

func changeStatusBarIcon(_ imgName: String) {
statusBar.frames.removeAll()

currentAnimationWorkItem?.cancel()
if statusBar.version == Int.max {
statusBar.version = 0
} else {
statusBar.version += 1
}

switch imgName {
case "cat": for i in (0...4) {statusBar.frames.append(NSImage(imageLiteralResourceName: "cat_page\(i)"))}
case "gon": for i in (1...5) {statusBar.frames.append(NSImage(imageLiteralResourceName: "gon_\(i)"))}
Expand Down Expand Up @@ -52,25 +59,34 @@ class StatusBarViewModel {
self.animate()
}
}

func scheduleAnimation() {
currentAnimationWorkItem?.cancel()

let workItem = DispatchWorkItem { [weak self] in
self?.statusBar.statusItem.button?.image = self?.statusBar.frames[self?.statusBar.cnt ?? 0]
self?.statusBar.cnt = ((self?.statusBar.cnt)! + 1) % (self?.statusBar.frames.count ?? 1)
func scheduleAnimation() {
scheduleQueue.sync {
currentAnimationWorkItem?.cancel()

if self?.statusBar.isRunning ?? false {
self?.scheduleAnimation()
let currentVersion = statusBar.version

let workItem = DispatchWorkItem { [weak self] in
guard self?.statusBar.version == currentVersion else { return }

self?.statusBar.statusItem.button?.image = self?.statusBar.frames[self?.statusBar.cnt ?? 0]

if let cnt = self?.statusBar.cnt, let framesCount = self?.statusBar.frames.count {
self?.statusBar.cnt = (cnt + 1) % framesCount
}

if self?.statusBar.isRunning ?? false {
self?.scheduleAnimation()
}
}

currentAnimationWorkItem = workItem
DispatchQueue.main.asyncAfter(deadline: .now() + statusBar.interval, execute: workItem)
}

currentAnimationWorkItem = workItem
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + statusBar.interval, execute: workItem)
}

func stopRunning() {
statusBar.isRunning = cpu.StopCPU()
statusBar.isRunning = cpu.stopCPU()
currentAnimationWorkItem?.cancel()
statusBar.cnt = 0
}
Expand Down
19 changes: 0 additions & 19 deletions Box42/Preferences/Icon.swift

This file was deleted.

4 changes: 0 additions & 4 deletions Box42/Preferences/PreferencesViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@ class PreferencesViewController: NSViewController {

var stackBox: [NSView] = []

let icons = iconModel().icon
icons.forEach { (icon) in
stackBox.append(NSButton(title: "Change \(icon) Icon", target: self, action: #selector(changeIconButtonPressed)))
}

let scripts = Scripts().info
scripts.forEach { (script) in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ class ScriptsLogicController {
static let shared = ScriptsLogicController()

private init() {
NotificationCenter.default.addObserver(self, selector: #selector(handleButtonTapped), name: NSNotification.Name(NotifConst.object.collectionButtonTapped), object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(handleButtonTapped), name: .collectionButtonTapped, object: nil)
}

@objc func handleButtonTapped(notification: NSNotification) {
if let button = notification.object as? NSButton {
let buttonTitle = button.title // 메인 스레드에서 타이틀을 캡쳐
let buttonTitle = button.title
print("Button with title \(buttonTitle) was tapped")

DispatchQueue.global(qos: .background).async { [weak self] in
if buttonTitle == "clean" {
if buttonTitle == QuickSlotUI.title.clean {
self?.executeCleanScript()
}
}
Expand Down Expand Up @@ -53,5 +53,4 @@ class ScriptsLogicController {
}
}
}

}
4 changes: 2 additions & 2 deletions Box42/QuickSlot/Controller/QuickSlotViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class QuickSlotViewController: NSViewController {
let quickSlotViewGroup = QuickSlotGroupView()
quickSlotViewGroup.headerAction = headerAction

NotificationCenter.default.addObserver(self, selector: #selector(handleButtonTapped), name: NSNotification.Name(NotifConst.object.collectionButtonTapped), object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(handleButtonTapped), name: .collectionButtonTapped, object: nil)

self.view = quickSlotViewGroup
}
Expand All @@ -26,7 +26,7 @@ class QuickSlotViewController: NSViewController {

@objc func handleButtonTapped(notification: NSNotification) {
if let button = notification.object as? NSButton {
print("Button with title \(button.title) was tapped")
print("Button with title \(button.title) was tapped in QuickSlotView")
}
}
}
4 changes: 2 additions & 2 deletions Box42/QuickSlot/Model/QuickSlotButtonModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ struct QuickSlotButtonModel {
let id: UUID
var title: String

init(title: String = "Default") {
self.id = UUID()
init(id: UUID = UUID(), title: String = "Default") {
self.id = id
self.title = title
}
}
7 changes: 7 additions & 0 deletions Box42/QuickSlot/Model/QuickSlotUI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,11 @@ enum QuickSlotUI {
enum color {
// static let pinText = NSColor(hex: "#696969")
}

enum title {
static let clean = "Clean"
static let preferences = "Preferences"
static let scripts = "Scripts"
static let user = "User"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
//
// PreferencesViewController.swift
// Box42
//
// Created by Chanhee Kim on 7/24/23.
//

import Cocoa
import SnapKit

class PreferencesViewController: NSViewController {
var prefTableView : NSTableView?

override func loadView() {
self.view = NSView()
self.view.wantsLayer = true
self.view.layer?.backgroundColor = NSColor.blue.cgColor

prefTableView = NSTableView(frame: .zero)
// Column 추가
let column1 = NSTableColumn(identifier: NSUserInterfaceItemIdentifier("Column1"))
column1.width = 100.0
column1.title = "Column 1"
prefTableView?.addTableColumn(column1)

// delegate와 dataSource 설정
prefTableView?.delegate = self
prefTableView?.dataSource = self

// TableView를 스크롤 뷰에 추가 (일반적으로 NSTableView는 NSScrollView 안에 위치합니다)
let scrollView = NSScrollView()
scrollView.documentView = prefTableView
self.view.addSubview(scrollView)


scrollView.snp.makeConstraints({ make in
make.edges.equalToSuperview()
})

prefTableView?.snp.makeConstraints({ make in
make.edges.equalToSuperview()
})
}
}

extension PreferencesViewController: NSTableViewDelegate, NSTableViewDataSource {
func numberOfRows(in tableView: NSTableView) -> Int {
return 10 // 총 로우 수
}

func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? {
let cell = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier("MyCell"), owner: self) as? NSTableCellView ?? NSTableCellView()
cell.textField?.stringValue = "Row \(row), Column \(tableColumn?.identifier ?? NSUserInterfaceItemIdentifier(""))"
return cell
}

func tableView(_ tableView: NSTableView, heightOfRow row: Int) -> CGFloat {
return 44.0 // 셀 높이를 44로 설정
}
}

Loading