Skip to content

Commit 32be15a

Browse files
authored
Merge pull request #171 from 3colorr/v1.3.1
V1.3.1
2 parents 11d9aed + f53fa85 commit 32be15a

18 files changed

+673
-258
lines changed

Mizuame.xcodeproj/project.pbxproj

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
41790C7D2A1F8D48002D746A /* TabGeneral.swift in Sources */ = {isa = PBXBuildFile; fileRef = 41790C7C2A1F8D48002D746A /* TabGeneral.swift */; };
3535
41790C812A1F92CA002D746A /* TabHelp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 41790C802A1F92CA002D746A /* TabHelp.swift */; };
3636
41790C852A1F92F4002D746A /* TabInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 41790C842A1F92F4002D746A /* TabInfo.swift */; };
37+
41884DB72D2433BF004C8AE2 /* ChooseFontSizeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 41884DB62D2433BF004C8AE2 /* ChooseFontSizeView.swift */; };
3738
418A6C632A07E105009C46CD /* MizuameApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 418A6C622A07E105009C46CD /* MizuameApp.swift */; };
3839
418A6C652A07E105009C46CD /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 418A6C642A07E105009C46CD /* ContentView.swift */; };
3940
418A6C672A07E105009C46CD /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 418A6C662A07E105009C46CD /* Assets.xcassets */; };
@@ -92,6 +93,7 @@
9293
41790C7C2A1F8D48002D746A /* TabGeneral.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabGeneral.swift; sourceTree = "<group>"; };
9394
41790C802A1F92CA002D746A /* TabHelp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabHelp.swift; sourceTree = "<group>"; };
9495
41790C842A1F92F4002D746A /* TabInfo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabInfo.swift; sourceTree = "<group>"; };
96+
41884DB62D2433BF004C8AE2 /* ChooseFontSizeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChooseFontSizeView.swift; sourceTree = "<group>"; };
9597
418A6C5F2A07E105009C46CD /* Mizuame.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Mizuame.app; sourceTree = BUILT_PRODUCTS_DIR; };
9698
418A6C622A07E105009C46CD /* MizuameApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MizuameApp.swift; sourceTree = "<group>"; };
9799
418A6C642A07E105009C46CD /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
@@ -170,6 +172,7 @@
170172
41BD1EB82A277A1200C97A2E /* StickyNotePreview.swift */,
171173
41AFAD812A30B05400D01A37 /* ThemePalette.swift */,
172174
41F18E8A2C96BEA300374767 /* SupportMarkdownSyntax.swift */,
175+
41884DB62D2433BF004C8AE2 /* ChooseFontSizeView.swift */,
173176
);
174177
path = Settings;
175178
sourceTree = "<group>";
@@ -382,6 +385,7 @@
382385
41790C852A1F92F4002D746A /* TabInfo.swift in Sources */,
383386
41C01B702A0D25B500B55670 /* SettingsView.swift in Sources */,
384387
41ACD1242A23892B001F111B /* TermsOfServiceView.swift in Sources */,
388+
41884DB72D2433BF004C8AE2 /* ChooseFontSizeView.swift in Sources */,
385389
413A95DD2A5A499800E735BF /* TabPrint.swift in Sources */,
386390
41AE86732A21B1E8000068CA /* SettingKeys.swift in Sources */,
387391
41790C812A1F92CA002D746A /* TabHelp.swift in Sources */,
@@ -515,14 +519,15 @@
515519
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
516520
GCC_WARN_UNUSED_FUNCTION = YES;
517521
GCC_WARN_UNUSED_VARIABLE = YES;
518-
INFOPLIST_KEY_NSHumanReadableCopyright = 1.3.0;
522+
INFOPLIST_KEY_NSHumanReadableCopyright = 1.3.1;
519523
MACOSX_DEPLOYMENT_TARGET = 15.0;
520524
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
521525
MTL_FAST_MATH = YES;
522526
ONLY_ACTIVE_ARCH = YES;
523527
SDKROOT = macosx;
524528
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
525529
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
530+
SWIFT_VERSION = 6.0;
526531
};
527532
name = Debug;
528533
};
@@ -574,13 +579,14 @@
574579
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
575580
GCC_WARN_UNUSED_FUNCTION = YES;
576581
GCC_WARN_UNUSED_VARIABLE = YES;
577-
INFOPLIST_KEY_NSHumanReadableCopyright = 1.3.0;
582+
INFOPLIST_KEY_NSHumanReadableCopyright = 1.3.1;
578583
MACOSX_DEPLOYMENT_TARGET = 15.0;
579584
MTL_ENABLE_DEBUG_INFO = NO;
580585
MTL_FAST_MATH = YES;
581586
SDKROOT = macosx;
582587
SWIFT_COMPILATION_MODE = wholemodule;
583588
SWIFT_OPTIMIZATION_LEVEL = "-O";
589+
SWIFT_VERSION = 6.0;
584590
};
585591
name = Release;
586592
};
@@ -593,7 +599,7 @@
593599
CODE_SIGN_ENTITLEMENTS = Mizuame/Mizuame.entitlements;
594600
CODE_SIGN_STYLE = Automatic;
595601
COMBINE_HIDPI_IMAGES = YES;
596-
CURRENT_PROJECT_VERSION = 1.3.0;
602+
CURRENT_PROJECT_VERSION = 1.3.1;
597603
DEAD_CODE_STRIPPING = YES;
598604
DEVELOPMENT_ASSET_PATHS = "\"Mizuame/Preview Content\"";
599605
DEVELOPMENT_TEAM = 4897P87J67;
@@ -609,7 +615,7 @@
609615
"@executable_path/../Frameworks",
610616
);
611617
MACOSX_DEPLOYMENT_TARGET = 13.3;
612-
MARKETING_VERSION = 1.3.0;
618+
MARKETING_VERSION = 1.3.1;
613619
PRODUCT_BUNDLE_IDENTIFIER = com.3colorr.Mizuame;
614620
PRODUCT_NAME = "$(TARGET_NAME)";
615621
SWIFT_EMIT_LOC_STRINGS = YES;
@@ -628,7 +634,7 @@
628634
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
629635
CODE_SIGN_STYLE = Automatic;
630636
COMBINE_HIDPI_IMAGES = YES;
631-
CURRENT_PROJECT_VERSION = 1.3.0;
637+
CURRENT_PROJECT_VERSION = 1.3.1;
632638
DEAD_CODE_STRIPPING = YES;
633639
DEVELOPMENT_ASSET_PATHS = "\"Mizuame/Preview Content\"";
634640
DEVELOPMENT_TEAM = 4897P87J67;
@@ -644,7 +650,7 @@
644650
"@executable_path/../Frameworks",
645651
);
646652
MACOSX_DEPLOYMENT_TARGET = 13.3;
647-
MARKETING_VERSION = 1.3.0;
653+
MARKETING_VERSION = 1.3.1;
648654
PRODUCT_BUNDLE_IDENTIFIER = com.gmail.3colorr.mizuame;
649655
PRODUCT_NAME = "$(TARGET_NAME)";
650656
PROVISIONING_PROFILE_SPECIFIER = "";
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"colors" : [
3+
{
4+
"color" : {
5+
"color-space" : "srgb",
6+
"components" : {
7+
"alpha" : "1.000",
8+
"blue" : "0.900",
9+
"green" : "0.900",
10+
"red" : "0.900"
11+
}
12+
},
13+
"idiom" : "universal"
14+
},
15+
{
16+
"appearances" : [
17+
{
18+
"appearance" : "luminosity",
19+
"value" : "dark"
20+
}
21+
],
22+
"color" : {
23+
"color-space" : "srgb",
24+
"components" : {
25+
"alpha" : "1.000",
26+
"blue" : "0.320",
27+
"green" : "0.320",
28+
"red" : "0.320"
29+
}
30+
},
31+
"idiom" : "universal"
32+
}
33+
],
34+
"info" : {
35+
"author" : "xcode",
36+
"version" : 1
37+
}
38+
}

