Skip to content

Commit 683fdab

Browse files
authored
Merge pull request #3 from Shakshi3104/fixes
Fix the issue of cutting off edges on > 8 cores Mac
2 parents 751c38d + a249ec1 commit 683fdab

File tree

4 files changed

+92
-4
lines changed

4 files changed

+92
-4
lines changed

Gaufre.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
CE42C03027535B8C00FC7ECF /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE42C02F27535B8C00FC7ECF /* AppDelegate.swift */; };
1111
CE42C03427535B8E00FC7ECF /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = CE42C03327535B8E00FC7ECF /* Assets.xcassets */; };
1212
CE42C03727535B8E00FC7ECF /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = CE42C03527535B8E00FC7ECF /* Main.storyboard */; };
13+
CE99077C279D12B60085608B /* DebugWafersView.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE99077B279D12B60085608B /* DebugWafersView.swift */; };
1314
CEB1351F278A69F9002318CA /* CoreWafer in Frameworks */ = {isa = PBXBuildFile; productRef = CEB1351E278A69F9002318CA /* CoreWafer */; };
1415
/* End PBXBuildFile section */
1516

@@ -21,6 +22,7 @@
2122
CE42C03827535B8E00FC7ECF /* Gaufre.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Gaufre.entitlements; sourceTree = "<group>"; };
2223
CE42C03E27535C5D00FC7ECF /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; };
2324
CE42C05727537E9400FC7ECF /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
25+
CE99077B279D12B60085608B /* DebugWafersView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DebugWafersView.swift; sourceTree = "<group>"; };
2426
CECC6F152754679B0001E388 /* gaufre.gif */ = {isa = PBXFileReference; lastKnownFileType = image.gif; path = gaufre.gif; sourceTree = "<group>"; };
2527
CECC6F1727546A090001E388 /* gaufre-icon.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "gaufre-icon.png"; sourceTree = "<group>"; };
2628
/* End PBXFileReference section */
@@ -63,6 +65,7 @@
6365
CE42C03327535B8E00FC7ECF /* Assets.xcassets */,
6466
CE42C03527535B8E00FC7ECF /* Main.storyboard */,
6567
CE42C03827535B8E00FC7ECF /* Gaufre.entitlements */,
68+
CE99077B279D12B60085608B /* DebugWafersView.swift */,
6669
);
6770
path = Gaufre;
6871
sourceTree = "<group>";
@@ -152,6 +155,7 @@
152155
isa = PBXSourcesBuildPhase;
153156
buildActionMask = 2147483647;
154157
files = (
158+
CE99077C279D12B60085608B /* DebugWafersView.swift in Sources */,
155159
CE42C03027535B8C00FC7ECF /* AppDelegate.swift in Sources */,
156160
);
157161
runOnlyForDeploymentPostprocessing = 0;

Gaufre.xcodeproj/xcuserdata/user.xcuserdatad/xcschemes/xcschememanagement.plist

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
<key>orderHint</key>
1010
<integer>0</integer>
1111
</dict>
12+
<key>debug.xcscheme_^#shared#^_</key>
13+
<dict>
14+
<key>orderHint</key>
15+
<integer>1</integer>
16+
</dict>
1217
</dict>
1318
<key>SuppressBuildableAutocreation</key>
1419
<dict>

Gaufre/AppDelegate.swift

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import Cocoa
99
import SwiftUI
1010
import CoreWafer
11+
import DeviceHardware
1112

1213
@main
1314
class AppDelegate: NSObject, NSApplicationDelegate {
@@ -42,12 +43,25 @@ class AppDelegate: NSObject, NSApplicationDelegate {
4243
statusBarButton.target = self
4344
}
4445

45-
// Each core load view
46-
let waftersView = NSHostingView(rootView: WafersView(processor: processor) .scaleEffect(0.55))
47-
waftersView.frame = NSRect(x: 0, y: 0, width: 200, height: 100)
46+
// Each core load view
47+
let wafersView: NSView
48+
let coreCount: Int
49+
50+
#if DEBUG
51+
coreCount = 56
52+
wafersView = NSHostingView(rootView: DebugWafersView(coreCount: coreCount) .scaleEffect(0.55))
53+
#else
54+
coreCount = MacDeviceHardware.deviceHardware.processorCount
55+
wafersView = NSHostingView(rootView: WafersView(processor: processor) .scaleEffect(0.55))
56+
#endif
57+
58+
let width = coreCount < 30 ? 20 * coreCount + 40 : 20 * coreCount / 2 + 40
59+
let height = coreCount < 30 ? 100 : 160
60+
61+
wafersView.frame = NSRect(x: 0, y: 0, width: width, height: height)
4862

4963
let coreInfoItem = NSMenuItem()
50-
coreInfoItem.view = waftersView
64+
coreInfoItem.view = wafersView
5165

5266
// main menu
5367
let mainMenu = NSMenu()

Gaufre/DebugWafersView.swift

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
//
2+
// DebugProcessorObserver.swift
3+
// Gaufre
4+
//
5+
// Created by MacBook Pro M1 on 2022/01/23.
6+
//
7+
8+
import SwiftUI
9+
10+
#if DEBUG
11+
struct DebugWafersView: View {
12+
var coreCount: Int
13+
14+
var body: some View {
15+
if coreCount < 30 {
16+
HStack(alignment: .bottom) {
17+
ForEach(0..<coreCount) { _ in
18+
let coreUsage = Double.random(in: 0.0...99.9)
19+
20+
BarView(value: coreUsage)
21+
}
22+
}
23+
.padding(20)
24+
} else {
25+
VStack {
26+
HStack(alignment: .bottom) {
27+
ForEach(0..<coreCount / 2) { _ in
28+
let coreUsage = Double.random(in: 0.0...99.9)
29+
30+
BarView(value: coreUsage)
31+
}
32+
}
33+
34+
HStack(alignment: .bottom) {
35+
ForEach(coreCount / 2 ..< coreCount) { _ in
36+
let coreUsage = Double.random(in: 0.0...99.9)
37+
38+
BarView(value: coreUsage)
39+
}
40+
}
41+
}
42+
.padding(20)
43+
}
44+
}
45+
}
46+
47+
struct BarView: View {
48+
var value: CGFloat
49+
var maxValue: CGFloat = 120
50+
var color = Color(.sRGB, red: 0.2, green: 0.5, blue: 0.8)
51+
52+
var body: some View {
53+
VStack {
54+
ZStack(alignment: .bottom) {
55+
RoundedRectangle(cornerRadius: 5)
56+
.frame(width: 30, height: maxValue)
57+
.foregroundColor(.secondary.opacity(0.2))
58+
RoundedRectangle(cornerRadius: 5)
59+
.frame(width: 30, height: value)
60+
.foregroundColor(color)
61+
}
62+
}
63+
}
64+
}
65+
#endif

0 commit comments

Comments
 (0)