Skip to content

feat: add menubar tray #9

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

Merged
merged 3 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 5 additions & 0 deletions Coder Desktop/.swiftlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
disabled_rules:
- todo
- trailing_comma
type_name:
allowed_symbols: "_"
78 changes: 78 additions & 0 deletions Coder Desktop/Coder Desktop.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
/* Begin PBXBuildFile section */
961679332CFF117300B2B6DF /* NetworkExtension.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 961679322CFF117300B2B6DF /* NetworkExtension.framework */; };
9616793D2CFF117300B2B6DF /* com.coder.Coder-Desktop.VPN.systemextension in Embed System Extensions */ = {isa = PBXBuildFile; fileRef = 961679302CFF117300B2B6DF /* com.coder.Coder-Desktop.VPN.systemextension */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
AA8BC3392D0060A900E1ABAA /* ViewInspector in Frameworks */ = {isa = PBXBuildFile; productRef = AA8BC3382D0060A900E1ABAA /* ViewInspector */; };
AA8BC33F2D0061F200E1ABAA /* FluidMenuBarExtra in Frameworks */ = {isa = PBXBuildFile; productRef = AA8BC33E2D0061F200E1ABAA /* FluidMenuBarExtra */; };
AA8BC4CF2D00A4B700E1ABAA /* KeychainAccess in Frameworks */ = {isa = PBXBuildFile; productRef = AA8BC4CE2D00A4B700E1ABAA /* KeychainAccess */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -98,13 +101,16 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
AA8BC4CF2D00A4B700E1ABAA /* KeychainAccess in Frameworks */,
AA8BC33F2D0061F200E1ABAA /* FluidMenuBarExtra in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
9616790C2CFF100E00B2B6DF /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
AA8BC3392D0060A900E1ABAA /* ViewInspector in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -172,13 +178,16 @@
buildRules = (
);
dependencies = (
AA8BC33C2D0060E700E1ABAA /* PBXTargetDependency */,
9616793C2CFF117300B2B6DF /* PBXTargetDependency */,
);
fileSystemSynchronizedGroups = (
961678FE2CFF100D00B2B6DF /* Coder Desktop */,
);
name = "Coder Desktop";
packageProductDependencies = (
AA8BC33E2D0061F200E1ABAA /* FluidMenuBarExtra */,
AA8BC4CE2D00A4B700E1ABAA /* KeychainAccess */,
);
productName = "Coder Desktop";
productReference = 961678FC2CFF100D00B2B6DF /* Coder Desktop.app */;
Expand All @@ -202,6 +211,7 @@
);
name = "Coder DesktopTests";
packageProductDependencies = (
AA8BC3382D0060A900E1ABAA /* ViewInspector */,
);
productName = "Coder DesktopTests";
productReference = 9616790F2CFF100E00B2B6DF /* Coder DesktopTests.xctest */;
Expand Down Expand Up @@ -287,6 +297,12 @@
);
mainGroup = 961678F32CFF100D00B2B6DF;
minimizedProjectReferenceProxies = 1;
packageReferences = (
AA8BC3372D00609700E1ABAA /* XCRemoteSwiftPackageReference "ViewInspector" */,
AA8BC33A2D0060C500E1ABAA /* XCRemoteSwiftPackageReference "SwiftLintPlugins" */,
AA8BC33D2D0061F200E1ABAA /* XCRemoteSwiftPackageReference "fluid-menu-bar-extra" */,
AA8BC4CD2D00A4B700E1ABAA /* XCRemoteSwiftPackageReference "KeychainAccess" */,
);
preferredProjectObjectVersion = 77;
productRefGroup = 961678FD2CFF100D00B2B6DF /* Products */;
projectDirPath = "";
Expand Down Expand Up @@ -378,6 +394,10 @@
target = 9616792F2CFF117300B2B6DF /* VPN */;
targetProxy = 9616793B2CFF117300B2B6DF /* PBXContainerItemProxy */;
};
AA8BC33C2D0060E700E1ABAA /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
productRef = AA8BC33B2D0060E700E1ABAA /* SwiftLintBuildToolPlugin */;
};
/* End PBXTargetDependency section */

/* Begin XCBuildConfiguration section */
Expand Down Expand Up @@ -724,6 +744,64 @@
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */

/* Begin XCRemoteSwiftPackageReference section */
AA8BC3372D00609700E1ABAA /* XCRemoteSwiftPackageReference "ViewInspector" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/nalexn/ViewInspector";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 0.10.0;
};
};
AA8BC33A2D0060C500E1ABAA /* XCRemoteSwiftPackageReference "SwiftLintPlugins" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/SimplyDanny/SwiftLintPlugins";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 0.57.1;
};
};
AA8BC33D2D0061F200E1ABAA /* XCRemoteSwiftPackageReference "fluid-menu-bar-extra" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/lfroms/fluid-menu-bar-extra";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 1.1.0;
};
};
AA8BC4CD2D00A4B700E1ABAA /* XCRemoteSwiftPackageReference "KeychainAccess" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/kishikawakatsumi/KeychainAccess";
requirement = {
branch = e0c7eebc5a4465a3c4680764f26b7a61f567cdaf;
kind = branch;
};
};
/* End XCRemoteSwiftPackageReference section */

