-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
1,519 additions
and
78 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,29 +1,29 @@ | ||
# Xcode | ||
# macOS specific junk | ||
.DS_Store | ||
._* | ||
|
||
# Xcode specific | ||
xcuserdata/ | ||
*.xcuserstate | ||
|
||
# allow VSCode config files | ||
# (allow VSCode config files) | ||
#.vscode | ||
|
||
# VSCode builds here | ||
# VSCode build files | ||
build/ | ||
|
||
# macOS | ||
.DS_Store | ||
._* | ||
|
||
# Swift/Objective-C specific | ||
*.hmap | ||
*.ipa | ||
*.dSYM.zip | ||
*.dSYM | ||
|
||
# Playgrounds | ||
# Playgrounds specific | ||
timeline.xctimeline | ||
playground.xcworkspace | ||
|
||
# Swift Package Manager | ||
.build/ | ||
|
||
# Xcode Derived Data | ||
DerivedData/ | ||
|
||
# Swift Package Manager specific | ||
.build/ |
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,5 @@ | ||
# swiftlint can be installed by running `brew install swiftlint` | ||
|
||
disabled_rules: | ||
# Yes, TODOs etc. should be dealt with eventually. Don't complain about them for now though. | ||
- todo |
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 |
---|---|---|
@@ -1,12 +1,17 @@ | ||
{ | ||
"cSpell.ignoreWords": [ | ||
"nextonly", | ||
"Asahi", | ||
"NVRAM", | ||
"asahi", | ||
"nextonly", | ||
"NVRAM", | ||
"bootable", | ||
"diskutil", | ||
"prefs", | ||
"xcodeproj" | ||
] | ||
"xcodeproj", | ||
"beachball", | ||
"Localizable", | ||
], | ||
// NOTE: Looks like vscode / "Format document" would like to default to 2 spaces (?!) | ||
// TODO: pick the most sane default (4, hopefully) & pick and set up automatic Swift formatter | ||
"editor.tabSize": 4, | ||
} |
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 was deleted.
Oops, something went wrong.
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,66 @@ | ||
// SPDX-License-Identifier: MIT | ||
// AppDelegate.swift | ||
|
||
import Cocoa | ||
import SwiftUI | ||
|
||
class AppDelegate: NSObject, NSApplicationDelegate, NSPopoverDelegate, ObservableObject { | ||
// Fallback values for popover widths, in case fetching from Localizable.strings fails (wide, to fit "anything") | ||
static let fallbackRestartConfirmationPopoverWidth = 500 | ||
static let fallbackStartupDiskConfirmationPopoverWidth = 500 | ||
static let fallbackPreferencesPopoverWidth = 500 | ||
static let fallbackHelpPopoverWidth = 500 | ||
|
||
// Use a popover i.e. "menubar icon speech bubble" instead of dialogs / windows | ||
var popover: NSPopover = NSPopover() | ||
|
||
// hostingController is used for bridging SwiftUI views into AppKit's NSPopover | ||
var hostingController: NSHostingController<ContentView>? | ||
lazy var statusItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.squareLength) | ||
@Published var currentView: CurrentView = .restartConfirmation(1) | ||
var menuItemToView: [NSMenuItem: MenuItem] = [:] | ||
|
||
// TODO: refactor this into a separate class (or at least a separate file)? | ||
// FIXME: UI demo only (code is stupid and ugly, will fix later) | ||
func setStartupDiskForNextBootOnlyAndRestart() { | ||
// Synchronous: if mouse cursor on icon, it will beachball until password dialog dismissed (intended behavior) | ||
// TODO: can this line be removed? (wasn't it closed earlier?) | ||
self.closePopover(nil) | ||
|
||
// TODO: hardcoded for now etc, fix later... | ||
let script = """ | ||
do shell script "bless --mount \\"/Volumes/FedoraLinux\\" --setBoot --nextonly" with administrator privileges | ||
""" | ||
let appleScript = NSAppleScript(source: script) | ||
|
||
var error: NSDictionary? | ||
if appleScript?.executeAndReturnError(&error) == nil { | ||
// TODO: implement better error handling | ||
// If user canceled, do nothing and return | ||
if let error = error, (error[NSAppleScript.errorNumber] as? Int) == -128 { | ||
// Try to close the popover just in case it wasn't already successfully closed earlier | ||
DispatchQueue.main.async { | ||
self.closePopover(nil) | ||
} | ||
return | ||
} | ||
// TODO: implement the real popover UI for this error message | ||
// Display an error dialog (show full error message from sudo bless) | ||
let alert = NSAlert() | ||
alert.messageText = "Error" | ||
if let errorMessage = error?[NSAppleScript.errorMessage] as? String { | ||
alert.informativeText = errorMessage | ||
} else { | ||
alert.informativeText = "Unknown error" | ||
} | ||
alert.alertStyle = .warning | ||
alert.runModal() | ||
return | ||
} else { | ||
// DEBUG: Fake restart (dialog only, no actual restart) | ||
NSAppleScript(source: "display dialog \"Fake restart\"")?.executeAndReturnError(nil) | ||
// Perform the actual restart | ||
// NSAppleScript(source: "tell application \"System Events\" to restart")?.executeAndReturnError(nil) | ||
} | ||
} | ||
} |
Oops, something went wrong.