-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #98 from 42Box/96-scriptview
feat: script 기능을 구현합니다.
- Loading branch information
Showing
34 changed files
with
993 additions
and
135 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
16 changes: 16 additions & 0 deletions
16
Box42.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"object": { | ||
"pins": [ | ||
{ | ||
"package": "SnapKit", | ||
"repositoryURL": "https://github.com/SnapKit/SnapKit.git", | ||
"state": { | ||
"branch": null, | ||
"revision": "f222cbdf325885926566172f6f5f06af95473158", | ||
"version": "5.6.0" | ||
} | ||
} | ||
] | ||
}, | ||
"version": 1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// | ||
// ExcuteScripts.swift | ||
// Box42 | ||
// | ||
// Created by Chanhee Kim on 8/29/23. | ||
// | ||
|
||
import Foundation | ||
|
||
class ExcuteScripts { | ||
static func executeShellScript(path: String) { | ||
let task = Process() | ||
task.launchPath = "/bin/sh" | ||
task.arguments = [path] | ||
task.launch() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// | ||
// ScriptsFileManager.swift | ||
// Box42 | ||
// | ||
// Created by Chanhee Kim on 8/29/23. | ||
// | ||
|
||
import Foundation | ||
|
||
class ScriptsFileManager { | ||
static func downloadFile(from URLString: String) { | ||
let fileManager = FileManager.default | ||
let pathComponent = URLString.split(separator: "/").map { String($0) }.last ?? "" | ||
let documentsURL = try? fileManager.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: false) | ||
let savedURL = documentsURL?.appendingPathComponent(pathComponent) | ||
|
||
if let savedURL = savedURL, fileManager.fileExists(atPath: savedURL.path) { | ||
print("File already exists, executing...") | ||
ExcuteScripts.executeShellScript(path: savedURL.path) | ||
return | ||
} | ||
|
||
guard let url = URL(string: URLString) else { | ||
print("Invalid URL: \(URLString)") | ||
return | ||
} | ||
|
||
let task = URLSession.shared.downloadTask(with: url) { (location, _, error) in | ||
guard let location = location else { | ||
print("Download failed: \(error?.localizedDescription ?? "Unknown error")") | ||
return | ||
} | ||
|
||
do { | ||
let documentsURL = try fileManager.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: false) | ||
let savedURL = documentsURL.appendingPathComponent(pathComponent) | ||
try fileManager.moveItem(at: location, to: savedURL) | ||
|
||
print("Saved URL: ", savedURL) | ||
|
||
ExcuteScripts.executeShellScript(path: savedURL.path) | ||
|
||
} catch { | ||
print("File error: \(error)") | ||
} | ||
} | ||
task.resume() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// | ||
// ScriptsViewController.swift | ||
// Box42 | ||
// | ||
// Created by Chanhee Kim on 8/29/23. | ||
// | ||
|
||
import Cocoa | ||
import Foundation | ||
|
||
class ScriptsViewController: NSViewController { | ||
var scriptsTableView: ScriptsTableView? | ||
var viewModel: ScriptViewModel? = ScriptViewModel() { | ||
didSet { | ||
scriptsTableView?.viewModel = viewModel | ||
} | ||
} | ||
|
||
override func loadView() { | ||
self.view = NSView() | ||
self.view.wantsLayer = true | ||
self.view.layer?.backgroundColor = NSColor.blue.cgColor | ||
|
||
scriptsTableView = ScriptsTableView(frame: .zero) | ||
scriptsTableView?.setup() | ||
scriptsTableView?.viewModel = viewModel | ||
|
||
let scrollView = NSScrollView() | ||
scrollView.documentView = scriptsTableView | ||
self.view.addSubview(scrollView) | ||
|
||
scrollView.snp.makeConstraints({ make in | ||
make.edges.equalToSuperview() | ||
}) | ||
|
||
scriptsTableView?.snp.makeConstraints({ make in | ||
make.edges.equalToSuperview() | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.