Compare commits

..

8 commits
main ... main

Author SHA1 Message Date
Etienne Roesch
bcd9af6e8c ENH: Better looking status bar icon 2025-04-16 17:00:18 +01:00
Etienne Roesch
1a40bf1065 FIX: forcing colour for text in case macos dark/light mode enabled 2025-04-10 13:36:17 +01:00
Etienne Roesch
2b61760d94 ENH: ScrollViewReader with full-space background colour 2025-04-05 22:02:22 +01:00
Etienne Roesch
4abda00033 FIX: fixed issues due to ScrollView limit and stream rate 2025-04-04 11:27:48 +01:00
Etienne Roesch
80cddb0314 FIX: Replaced statusbar to show icon instead of string. 2025-04-02 18:37:29 +01:00
Etienne Roesch
d3b066218f FIX: Silences error due to metallib on resizing of window 2025-03-31 11:47:45 +01:00
Etienne Roesch
c946f6577f ENH: Added mention about macos security setting in README.org 2025-03-29 16:40:15 +00:00
Etienne Roesch
a3a858a891 ENH: Fixed sizing of the main window. 2025-03-29 16:23:21 +00:00
12 changed files with 224 additions and 132 deletions

View file

@ -397,7 +397,7 @@
COMBINE_HIDPI_IMAGES = YES; COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 1; CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_ASSET_PATHS = "\"MSG Desktop/Preview Content\""; DEVELOPMENT_ASSET_PATHS = "\"MSG Desktop/Preview Content\"";
DEVELOPMENT_TEAM = C8Z9PRF4VH; DEVELOPMENT_TEAM = RN94J52F92;
ENABLE_HARDENED_RUNTIME = YES; ENABLE_HARDENED_RUNTIME = YES;
ENABLE_PREVIEWS = YES; ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES; GENERATE_INFOPLIST_FILE = YES;
@ -424,7 +424,7 @@
COMBINE_HIDPI_IMAGES = YES; COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 1; CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_ASSET_PATHS = "\"MSG Desktop/Preview Content\""; DEVELOPMENT_ASSET_PATHS = "\"MSG Desktop/Preview Content\"";
DEVELOPMENT_TEAM = C8Z9PRF4VH; DEVELOPMENT_TEAM = RN94J52F92;
ENABLE_HARDENED_RUNTIME = YES; ENABLE_HARDENED_RUNTIME = YES;
ENABLE_PREVIEWS = YES; ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES; GENERATE_INFOPLIST_FILE = YES;

Binary file not shown.

After

Width:  |  Height:  |  Size: 207 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 100 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 207 KiB

View file

