Skip to content

Commit 090a2d3

Browse files
authored
Merge pull request #17 from mtj0928/update-macOS-template
update macOS template
2 parents c70f1d7 + 5461770 commit 090a2d3

File tree

3 files changed

+66
-40
lines changed

3 files changed

+66
-40
lines changed

SlideKitDemo-macOS/SlideKitDemo-macOS.xcodeproj/project.pbxproj

+4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
04E2C08728B9155E0076F292 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 04E2C08628B9155E0076F292 /* Preview Assets.xcassets */; };
1313
04E2C09028B915A60076F292 /* SlideKit in Frameworks */ = {isa = PBXBuildFile; productRef = 04E2C08F28B915A60076F292 /* SlideKit */; };
1414
04E2C09328B9AA820076F292 /* BasicSlide.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04E2C09228B9AA820076F292 /* BasicSlide.swift */; };
15+
183D674328DBDE230097167F /* SlideConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 183D674228DBDE230097167F /* SlideConfiguration.swift */; };
1516
18D33A2D28D54D250095156B /* CustomHeaderStyleSlide.swift in Sources */ = {isa = PBXBuildFile; fileRef = 18D33A2C28D54D250095156B /* CustomHeaderStyleSlide.swift */; };
1617
/* End PBXBuildFile section */
1718