/* Begin XCSwiftPackageProductDependency section */
AA8BC3382D0060A900E1ABAA /* ViewInspector */ = {
isa = XCSwiftPackageProductDependency;
package = AA8BC3372D00609700E1ABAA /* XCRemoteSwiftPackageReference "ViewInspector" */;
productName = ViewInspector;
};
AA8BC33B2D0060E700E1ABAA /* SwiftLintBuildToolPlugin */ = {
isa = XCSwiftPackageProductDependency;
package = AA8BC33A2D0060C500E1ABAA /* XCRemoteSwiftPackageReference "SwiftLintPlugins" */;
productName = "plugin:SwiftLintBuildToolPlugin";
};
AA8BC33E2D0061F200E1ABAA /* FluidMenuBarExtra */ = {
isa = XCSwiftPackageProductDependency;
package = AA8BC33D2D0061F200E1ABAA /* XCRemoteSwiftPackageReference "fluid-menu-bar-extra" */;
productName = FluidMenuBarExtra;
};
AA8BC4CE2D00A4B700E1ABAA /* KeychainAccess */ = {
isa = XCSwiftPackageProductDependency;
package = AA8BC4CD2D00A4B700E1ABAA /* XCRemoteSwiftPackageReference "KeychainAccess" */;
productName = KeychainAccess;
};
/* End XCSwiftPackageProductDependency section */
};
rootObject = 961678F42CFF100D00B2B6DF /* Project object */;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"originHash" : "726475d6c2c0355de7a4de72708853eaf53eb295e791efe2cc4b8eb5ce4e9ae8",
"pins" : [
{
"identity" : "fluid-menu-bar-extra",
Copy link
Member Author

@ethanndickson ethanndickson Dec 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a drop-in replacement for SwiftUI MenuBarExtra, since the original kinda just sucks and doesn't handle resizing very well. It's used by https://github.com/Shopify/tophat, and is designed so that if MenuBarExtra ever improves, you can just swap back.

"kind" : "remoteSourceControl",
"location" : "https://github.com/lfroms/fluid-menu-bar-extra",
"state" : {
"revision" : "e152a3a1a25aca24906217f8d4d63afbb08d7f97",
"version" : "1.1.0"
}
},
{
"identity" : "keychainaccess",
"kind" : "remoteSourceControl",
"location" : "https://github.com/kishikawakatsumi/KeychainAccess",
"state" : {
"revision" : "e0c7eebc5a4465a3c4680764f26b7a61f567cdaf"
}
},
{
"identity" : "swiftlintplugins",
"kind" : "remoteSourceControl",
"location" : "https://github.com/SimplyDanny/SwiftLintPlugins",
"state" : {
"revision" : "f9731bef175c3eea3a0ca960f1be78fcc2bc7853",
"version" : "0.57.1"
}
},
{
"identity" : "viewinspector",
"kind" : "remoteSourceControl",
"location" : "https://github.com/nalexn/ViewInspector",
"state" : {
"revision" : "5acfa0a3c095ac9ad050abe51c60d1831e8321da",
"version" : "0.10.0"
}
}
],
"version" : 3
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"images" : [
{
"filename" : "coder_icon_16.png",
"idiom" : "mac",
"scale" : "1x"
},
{
"filename" : "coder_icon_32.png",
"idiom" : "mac",
"scale" : "2x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 21 additions & 16 deletions Coder Desktop/Coder Desktop/Coder_DesktopApp.swift
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
import SwiftUI
import SwiftData
import FluidMenuBarExtra

@main
struct Coder_DesktopApp: App {
var sharedModelContainer: ModelContainer = {
let schema = Schema([
Item.self,
])
let modelConfiguration = ModelConfiguration(schema: schema, isStoredInMemoryOnly: false)
struct DesktopApp: App {
@NSApplicationDelegateAdaptor private var appDelegate: AppDelegate
@State private var hidden: Bool = false

do {
return try ModelContainer(for: schema, configurations: [modelConfiguration])
} catch {
fatalError("Could not create ModelContainer: \(error)")
var body: some Scene {
MenuBarExtra("", isInserted: $hidden) {
EmptyView()
}
}()
}
}

var body: some Scene {
WindowGroup {
ContentView()
class AppDelegate: NSObject, NSApplicationDelegate {
private var menuBarExtra: FluidMenuBarExtra?
// TODO: Replace with real implementations
private var vpn = PreviewVPN()
private var session = PreviewSession()

func applicationDidFinishLaunching(_ notification: Notification) {
self.menuBarExtra = FluidMenuBarExtra(title: "Coder Desktop", image: "MenuBarIcon") {
VPNMenu(
vpn: self.vpn,
session: self.session
).frame(width: 256)
}
.modelContainer(sharedModelContainer)
}
}
52 changes: 0 additions & 52 deletions Coder Desktop/Coder Desktop/ContentView.swift

This file was deleted.

11 changes: 0 additions & 11 deletions Coder Desktop/Coder Desktop/Item.swift

This file was deleted.

25 changes: 25 additions & 0 deletions Coder Desktop/Coder Desktop/Preview Content/PreviewSession.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import SwiftUI

class PreviewSession: Session {
@Published var hasSession: Bool
@Published var sessionToken: String?
@Published var baseAccessURL: URL?

init() {
hasSession = false
sessionToken = nil
baseAccessURL = nil
}

func login(baseAccessURL: URL, sessionToken: String) {
hasSession = true
self.baseAccessURL = baseAccessURL
self.sessionToken = sessionToken
}

func logout() {
hasSession = false
self.baseAccessURL = nil
self.sessionToken = nil
}
}
Loading