Skip to content
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
.DS_Store
Box42/.DS_Store

.prettierrc
.swift-format
561 changes: 561 additions & 0 deletions Box42.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions Box42.xcodeproj/project.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Bucket
uuid = "96FF2BD3-0568-4B42-8A61-04ECE5B48840"
type = "1"
version = "2.0">
</Bucket>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>Box42.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
</dict>
</dict>
</plist>
104 changes: 96 additions & 8 deletions Box42/Preferences/PreferencesController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,18 @@
//

import Cocoa
import Foundation

class PreferencesViewController: NSViewController {

let menubarVC = MenubarViewController()
private var stackView: NSStackView!
private var rightView: NSView!
private var outputView: NSTextView!

override func loadView() {
self.view = NSView()
self.stackView = NSStackView()
self.stackView.orientation = .horizontal
self.stackView.orientation = .vertical
self.stackView.distribution = .fillEqually
self.stackView.spacing = 20
self.view.addSubview(stackView)
Expand All @@ -32,10 +34,39 @@ class PreferencesViewController: NSViewController {
self.stackView.addArrangedSubview(leftView)
self.stackView.addArrangedSubview(rightView)

let iconButton = NSButton(title: "Change Icon", target: self, action: #selector(changeIconButtonPressed))
let cronButton = NSButton(title: "Cron Script", target: self, action: #selector(cronButtonPressed))
outputView = NSTextView()
outputView.translatesAutoresizingMaskIntoConstraints = false
rightView.addSubview(outputView)

NSLayoutConstraint.activate([
outputView.topAnchor.constraint(equalTo: rightView.topAnchor),
outputView.leadingAnchor.constraint(equalTo: rightView.leadingAnchor),
outputView.trailingAnchor.constraint(equalTo: rightView.trailingAnchor),
outputView.bottomAnchor.constraint(equalTo: rightView.bottomAnchor)
])


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
stackBox.append(NSButton(title: "\(script.name) Script: \(script.description)", target: self, action: #selector(scriptButtonPressed)))

}

// let scriptButton = NSButton(title: "Script", target: self, action: #selector(scriptButtonPressed))
let appleScriptButton = NSButton(title: "Apple Script", target: self, action: #selector(scriptButtonPressed))
let etcButton = NSButton(title: "Etc.", target: self, action: #selector(etcButtonPressed))
let buttonStackView = NSStackView(views: [iconButton, cronButton, etcButton])

// stackBox.append(scriptButton)
stackBox.append(appleScriptButton)
stackBox.append(etcButton)
let buttonStackView = NSStackView(views: stackBox)
buttonStackView.orientation = .vertical
buttonStackView.distribution = .fillEqually
buttonStackView.spacing = 20
Expand All @@ -49,12 +80,69 @@ class PreferencesViewController: NSViewController {
])
}

@objc func changeIconButtonPressed() {
@objc func changeIconButtonPressed(_ sender: NSButton) {
// Change the content of the right view for icon changing
let icon = sender.title.split(separator: " ").map{String($0)}
print(icon[1])
menubarVC.menubarStopRunning()
menubarVC.buttonImageChange(icon[1])
menubarVC.menubarStartRunning()
}

@objc func cronButtonPressed() {
// Change the content of the right view for cron script selection
@objc func scriptButtonPressed(_ sender: NSButton) {
let script = sender.title.split(separator: " ").map{String($0)}
if script[1] == "Script:" {
if let scriptPath = Bundle.main.path(forResource: script[0], ofType: "sh") {
let task = Process()
task.launchPath = "/bin/sh"
task.arguments = [scriptPath]

let outputPipe = Pipe()
task.standardOutput = outputPipe
task.standardError = outputPipe


task.standardError = outputPipe

outputPipe.fileHandleForReading.readabilityHandler = { [weak self] fileHandle in
if #available(OSX 10.15.4, *) {
if let data = try? fileHandle.readToEnd(), let output = String(data: data, encoding: .utf8) {
DispatchQueue.main.async {
if let outputView = self?.outputView {
outputView.string += "\(output)"
} else {
print("outputView is nil")
}
}
}
} else {
// Fallback on earlier versions
}
}


task.launch()
task.waitUntilExit()

// let outputData = outputPipe.fileHandleForReading.readDataToEndOfFile()
// let output = String(data: outputData, encoding: .utf8) ?? ""
// print("Output: \(output)")
} else {
print("Script not found")
}
} else if sender.title == "Apple Script" {
let appleScriptCode = "display dialog \"Hello, World!\""

if let appleScript = NSAppleScript(source: appleScriptCode) {
var errorDict: NSDictionary? = nil
appleScript.executeAndReturnError(&errorDict)

if let error = errorDict {
print("Error: \(error)")
}
}

}
}

@objc func etcButtonPressed() {
Expand Down
68 changes: 7 additions & 61 deletions Box42/Resources/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -173,67 +173,17 @@
</objects>
<point key="canvasLocation" x="74" y="-203"/>
</scene>
<!--_Box Controller-->
<scene sceneID="FDO-e1-3rp">
<objects>
<viewController storyboardIdentifier="_BoxController" id="gIi-Fb-I3o" userLabel="_Box Controller" customClass="BoxController" customModule="Box42" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" verifyAmbiguity="off" id="TiL-dt-mkO">
<rect key="frame" x="0.0" y="0.0" width="900" height="700"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<subviews>
<customView id="INZ-EX-kDJ">
<rect key="frame" x="0.0" y="0.0" width="132" height="700"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<subviews>
<box verticalHuggingPriority="750" fixedFrame="YES" boxType="separator" translatesAutoresizingMaskIntoConstraints="NO" id="mRA-Vv-3gU">
<rect key="frame" x="12" y="18" width="108" height="5"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
</box>
</subviews>
<constraints>
<constraint firstAttribute="width" constant="132" id="VeD-fm-G75"/>
</constraints>
</customView>
<customView translatesAutoresizingMaskIntoConstraints="NO" id="wSX-Lf-Y7g">
<rect key="frame" x="132" y="0.0" width="768" height="700"/>
<constraints>
<constraint firstAttribute="width" constant="768" id="P3a-KZ-K2x"/>
</constraints>
</customView>
</subviews>
<constraints>
<constraint firstAttribute="trailing" secondItem="wSX-Lf-Y7g" secondAttribute="trailing" id="4aT-cG-d52"/>
<constraint firstAttribute="bottom" secondItem="INZ-EX-kDJ" secondAttribute="bottom" id="5Oe-oJ-6Ep"/>
<constraint firstItem="wSX-Lf-Y7g" firstAttribute="leading" secondItem="INZ-EX-kDJ" secondAttribute="trailing" id="85h-Jg-ZxM"/>
<constraint firstItem="INZ-EX-kDJ" firstAttribute="leading" secondItem="TiL-dt-mkO" secondAttribute="leading" id="JJl-NI-kKY"/>
<constraint firstItem="wSX-Lf-Y7g" firstAttribute="leading" secondItem="INZ-EX-kDJ" secondAttribute="trailing" id="KQI-4y-kbU"/>
<constraint firstItem="INZ-EX-kDJ" firstAttribute="top" secondItem="TiL-dt-mkO" secondAttribute="top" id="Msu-h5-kx7"/>
<constraint firstItem="wSX-Lf-Y7g" firstAttribute="top" secondItem="TiL-dt-mkO" secondAttribute="top" id="OaQ-LB-N8c"/>
<constraint firstItem="wSX-Lf-Y7g" firstAttribute="leading" secondItem="INZ-EX-kDJ" secondAttribute="trailing" id="QSq-OR-7zS"/>
<constraint firstAttribute="bottom" secondItem="wSX-Lf-Y7g" secondAttribute="bottom" id="gMz-h7-ml5"/>
</constraints>
</view>
<connections>
<outlet property="boxView" destination="TiL-dt-mkO" id="LTJ-21-eyx"/>
<outlet property="buttonViewGroup" destination="INZ-EX-kDJ" id="dZB-tM-Jhh"/>
<outlet property="divider" destination="mRA-Vv-3gU" id="Meb-TJ-dtY"/>
<outlet property="hostingViewGroup" destination="wSX-Lf-Y7g" id="ZgT-tU-ZGf"/>
</connections>
</viewController>
<customObject id="aK9-Xf-jfI" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="74" y="1056"/>
</scene>
<!--Box Controller-->
<!--Box View Controller-->
<scene sceneID="2YF-NG-qgR">
<objects>
<viewController storyboardIdentifier="BoxController" id="vnM-6c-Kef" customClass="BoxController" customModule="Box42" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" verifyAmbiguity="off" id="G4d-7M-cg0">
<rect key="frame" x="0.0" y="0.0" width="900" height="700"/>
<customObject id="xrs-eX-5QB" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
<viewController storyboardIdentifier="Main" id="vnM-6c-Kef" customClass="BoxViewController" customModule="Box42" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" misplaced="YES" verifyAmbiguity="off" id="G4d-7M-cg0">
<rect key="frame" x="0.0" y="0.0" width="900" height="806"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<subviews>
<customView id="ulN-bz-DqK">
<rect key="frame" x="0.0" y="0.0" width="132" height="700"/>
<rect key="frame" x="0.0" y="106" width="132" height="700"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<subviews>
<box verticalHuggingPriority="750" fixedFrame="YES" boxType="separator" translatesAutoresizingMaskIntoConstraints="NO" id="QtO-vD-ZQX">
Expand Down Expand Up @@ -266,14 +216,10 @@
</view>
<connections>
<outlet property="boxView" destination="G4d-7M-cg0" id="lRF-TY-gNh"/>
<outlet property="buttonViewGroup" destination="ulN-bz-DqK" id="OlQ-fm-tRr"/>
<outlet property="divider" destination="QtO-vD-ZQX" id="UfE-2c-FbH"/>
<outlet property="hostingViewGroup" destination="ru4-50-bBK" id="Rig-Pv-QaA"/>
</connections>
</viewController>
<customObject id="xrs-eX-5QB" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="74" y="270"/>
<point key="canvasLocation" x="74" y="323"/>
</scene>
</scenes>
</document>
25 changes: 25 additions & 0 deletions Box42/Scripts/Scripts.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// Scripts.swift
// Box42
//
// Created by Chanhee Kim on 8/11/23.
//

import Foundation

struct Scripts {
var info: [(name: String, description: String)] = [("cleanCache", "cleaning cache"), ("brewInGoinfre",
"brew download in goinfre")]
}

struct Script {
var id: UUID
var name: String
var description: String

init(name: String, description: String) {
self.id = UUID()
self.name = name
self.description = description
}
}
Loading