@@ -22,6 +23,7 @@
2223
04E2C08628B9155E0076F292 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = "<group>"; };
2324
04E2C08828B9155E0076F292 /* SlideKitDemo_macOS.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = SlideKitDemo_macOS.entitlements; sourceTree = "<group>"; };
2425
04E2C09228B9AA820076F292 /* BasicSlide.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BasicSlide.swift; sourceTree = "<group>"; };
26+
183D674228DBDE230097167F /* SlideConfiguration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = SlideConfiguration.swift; path = ../../../../../../Desktop/SlideConfiguration.swift; sourceTree = "<group>"; };
2527
18C893BB28BE64B600A8054D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; };
2628
18D33A2C28D54D250095156B /* CustomHeaderStyleSlide.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomHeaderStyleSlide.swift; sourceTree = "<group>"; };
2729
/* End PBXFileReference section */
@@ -60,6 +62,7 @@
6062
children = (
6163
18C893BB28BE64B600A8054D /* Info.plist */,
6264
04E2C07F28B9155D0076F292 /* SlideKitDemo_macOSApp.swift */,
65+
183D674228DBDE230097167F /* SlideConfiguration.swift */,
6366
04E2C09128B9AA770076F292 /* Slides */,
6467
04E2C08328B9155E0076F292 /* Assets.xcassets */,
6568
04E2C08828B9155E0076F292 /* SlideKitDemo_macOS.entitlements */,
@@ -165,6 +168,7 @@
165168
isa = PBXSourcesBuildPhase;
166169
buildActionMask = 2147483647;
167170
files = (
171+
183D674328DBDE230097167F /* SlideConfiguration.swift in Sources */,
168172
18D33A2D28D54D250095156B /* CustomHeaderStyleSlide.swift in Sources */,
169173
04E2C09328B9AA820076F292 /* BasicSlide.swift in Sources */,
170174
04E2C08028B9155D0076F292 /* SlideKitDemo_macOSApp.swift in Sources */,

SlideKitDemo-macOS/SlideKitDemo-macOS/SlideKitDemo_macOSApp.swift

+17-40
Original file line numberDiff line numberDiff line change
@@ -11,55 +11,32 @@ import SlideKit
1111
@main
1212
struct SlideKitDemo_macOSApp: App {
1313

14-
/// Please edit the default value to the size you want
15-
let slideSize = SlideSize.standard16_9
16-
17-
/// Please add your slide into the trailing closure
18-
let slideIndexController = SlideIndexController {
19-
BasicSlide()
20-
CustomHeaderStyleSlide()
14+
/// Edit slide configurations in SlideConfiguration.swift
15+
private static let configuration = SlideConfiguration()
16+
17+
/// A presentation content view.
18+
/// Edit the view if you'd like to set environment, overlay view or background view here.
19+
var presentationContentView: some View {
20+
SlideRouterView(slideIndexController: Self.configuration.slideIndexController)
21+
.background(.white)
2122
}
2223

2324
var body: some Scene {
2425
WindowGroup {
25-
PresentationView(slideSize: slideSize) {
26-
SlideRouterView(slideIndexController: slideIndexController)
27-
.background(.white)
28-
}
29-
}
30-
.windowStyle(.hiddenTitleBar)
31-
.commands {
32-
CommandGroup(after: .undoRedo) {
33-
forwardButton(.rightArrow)
34-
forwardButton(.return)
35-
backButton(.leftArrow)
36-
}
37-
38-
CommandGroup(after: .windowList) {
39-
Button("Open Presenter Window") { NSWorkspace.shared.open(URL(string: "slide://editor")!) }
40-
.keyboardShortcut("p", modifiers: .command)
26+
PresentationView(slideSize: Self.configuration.size) {
27+
presentationContentView
4128
}
4229
}
30+
.setupAsPresentationWindow(Self.configuration.slideIndexController, appName: "slide")
4331

4432
WindowGroup {
45-
macOSPresenterView(slideSize: slideSize, slideIndexController: slideIndexController) {
46-
SlideRouterView(slideIndexController: slideIndexController)
47-
.background(.white)
33+
macOSPresenterView(
34+
slideSize: Self.configuration.size,
35+
slideIndexController: Self.configuration.slideIndexController
36+
) {
37+
presentationContentView
4838
}
4939
}
50-
.handlesExternalEvents(matching: ["editor"])
51-
}
52-
}
53-
54-
extension SlideKitDemo_macOSApp {
55-
56-
private func forwardButton(_ key: KeyEquivalent) -> some View {
57-
Button("forward") { slideIndexController.forward() }
58-
.keyboardShortcut(key, modifiers: [])
59-
}
60-
61-
private func backButton(_ key: KeyEquivalent) -> some View {
62-
Button("back") { slideIndexController.back() }
63-
.keyboardShortcut(key, modifiers: [])
40+
.setupAsPresenterWindow()
6441
}
6542
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
//
2+
// Scene+macOS.swift
3+
//
4+
//
5+
// Created by Junnosuke Matsumoto on 2022/09/21.
6+
//
7+
#if os(macOS)
8+
import SwiftUI
9+
10+
extension Scene {
11+
12+
public func setupAsPresentationWindow(
13+
_ slideIndexController: SlideIndexController,
14+
appName: String
15+
) -> some Scene {
16+
windowStyle(.hiddenTitleBar)
17+
.commands {
18+
CommandGroup(after: .undoRedo) {
19+
forwardButton(.rightArrow, slideIndexController: slideIndexController)
20+
forwardButton(.return, slideIndexController: slideIndexController)
21+
backButton(.leftArrow, slideIndexController: slideIndexController)
22+
}
23+
24+
CommandGroup(after: .windowList) {
25+
Button("Open Presenter Window") { NSWorkspace.shared.open(URL(string: "\(appName)://editor")!) }
26+
.keyboardShortcut("p", modifiers: .command)
27+
}
28+
}
29+
}
30+
31+
private func forwardButton(_ key: KeyEquivalent, slideIndexController: SlideIndexController) -> some View {
32+
Button("forward") { slideIndexController.forward() }
33+
.keyboardShortcut(key, modifiers: [])
34+
}
35+
36+
private func backButton(_ key: KeyEquivalent, slideIndexController: SlideIndexController) -> some View {
37+
Button("back") { slideIndexController.back() }
38+
.keyboardShortcut(key, modifiers: [])
39+
}
40+
41+
public func setupAsPresenterWindow() -> some Scene {
42+
handlesExternalEvents(matching: ["editor"])
43+
}
44+
}
45+
#endif

0 commit comments

Comments
 (0)