@ -0,0 +1,23 @@
{
"images" : [
{
"filename" : "512@1x.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "512@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "1024.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

View file

@ -7,38 +7,61 @@
import SwiftUI import SwiftUI
struct ViewHeightKey: PreferenceKey {
static var defaultValue: CGFloat = 0
static func reduce(value: inout CGFloat, nextValue: () -> CGFloat) {
value = nextValue()
}
}
struct ContentView: View { struct ContentView: View {
@ObservedObject var appState = AppState.shared @ObservedObject var appState = AppState.shared
private let maxLines = 300 private let maxLines = 300
@State private var showCancelButton: Bool = false @State private var showCancelButton: Bool = false
@State private var showReinitPopup = false @State private var showReinitPopup = false
@State private var showCancelPopup = false @State private var showCancelPopup = false
@State private var imageHeight: CGFloat = 0
var body: some View { var body: some View {
VStack { GeometryReader { geometry in
// Image(systemName: "globe") VStack(spacing: 10) {
// .imageScale(.large) // App icon
// .foregroundStyle(.tint)
let appIcon = NSImage(named: NSImage.applicationIconName) let appIcon = NSImage(named: NSImage.applicationIconName)
// Use SwiftUI's Image to display the icon
Image(nsImage: appIcon ?? NSImage()) Image(nsImage: appIcon ?? NSImage())
.resizable() // Optional: if you want to resize the icon . resizable()
.scaledToFit() // Optional: makes sure the aspect ratio is maintained .scaledToFit()
.frame(maxHeight: 150)
.background(
GeometryReader { proxy in
Color.clear
.preference(key: ViewHeightKey.self, value: proxy.size.height)
}
)
.onPreferenceChange(ViewHeightKey.self) { height in
self.imageHeight = height
}
ZStack {
Color.black
.ignoresSafeArea()
// ScrollView fills remaining height
ScrollViewReader { proxy in ScrollViewReader { proxy in
ScrollView { ScrollView {
VStack(alignment: .leading) { LazyVStack(alignment: .leading, spacing: 0) {
TextEditor(text: $appState.output) let lines = appState.output.components(separatedBy: .newlines)
.font(.system(.body, design: .monospaced))
.frame(minWidth: 750, minHeight: 300) ForEach(lines.indices, id: \.self) { index in
.padding() Text(lines[index])
.disabled(true) .font(.system(.body, design: .monospaced))
.foregroundColor(.gray)
.frame(maxWidth: .infinity, alignment: .leading)
Text("")
.id("bottom")
} }
Color.clear.frame(height: 1).id("bottom")
}
.padding()
} }
.onChange(of: appState.output) { _, _ in .onChange(of: appState.output) { _, _ in
trimLinesIfNeeded() trimLinesIfNeeded()
@ -46,52 +69,62 @@ struct ContentView: View {
proxy.scrollTo("bottom", anchor: .bottom) proxy.scrollTo("bottom", anchor: .bottom)
} }
} }
// ScrollView {
// VStack(alignment: .leading) {
// TextEditor(text: $appState.output)
// .font(.system(.body, design: .monospaced))
// .frame(
// width: geometry.size.width - 60,
// height: max(0, geometry.size.height - imageHeight - 120) // - rough height of button row and padding
// )
// .padding()
// .disabled(true)
//
// Text("")
// .id("bottom")
// }
// }
// .onChange(of: appState.output) { _, _ in
// trimLinesIfNeeded()
// withAnimation {
// proxy.scrollTo("bottom", anchor: .bottom)
// }
// }
} }
}
// Buttons
HStack { HStack {
Button(action: { Button("Init") {
DispatchQueue.main.async { DispatchQueue.main.async { self.showCancelButton = true }
self.showCancelButton = true
}
runShellCommandAsync(command: "msg machine init", outputText: $appState.output, showButton: $showCancelButton) runShellCommandAsync(command: "msg machine init", outputText: $appState.output, showButton: $showCancelButton)
}) {
Text("Init")
} }
Button("Reinit") {
Button(action: {
showReinitPopup.toggle() showReinitPopup.toggle()
}) { }
Text("Reinit") .confirmationDialog("Are you sure?", isPresented: $showReinitPopup, titleVisibility: .visible) {
}.confirmationDialog("Are you sure?", isPresented: $showReinitPopup, titleVisibility: .visible) {
Button("Confirm", role: .destructive) { Button("Confirm", role: .destructive) {
DispatchQueue.main.async {
self.showCancelButton = true self.showCancelButton = true
runShellCommandAsync(command: "rm -rf ~/.guix && msg machine init", outputText: $appState.output, showButton: $showCancelButton) runShellCommandAsync(command: "rm -rf ~/.guix && msg machine init", outputText: $appState.output, showButton: $showCancelButton)
} }
}
Button("Cancel", role: .cancel) {} Button("Cancel", role: .cancel) {}
} }
Button("Start") {
Button(action: { runShellCommandAsync(command: "msg machine start", outputText: $appState.output, showButton: nil)
runShellCommandAsync(command: "msg machine start", outputText: $appState.output, showButton: nil) }) {
Text("Start")
} }
if showCancelButton {
Button(action: {
showCancelPopup.toggle()
}) {
Text("Cancel")
}.confirmationDialog("Are you sure?", isPresented: $showCancelPopup, titleVisibility: .visible) {
Button("Confirm", role: .destructive) {
if showCancelButton {
Button("Cancel") {
showCancelPopup.toggle()
}
.confirmationDialog("Are you sure?", isPresented: $showCancelPopup, titleVisibility: .visible) {
Button("Confirm", role: .destructive) {
runShellCommandAsync(command: "kill $(ps aux | grep '[g]uile' | awk '{print $2}')", outputText: $appState.output, showButton: nil) runShellCommandAsync(command: "kill $(ps aux | grep '[g]uile' | awk '{print $2}')", outputText: $appState.output, showButton: nil)
runShellCommandAsync(command: "kill $(ps aux | grep '[q]emu' | awk '{print $2}')", outputText: $appState.output, showButton: nil) runShellCommandAsync(command: "kill $(ps aux | grep '[q]emu' | awk '{print $2}')", outputText: $appState.output, showButton: nil)
DispatchQueue.main.async { DispatchQueue.main.async {
self.showCancelButton = false self.showCancelButton = false
} }
} }
@ -99,35 +132,34 @@ struct ContentView: View {
} }
} }
if !showCancelButton { if !showCancelButton {
Button(action: { Button("Stop") {
runShellCommandAsync(command: "msg machine stop", outputText: $appState.output, showButton: nil) }) { runShellCommandAsync(command: "msg machine stop", outputText: $appState.output, showButton: nil)
Text("Stop")
} }
} }
Button("Shell") {
Button(action: { runShellCommandAsync(
runShellCommandAsync(command: "osascript -e 'tell application \"Terminal\" to do script \"msg shell\"' -e 'tell application \"Terminal\" to activate'", outputText: $appState.output, showButton: nil) command: "osascript -e 'tell application \"Terminal\" to do script \"msg shell\"' -e 'tell application \"Terminal\" to activate'",
outputText: $appState.output,
}) { showButton: nil
Text("Shell") )
} }
} }
} }
.padding() .padding()
.frame(width: 800, height: 400) .frame(maxHeight: .infinity)
.onAppear {
// Silences error due to metallib on resizing of window
let device = MTLCreateSystemDefaultDevice()
_ = device?.makeDefaultLibrary()
}
}
} }
private func trimLinesIfNeeded() { private func trimLinesIfNeeded() {
let lines = AppState.shared.output.split(separator: "\n") let lines = AppState.shared.output.split(separator: "\n")
if lines.count > maxLines { if lines.count > maxLines {
_ = lines.count - maxLines
let trimmedLines = lines.suffix(maxLines) let trimmedLines = lines.suffix(maxLines)
AppState.shared.output = trimmedLines.joined(separator: "\n") AppState.shared.output = trimmedLines.joined(separator: "\n")
} }

View file

@ -0,0 +1,11 @@
//
// MGS_Desktop.metal
// MSG Desktop
//
// Created by Etienne Roesch on 31/03/2025.
//
#include <metal_stdlib>
using namespace metal;

View file

@ -34,6 +34,7 @@ func runShellCommandAsync(command: String, outputText: Binding<String>?, showBut
var observer: NSObjectProtocol? var observer: NSObjectProtocol?
observer = NotificationCenter.default.addObserver(forName: .NSFileHandleDataAvailable, object: fileHandle, queue: nil) { _ in observer = NotificationCenter.default.addObserver(forName: .NSFileHandleDataAvailable, object: fileHandle, queue: nil) { _ in
let data = fileHandle.availableData let data = fileHandle.availableData
if let output = String(data: data, encoding: .utf8), !output.isEmpty { if let output = String(data: data, encoding: .utf8), !output.isEmpty {
@ -59,6 +60,8 @@ func runShellCommandAsync(command: String, outputText: Binding<String>?, showBut
} }
class AppDelegate: NSObject, NSApplicationDelegate { class AppDelegate: NSObject, NSApplicationDelegate {
var window: NSWindow!
func applicationWillTerminate(_ notification: Notification) { func applicationWillTerminate(_ notification: Notification) {
runShellCommandAsync(command: "msg machine stop", outputText: nil, showButton: nil) runShellCommandAsync(command: "msg machine stop", outputText: nil, showButton: nil)
runShellCommandAsync(command: "kill $(ps aux | grep '[g]uile' | awk '{print $2}')", outputText: nil, showButton: nil) runShellCommandAsync(command: "kill $(ps aux | grep '[g]uile' | awk '{print $2}')", outputText: nil, showButton: nil)
@ -75,9 +78,28 @@ class AppDelegate: NSObject, NSApplicationDelegate {
func applicationDidFinishLaunching(_ notification: Notification) { func applicationDidFinishLaunching(_ notification: Notification) {
statusBarItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.variableLength) statusBarItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.variableLength)
let contentView = ContentView()
window = NSWindow(
contentRect: NSRect(x: 0, y: 0, width: 800, height: 600),
styleMask: [.titled, .closable, .resizable, .miniaturizable],
backing: .buffered,
defer: false
)
window.center()
//window.setFrameAutosaveName("MSG App") // to retain size after quitting
window.contentView = NSHostingView(rootView: contentView)
window.makeKeyAndOrderFront(nil)
if let button = statusBarItem.button { if let button = statusBarItem.button {
button.title = "MSG" //button.title = "MSG"
button.toolTip = "MSG App" button.toolTip = "MSG App"
if let image = NSImage(named: "AppStatusBar") {
let newSize = NSSize(width: 18, height: 18)
image.size = newSize
image.isTemplate = true // Important: so it adapts to dark/light mode but we need to get B&W icons..
button.image = image
}
button.target = self
} }
let menu = NSMenu() let menu = NSMenu()
@ -105,8 +127,6 @@ class AppDelegate: NSObject, NSApplicationDelegate {
} }
class AppState: ObservableObject { class AppState: ObservableObject {
@Published var output: String = "Please select an option \n" @Published var output: String = "Please select an option \n"
@ -118,8 +138,6 @@ struct MSG_DesktopApp: App {
@NSApplicationDelegateAdaptor(AppDelegate.self) var appDelegate @NSApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
var body: some Scene { var body: some Scene {
WindowGroup { Settings {} // prevents crash on some macOS version
ContentView()
}
} }
} }

View file

@ -1,4 +1,4 @@
[[./example-gifs/init-example.gif]] [[./doc/images/init-example.gif]]
* Install from tap * Install from tap
** Add Tap ** Add Tap
@ -10,3 +10,11 @@ brew tap MSG/apps https://forge.superkamiguru.org/MSG/homebrew-apps
#+begin_src sh #+begin_src sh
brew install msg-desktop brew install msg-desktop
#+end_src #+end_src
** Security & Privacy
The first time you run the app, you will need to allow it to run in the Security
& Privacy settings of your Mac. This is because the app is not signed by Apple.
You can do this by going to System Preferences > Security & Privacy > General
and clicking "Open Anyway" next to the message about the app being blocked.
[[./doc/images/macos15.3.2-security.png]]

BIN
doc/.DS_Store vendored Normal file

Binary file not shown.

View file

Before

Width:  |  Height:  |  Size: 4.4 MiB

After

Width:  |  Height:  |  Size: 4.4 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 61 KiB