Mizuame/ContentView.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ struct ContentView: View {
111111

112112
var body: some View {
113113
switch viewState {
114+
case SettingsViewState.CHOOSE_FONTSIZE.rawValue:
115+
ChooseFontSizeView(state: $viewState)
116+
114117
case SettingsViewState.TERMS_OF_SERVICE.rawValue:
115118
TermsOfServiceView(state: $viewState)
116119

@@ -450,7 +453,8 @@ struct ContentView: View {
450453
text: stickyText,
451454
fontSize: fontSize,
452455
codeBlockTheme: markdownCodeBlockTheme,
453-
formulaBlockTheme: markdownFormulaBlockTheme)
456+
formulaBlockTheme: markdownFormulaBlockTheme,
457+
lineSpacing: CGFloat(self.lineSpacing))
454458
.multilineTextAlignment(.leading)
455459
.textSelection(.enabled)
456460
.padding(EdgeInsets(top: 5, leading: 5, bottom: 0, trailing: 5))

Mizuame/MarkdownStyling.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ extension View {
1818
/// - formulaBlockTheme: The background color to apply to formula blocks.
1919
/// - Returns: A View with applied styles.
2020
///
21-
func convertMarkdownTextToView(text: String, fontSize: Int, codeBlockTheme: String, formulaBlockTheme: String) -> some View {
21+
func convertMarkdownTextToView(text: String, fontSize: Int, codeBlockTheme: String, formulaBlockTheme: String, lineSpacing: CGFloat) -> some View {
2222

2323
let initialFontSize = CGFloat(SettingKeys.FontSize().initialValue)
2424
let markdownModels: [MarkdownModel] = text.toMarkdown(size: fontSize)
2525

26-
return VStack(alignment: .leading) {
26+
return VStack(alignment: .leading, spacing: lineSpacing) {
2727
ForEach(markdownModels) { md in
2828
HStack(spacing: 0) {
2929
ForEach(md.markdownTextViews) { elem in

Mizuame/MizuameApp.swift

Lines changed: 118 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,19 @@ class AppDelegate: NSObject, NSApplicationDelegate, ObservableObject {
2929
@AppStorage(SettingKeys.StickyNote().keyMarkdownAction) private var isEnableMarkdown: Bool = SettingKeys.StickyNote().initialMarkdownAction
3030
@AppStorage(SettingKeys.StickyNote().keyShowMarkdownPreview) private var showMarkdownPreview: Bool = SettingKeys.StickyNote().initialShowMarkdownPreview
3131

32+
@AppStorage(SettingKeys.StickyNote.KeyboardShortcuts().keyKeyboardShortcutAction) private var keyboardShortcutPattern: Int = SettingKeys.StickyNote.KeyboardShortcuts.KeyboardPattern().none
33+
3234
private var statusItem: NSStatusItem?
3335
private var popover: NSPopover = NSPopover()
3436

3537
private var isOpenNote: Bool = true
3638

39+
// For keyboard shortcut
40+
private weak var statusBarButton: NSStatusBarButton?
41+
private var monitor: Any?
42+
private var noteOpenCounter: Int = SettingKeys.StickyNote.KeyboardShortcuts().initialNoteOpenCounter
43+
private var counterResetTask: Task<Void, Never>?
44+
3745
func applicationDidFinishLaunching(_ notification: Notification) {
3846
NSApp.setActivationPolicy(.accessory)
3947

@@ -48,6 +56,8 @@ class AppDelegate: NSObject, NSApplicationDelegate, ObservableObject {
4856
button.image = NSImage(named: "MenubarIcon")
4957
button.action = #selector(showPopover)
5058
button.sendAction(on: [.leftMouseUp, .rightMouseUp])
59+
60+
statusBarButton = button
5161
}
5262

5363
popover.contentViewController = NSHostingController(rootView: ContentView(delegate: self))
@@ -57,66 +67,128 @@ class AppDelegate: NSObject, NSApplicationDelegate, ObservableObject {
5767
} else {
5868
disablePinning()
5969
}
70+
71+
if keyboardShortcutPattern != SettingKeys.StickyNote.KeyboardShortcuts.KeyboardPattern().none {
72+
// Check accessibility permission
73+
let options: [String: Bool] = [kAXTrustedCheckOptionPrompt.takeUnretainedValue() as String: true]
74+
let isTrusted = AXIsProcessTrustedWithOptions(options as CFDictionary)
75+
76+
if isTrusted {
77+
monitor = NSEvent.addGlobalMonitorForEvents(matching: [.flagsChanged]) { event in
78+
self.handleKeyEvent(event)
79+
}
80+
}
81+
}
6082
}
6183

62-
@objc func showPopover(sender: NSStatusBarButton) {
63-
guard let currentEvent = NSApp.currentEvent else {
64-
return
65-
}
66-
67-
guard let unwrappedStatusItem = statusItem else {
68-
return
84+
func applicationWillTerminate(_ aNotification: Notification) {
85+
// Remove a handle key event.
86+
if let monitor = monitor {
87+
NSEvent.removeMonitor(monitor)
6988
}
70-
71-
if currentEvent.type == NSEvent.EventType.rightMouseUp {
89+
}
7290

73-
let menu = NSMenu()
74-
75-
menu.addItem(
76-
withTitle: NSLocalizedString("menubar.clickevent.right.menu.item.quit", comment: ""),
77-
action: #selector(quitApp),
78-
keyEquivalent: ""
79-
)
80-
81-
unwrappedStatusItem.menu = menu
82-
unwrappedStatusItem.button?.performClick(nil)
83-
unwrappedStatusItem.menu = nil
84-
85-
} else if currentEvent.type == NSEvent.EventType.leftMouseUp {
91+
private func handleKeyEvent(_ event: NSEvent) {
92+
93+
/**
94+
* ## How do keyboard shortcuts for opening the note work?
95+
*
96+
* When the user types the keyboard shortcut key three times within a very short time, the note will open.
97+
* Each time the user types the shortcut key, the note open counter is decremented.
98+
* If any key other than the shortcut key is pressed, or if the user does not press the shortcut key consecutively within a very short time,
99+
* the note open counter is reset to the initial value.
100+
*
101+
* Additionally, since func handleKeyEvent is called both when a key is pressed and when it is released,
102+
* the initial value of the note open counter must be set to twice the number of times you want the user to press the shortcut key.
103+
*
104+
*/
105+
if (event.keyCode == keyboardShortcutPattern) {
106+
noteOpenCounter -= 1;
107+
108+
if noteOpenCounter <= 0
109+
{
110+
if let button = statusBarButton {
111+
showPopover(sender: button, isGlobalHotKey: true)
112+
}
113+
}
114+
115+
counterResetTask?.cancel()
86116

87-
if isPinNote {
88-
89-
isOpenNote.toggle()
90-
91-
if isOpenNote {
117+
counterResetTask = Task {
118+
do {
119+
try Task.checkCancellation()
120+
try await Task.sleep(nanoseconds: 3 * 100_000_000)
121+
noteOpenCounter = SettingKeys.StickyNote.KeyboardShortcuts().initialNoteOpenCounter
122+
123+
} catch {
124+
if Task.isCancelled {
125+
print("Task is Canceled")
126+
} else {
127+
print("Unexcepted error")
128+
}
129+
}
130+
}
131+
}
132+
else
133+
{
134+
noteOpenCounter = SettingKeys.StickyNote.KeyboardShortcuts().initialNoteOpenCounter
135+
}
136+
}
137+
138+
@objc func showPopover(sender: NSStatusBarButton, isGlobalHotKey: Bool = false) {
139+
140+
if let currentEvent = NSApp.currentEvent, let unwrappedStatusItem = statusItem {
141+
142+
if currentEvent.type == NSEvent.EventType.rightMouseUp {
143+
144+
let menu = NSMenu()
145+
146+
menu.addItem(
147+
withTitle: NSLocalizedString("menubar.clickevent.right.menu.item.quit", comment: ""),
148+
action: #selector(quitApp),
149+
keyEquivalent: ""
150+
)
151+
152+
unwrappedStatusItem.menu = menu
153+
unwrappedStatusItem.button?.performClick(nil)
154+
unwrappedStatusItem.menu = nil
155+
156+
} else if currentEvent.type == NSEvent.EventType.leftMouseUp || isGlobalHotKey == true {
157+
158+
if isPinNote {
159+
160+
isOpenNote.toggle()
161+
162+
if isOpenNote {
163+
popover.show(relativeTo: sender.bounds, of: sender, preferredEdge: NSRectEdge.maxY)
164+
165+
// When the user enables "Markdown preview (turn on 'isEnableMarkdown')",
166+
// "showMarkdownPreview" will be TRUE every time the user opens a note to the Markdown preview.
167+
if isEnableMarkdown {
168+
showMarkdownPreview = true
169+
}
170+
171+
} else {
172+
popover.close()
173+
}
174+
} else {
92175
popover.show(relativeTo: sender.bounds, of: sender, preferredEdge: NSRectEdge.maxY)
93176

177+
// Initialize "isOpenNote" when "pin a note" is enable next time.
178+
isOpenNote = false
179+
94180
// When the user enables "Markdown preview (turn on 'isEnableMarkdown')",
95181
// "showMarkdownPreview" will be TRUE every time the user opens a note to the Markdown preview.
96182
if isEnableMarkdown {
97183
showMarkdownPreview = true
98184
}
99-
100-
} else {
101-
popover.close()
102-
}
103-
} else {
104-
popover.show(relativeTo: sender.bounds, of: sender, preferredEdge: NSRectEdge.maxY)
105-
106-
// Initialize "isOpenNote" when "pin a note" is enable next time.
107-
isOpenNote = false
108-
109-
// When the user enables "Markdown preview (turn on 'isEnableMarkdown')",
110-
// "showMarkdownPreview" will be TRUE every time the user opens a note to the Markdown preview.
111-
if isEnableMarkdown {
112-
showMarkdownPreview = true
113185
}
114-
}
115186

116-
popover.contentViewController?.view.window?.makeKey()
117-
118-
if #available(macOS 14, *) {
119-
NSApp.activate(ignoringOtherApps: true)
187+
popover.contentViewController?.view.window?.makeKey()
188+
189+
if #available(macOS 14, *) {
190+
NSApp.activate(ignoringOtherApps: true)
191+
}
120192
}
121193
}
122194
}

0 commit comments

Comments
 (0)