@hasna/recordings 0.1.4 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +170 -21
- package/package.json +4 -4
- package/src/native/Recordings/Package.resolved +15 -0
- package/src/native/Recordings/Package.swift +21 -0
- package/src/native/Recordings/Recordings/FnKeyMonitor.swift +122 -0
- package/src/native/Recordings/Recordings/Info.plist +22 -0
- package/src/native/Recordings/Recordings/MenuBarPopover.swift +188 -0
- package/src/native/Recordings/Recordings/RecordingEngine.swift +355 -0
- package/src/native/Recordings/Recordings/Recordings.entitlements +12 -0
- package/src/native/Recordings/Recordings/RecordingsApp.swift +30 -0
- package/src/native/Recordings/Recordings/SettingsView.swift +93 -0
- package/src/native/Recordings/Recordings/VoiceShortcuts.swift +82 -0
- package/src/native/Recordings/build.sh +40 -0
- package/src/native/Recordings/test_fn.swift +79 -0
- package/src/native/Recordings/test_fn2.swift +33 -0
- package/src/native/RecordingsHelper.swift +36 -0
package/LICENSE
CHANGED
|
@@ -1,21 +1,170 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship made available under
|
|
36
|
+
the License, as indicated by a copyright notice that is included in
|
|
37
|
+
or attached to the work (an example is provided in the Appendix below).
|
|
38
|
+
|
|
39
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
40
|
+
form, that is based on (or derived from) the Work and for which the
|
|
41
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
42
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
43
|
+
of this License, Derivative Works shall not include works that remain
|
|
44
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
45
|
+
the Work and Derivative Works thereof.
|
|
46
|
+
|
|
47
|
+
"Contribution" shall mean, as submitted to the Licensor for inclusion
|
|
48
|
+
in the Work by the copyright owner or by an individual or Legal Entity
|
|
49
|
+
authorized to submit on behalf of the copyright owner. For the purposes
|
|
50
|
+
of this definition, "submitted" means any form of electronic, verbal,
|
|
51
|
+
or written communication sent to the Licensor or its representatives,
|
|
52
|
+
including but not limited to communication on electronic mailing lists,
|
|
53
|
+
source code control systems, and issue tracking systems that are managed
|
|
54
|
+
by, or on behalf of, the Licensor for the purpose of recording and
|
|
55
|
+
discussing the Work, but excluding communication that is conspicuously
|
|
56
|
+
marked or designated in writing by the copyright owner as "Not a
|
|
57
|
+
Contribution."
|
|
58
|
+
|
|
59
|
+
"Contributor" shall mean Licensor and any Legal Entity on behalf of
|
|
60
|
+
whom a Contribution has been received by the Licensor and included
|
|
61
|
+
within the Work.
|
|
62
|
+
|
|
63
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
64
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
65
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
66
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
67
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
68
|
+
Work and such Derivative Works in Source or Object form.
|
|
69
|
+
|
|
70
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
71
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
72
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
73
|
+
(except as stated in this section) patent license to make, have made,
|
|
74
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
75
|
+
where such license applies only to those patent contributions
|
|
76
|
+
Licensors can make available under this License.
|
|
77
|
+
|
|
78
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
79
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
80
|
+
modifications, and in Source or Object form, provided that You
|
|
81
|
+
meet the following conditions:
|
|
82
|
+
|
|
83
|
+
(a) You must give any other recipients of the Work or Derivative Works
|
|
84
|
+
a copy of this License; and
|
|
85
|
+
|
|
86
|
+
(b) You must cause any modified files to carry prominent notices
|
|
87
|
+
stating that You changed the files; and
|
|
88
|
+
|
|
89
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
90
|
+
that You distribute, all copyright, patent, trademark, and
|
|
91
|
+
attribution notices from the Source form of the Work,
|
|
92
|
+
excluding those notices that do not pertain to any part of
|
|
93
|
+
the Derivative Works; and
|
|
94
|
+
|
|
95
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
96
|
+
distribution, You must include a readable copy of the attribution
|
|
97
|
+
notices contained within such NOTICE file, in at least one
|
|
98
|
+
of the following places: within a NOTICE text file distributed
|
|
99
|
+
as part of the Derivative Works; within the Source form or
|
|
100
|
+
documentation, if provided along with the Derivative Works; or,
|
|
101
|
+
within a display generated by the Derivative Works, if and
|
|
102
|
+
wherever such third-party notices normally appear. The contents
|
|
103
|
+
of the NOTICE file are for informational purposes only and
|
|
104
|
+
do not modify the License. You may add Your own attribution
|
|
105
|
+
notices within Derivative Works that You distribute, alongside
|
|
106
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
107
|
+
that such additional attribution notices cannot be construed
|
|
108
|
+
as modifying the License.
|
|
109
|
+
|
|
110
|
+
You may add Your own license statement for Your modifications and
|
|
111
|
+
may provide additional grant of rights to use, copy, modify, merge,
|
|
112
|
+
publish, distribute, sublicense, and/or sell copies of the Software.
|
|
113
|
+
|
|
114
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
115
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
116
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
117
|
+
this License, without any additional terms or conditions.
|
|
118
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
119
|
+
the terms of any separate license agreement you may have executed
|
|
120
|
+
with Licensor regarding such Contributions.
|
|
121
|
+
|
|
122
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
123
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
124
|
+
except as required for reasonable and customary use in describing the
|
|
125
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
126
|
+
|
|
127
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
128
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
129
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
130
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
131
|
+
implied, including, without limitation, any warranties or conditions
|
|
132
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
133
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
134
|
+
appropriateness of using or redistributing the Work and assume any
|
|
135
|
+
risks associated with Your exercise of permissions under this License.
|
|
136
|
+
|
|
137
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
138
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
139
|
+
unless required by applicable law (such as deliberate and grossly
|
|
140
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
141
|
+
liable to You for damages, including any direct, indirect, special,
|
|
142
|
+
incidental, or exemplary damages of any character arising as a
|
|
143
|
+
result of this License or out of the use or inability to use the
|
|
144
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
145
|
+
work stoppage, computer failure or malfunction, or all other
|
|
146
|
+
commercial damages or losses), even if such Contributor has been
|
|
147
|
+
advised of the possibility of such damages.
|
|
148
|
+
|
|
149
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
150
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
151
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
152
|
+
or other liability obligations and/or rights consistent with this
|
|
153
|
+
License. However, in accepting such obligations, You may offer only
|
|
154
|
+
conditions consistent with this License.
|
|
155
|
+
|
|
156
|
+
END OF TERMS AND CONDITIONS
|
|
157
|
+
|
|
158
|
+
Copyright 2024 hasna.com
|
|
159
|
+
|
|
160
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
161
|
+
you may not use this file except in compliance with the License.
|
|
162
|
+
You may obtain a copy of the License at
|
|
163
|
+
|
|
164
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
165
|
+
|
|
166
|
+
Unless required by applicable law or agreed to in writing, software
|
|
167
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
168
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
169
|
+
See the License for the specific language governing permissions and
|
|
170
|
+
limitations under the License.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hasna/recordings",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Speech-to-text recording tool with MCP and CLI — records, transcribes, and optionally enhances text using AI",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -38,9 +38,9 @@
|
|
|
38
38
|
"typescript": "^5.8.2"
|
|
39
39
|
},
|
|
40
40
|
"publishConfig": {
|
|
41
|
-
"
|
|
42
|
-
"
|
|
41
|
+
"registry": "https://registry.npmjs.org",
|
|
42
|
+
"access": "public"
|
|
43
43
|
},
|
|
44
|
-
"license": "
|
|
44
|
+
"license": "Apache-2.0",
|
|
45
45
|
"author": "Hasna <andrei@hasna.com>"
|
|
46
46
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"originHash" : "a6c896b6f831f2130914352c7417e95b036b1f02a1ff70318f1f4e5aa8966e9b",
|
|
3
|
+
"pins" : [
|
|
4
|
+
{
|
|
5
|
+
"identity" : "keyboardshortcuts",
|
|
6
|
+
"kind" : "remoteSourceControl",
|
|
7
|
+
"location" : "https://github.com/sindresorhus/KeyboardShortcuts",
|
|
8
|
+
"state" : {
|
|
9
|
+
"revision" : "1aef85578fdd4f9eaeeb8d53b7b4fc31bf08fe27",
|
|
10
|
+
"version" : "2.4.0"
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
],
|
|
14
|
+
"version" : 3
|
|
15
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// swift-tools-version: 6.2
|
|
2
|
+
|
|
3
|
+
import PackageDescription
|
|
4
|
+
|
|
5
|
+
let package = Package(
|
|
6
|
+
name: "Recordings",
|
|
7
|
+
platforms: [
|
|
8
|
+
.macOS(.v26)
|
|
9
|
+
],
|
|
10
|
+
dependencies: [
|
|
11
|
+
.package(url: "https://github.com/sindresorhus/KeyboardShortcuts", from: "2.0.0")
|
|
12
|
+
],
|
|
13
|
+
targets: [
|
|
14
|
+
.executableTarget(
|
|
15
|
+
name: "Recordings",
|
|
16
|
+
dependencies: ["KeyboardShortcuts"],
|
|
17
|
+
path: "Recordings",
|
|
18
|
+
exclude: ["Info.plist", "Recordings.entitlements"]
|
|
19
|
+
)
|
|
20
|
+
]
|
|
21
|
+
)
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import Cocoa
|
|
2
|
+
|
|
3
|
+
/// Monitors the fn/Globe key using CGEventTap.
|
|
4
|
+
/// Based on the proven pattern from CustomWispr (open-source WisprFlow alternative).
|
|
5
|
+
/// User must set System Settings > Keyboard > "Press fn key to: Do Nothing" for this to work.
|
|
6
|
+
final class FnKeyMonitor: @unchecked Sendable {
|
|
7
|
+
var onFnKeyDown: (() -> Void)?
|
|
8
|
+
var onFnKeyUp: (() -> Void)?
|
|
9
|
+
|
|
10
|
+
private var eventTap: CFMachPort?
|
|
11
|
+
private var runLoopSource: CFRunLoopSource?
|
|
12
|
+
private var healthCheckTimer: Timer?
|
|
13
|
+
private var fnIsDown = false
|
|
14
|
+
|
|
15
|
+
private static let fnKeyCode: UInt16 = 63
|
|
16
|
+
private static let fnFlagMask: UInt64 = 0x800000
|
|
17
|
+
|
|
18
|
+
/// Start monitoring. Returns true if successful.
|
|
19
|
+
func start() -> Bool {
|
|
20
|
+
guard eventTap == nil else {
|
|
21
|
+
fputs("[FnKeyMonitor] Already running\n", stderr)
|
|
22
|
+
return true
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
fputs("[FnKeyMonitor] Creating event tap...\n", stderr)
|
|
26
|
+
let eventMask: CGEventMask = (1 << CGEventType.flagsChanged.rawValue)
|
|
27
|
+
|
|
28
|
+
// passRetained so the callback reference stays alive
|
|
29
|
+
let selfPtr = Unmanaged.passRetained(self).toOpaque()
|
|
30
|
+
|
|
31
|
+
guard let tap = CGEvent.tapCreate(
|
|
32
|
+
tap: .cgSessionEventTap,
|
|
33
|
+
place: .headInsertEventTap,
|
|
34
|
+
options: .defaultTap,
|
|
35
|
+
eventsOfInterest: eventMask,
|
|
36
|
+
callback: { (proxy, type, event, refcon) -> Unmanaged<CGEvent>? in
|
|
37
|
+
guard let refcon = refcon else { return Unmanaged.passRetained(event) }
|
|
38
|
+
let monitor = Unmanaged<FnKeyMonitor>.fromOpaque(refcon).takeUnretainedValue()
|
|
39
|
+
return monitor.handleEvent(type: type, event: event)
|
|
40
|
+
},
|
|
41
|
+
userInfo: selfPtr
|
|
42
|
+
) else {
|
|
43
|
+
Unmanaged<FnKeyMonitor>.fromOpaque(selfPtr).release()
|
|
44
|
+
return false
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
self.eventTap = tap
|
|
48
|
+
|
|
49
|
+
let source = CFMachPortCreateRunLoopSource(kCFAllocatorDefault, tap, 0)
|
|
50
|
+
self.runLoopSource = source
|
|
51
|
+
CFRunLoopAddSource(CFRunLoopGetCurrent(), source, .commonModes)
|
|
52
|
+
CGEvent.tapEnable(tap: tap, enable: true)
|
|
53
|
+
fputs("[FnKeyMonitor] Event tap created and enabled OK\n", stderr)
|
|
54
|
+
|
|
55
|
+
// Health check: macOS silently disables taps — re-enable every 3 seconds
|
|
56
|
+
healthCheckTimer = Timer.scheduledTimer(withTimeInterval: 3.0, repeats: true) { [weak self] _ in
|
|
57
|
+
guard let self = self, let tap = self.eventTap else { return }
|
|
58
|
+
if !CGEvent.tapIsEnabled(tap: tap) {
|
|
59
|
+
fputs("[FnKeyMonitor] Tap was disabled, re-enabling\n", stderr)
|
|
60
|
+
CGEvent.tapEnable(tap: tap, enable: true)
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return true
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
func stop() {
|
|
68
|
+
healthCheckTimer?.invalidate()
|
|
69
|
+
healthCheckTimer = nil
|
|
70
|
+
|
|
71
|
+
if let tap = eventTap {
|
|
72
|
+
CGEvent.tapEnable(tap: tap, enable: false)
|
|
73
|
+
}
|
|
74
|
+
if let source = runLoopSource {
|
|
75
|
+
CFRunLoopRemoveSource(CFRunLoopGetCurrent(), source, .commonModes)
|
|
76
|
+
}
|
|
77
|
+
eventTap = nil
|
|
78
|
+
runLoopSource = nil
|
|
79
|
+
fnIsDown = false
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
private func handleEvent(type: CGEventType, event: CGEvent) -> Unmanaged<CGEvent>? {
|
|
83
|
+
// Re-enable if macOS disabled the tap
|
|
84
|
+
if type == .tapDisabledByTimeout || type == .tapDisabledByUserInput {
|
|
85
|
+
if let tap = eventTap {
|
|
86
|
+
CGEvent.tapEnable(tap: tap, enable: true)
|
|
87
|
+
}
|
|
88
|
+
return Unmanaged.passRetained(event)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
let keyCode = UInt16(event.getIntegerValueField(.keyboardEventKeycode))
|
|
92
|
+
|
|
93
|
+
// Only handle fn key (keyCode 63)
|
|
94
|
+
guard keyCode == FnKeyMonitor.fnKeyCode else {
|
|
95
|
+
return Unmanaged.passRetained(event)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
let flags = event.flags.rawValue
|
|
99
|
+
let fnPressed = (flags & FnKeyMonitor.fnFlagMask) != 0
|
|
100
|
+
|
|
101
|
+
fputs("[FnKeyMonitor] flagsChanged keyCode=\(keyCode) flags=0x\(String(flags, radix: 16)) fnPressed=\(fnPressed) fnIsDown=\(fnIsDown)\n", stderr)
|
|
102
|
+
|
|
103
|
+
if fnPressed && !fnIsDown {
|
|
104
|
+
// fn just pressed
|
|
105
|
+
fnIsDown = true
|
|
106
|
+
fputs("[FnKeyMonitor] fn DOWN — starting recording\n", stderr)
|
|
107
|
+
DispatchQueue.main.async { [weak self] in
|
|
108
|
+
self?.onFnKeyDown?()
|
|
109
|
+
}
|
|
110
|
+
return nil // Swallow — prevents emoji picker / language switch
|
|
111
|
+
} else if !fnPressed && fnIsDown {
|
|
112
|
+
// fn released
|
|
113
|
+
fnIsDown = false
|
|
114
|
+
DispatchQueue.main.async { [weak self] in
|
|
115
|
+
self?.onFnKeyUp?()
|
|
116
|
+
}
|
|
117
|
+
return nil // Swallow release too
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return Unmanaged.passRetained(event)
|
|
121
|
+
}
|
|
122
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
3
|
+
<plist version="1.0">
|
|
4
|
+
<dict>
|
|
5
|
+
<key>LSUIElement</key>
|
|
6
|
+
<true/>
|
|
7
|
+
<key>CFBundleName</key>
|
|
8
|
+
<string>Recordings</string>
|
|
9
|
+
<key>CFBundleDisplayName</key>
|
|
10
|
+
<string>Recordings</string>
|
|
11
|
+
<key>CFBundleIdentifier</key>
|
|
12
|
+
<string>com.hasna.recordings</string>
|
|
13
|
+
<key>CFBundleVersion</key>
|
|
14
|
+
<string>1</string>
|
|
15
|
+
<key>CFBundleShortVersionString</key>
|
|
16
|
+
<string>0.1.0</string>
|
|
17
|
+
<key>LSMinimumSystemVersion</key>
|
|
18
|
+
<string>26.0</string>
|
|
19
|
+
<key>NSMicrophoneUsageDescription</key>
|
|
20
|
+
<string>Recordings needs microphone access to record and transcribe your speech.</string>
|
|
21
|
+
</dict>
|
|
22
|
+
</plist>
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import SwiftUI
|
|
2
|
+
import KeyboardShortcuts
|
|
3
|
+
|
|
4
|
+
struct MenuBarPopover: View {
|
|
5
|
+
@ObservedObject var engine: RecordingEngine
|
|
6
|
+
@ObservedObject var shortcuts: VoiceShortcuts
|
|
7
|
+
|
|
8
|
+
var body: some View {
|
|
9
|
+
VStack(spacing: 0) {
|
|
10
|
+
header.padding(.horizontal, 16).padding(.top, 12).padding(.bottom, 8)
|
|
11
|
+
Divider()
|
|
12
|
+
modeSelector.padding(.horizontal, 16).padding(.vertical, 10)
|
|
13
|
+
shortcutRow.padding(.horizontal, 16).padding(.bottom, 8)
|
|
14
|
+
Divider()
|
|
15
|
+
recordingArea.padding(.horizontal, 16).padding(.vertical, 12)
|
|
16
|
+
Divider()
|
|
17
|
+
recentList.frame(maxHeight: 180)
|
|
18
|
+
Divider()
|
|
19
|
+
footer.padding(.horizontal, 16).padding(.vertical, 8)
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// MARK: - Header
|
|
24
|
+
|
|
25
|
+
private var header: some View {
|
|
26
|
+
HStack {
|
|
27
|
+
Image(systemName: "mic.fill").font(.title3).foregroundStyle(.tint)
|
|
28
|
+
Text("Recordings").font(.headline)
|
|
29
|
+
Spacer()
|
|
30
|
+
Toggle(isOn: $engine.isWhisperMode) {
|
|
31
|
+
Label("Whisper", systemImage: "speaker.wave.1.fill").font(.caption)
|
|
32
|
+
}
|
|
33
|
+
.toggleStyle(.button).buttonStyle(.bordered).controlSize(.small)
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// MARK: - Mode Selector
|
|
38
|
+
|
|
39
|
+
private var modeSelector: some View {
|
|
40
|
+
HStack(spacing: 8) {
|
|
41
|
+
modeBtn(.pushToTalk)
|
|
42
|
+
modeBtn(.dictation)
|
|
43
|
+
modeBtn(.command)
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
@ViewBuilder
|
|
48
|
+
private func modeBtn(_ m: RecordingMode) -> some View {
|
|
49
|
+
if engine.mode == m {
|
|
50
|
+
Button { engine.mode = m } label: {
|
|
51
|
+
Label(m.rawValue, systemImage: m.icon).font(.caption)
|
|
52
|
+
.foregroundStyle(.white).frame(maxWidth: .infinity)
|
|
53
|
+
}.buttonStyle(.borderedProminent).controlSize(.small)
|
|
54
|
+
} else {
|
|
55
|
+
Button { engine.mode = m } label: {
|
|
56
|
+
Label(m.rawValue, systemImage: m.icon).font(.caption)
|
|
57
|
+
.frame(maxWidth: .infinity)
|
|
58
|
+
}.buttonStyle(.bordered).controlSize(.small)
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// MARK: - Shortcut Row
|
|
63
|
+
|
|
64
|
+
private var shortcutRow: some View {
|
|
65
|
+
VStack(spacing: 6) {
|
|
66
|
+
// fn key toggle
|
|
67
|
+
HStack {
|
|
68
|
+
Toggle(isOn: $engine.useFnKey) {
|
|
69
|
+
HStack(spacing: 4) {
|
|
70
|
+
Text("fn").font(.system(.caption, design: .monospaced)).bold()
|
|
71
|
+
Text("Globe key").font(.caption).foregroundStyle(.secondary)
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
.toggleStyle(.switch).controlSize(.small)
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Custom shortcut
|
|
78
|
+
HStack(spacing: 8) {
|
|
79
|
+
Text("Custom").font(.caption).foregroundStyle(.secondary)
|
|
80
|
+
Spacer()
|
|
81
|
+
let current = KeyboardShortcuts.getShortcut(for: .toggleRecording)
|
|
82
|
+
Text(current?.description ?? "None")
|
|
83
|
+
.font(.system(.caption, design: .monospaced))
|
|
84
|
+
.padding(.horizontal, 8).padding(.vertical, 3)
|
|
85
|
+
.background(.quaternary, in: RoundedRectangle(cornerRadius: 5))
|
|
86
|
+
|
|
87
|
+
SettingsLink {
|
|
88
|
+
Text("Set").font(.caption2)
|
|
89
|
+
}.buttonStyle(.bordered).controlSize(.mini)
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// MARK: - Recording Area
|
|
95
|
+
|
|
96
|
+
private var recordingArea: some View {
|
|
97
|
+
VStack(spacing: 8) {
|
|
98
|
+
if engine.isRecording {
|
|
99
|
+
HStack(spacing: 12) {
|
|
100
|
+
Circle().fill(.red).frame(width: 10, height: 10)
|
|
101
|
+
Text(fmt(engine.recordingDuration))
|
|
102
|
+
.font(.system(.title2, design: .monospaced))
|
|
103
|
+
Spacer()
|
|
104
|
+
Button("Stop") { engine.stopAndTranscribe() }
|
|
105
|
+
.buttonStyle(.borderedProminent).tint(.red).controlSize(.small)
|
|
106
|
+
}
|
|
107
|
+
.padding(12).glassEffect(.regular.tint(.red))
|
|
108
|
+
} else if engine.isTranscribing {
|
|
109
|
+
HStack(spacing: 8) {
|
|
110
|
+
ProgressView().controlSize(.small)
|
|
111
|
+
Text("Transcribing...").font(.subheadline).foregroundStyle(.secondary)
|
|
112
|
+
}
|
|
113
|
+
.frame(maxWidth: .infinity).padding(12).glassEffect(.regular)
|
|
114
|
+
} else {
|
|
115
|
+
VStack(spacing: 10) {
|
|
116
|
+
Button { engine.startRecording() } label: {
|
|
117
|
+
Label("Record", systemImage: "mic.circle.fill").font(.title3)
|
|
118
|
+
}.buttonStyle(.borderedProminent).controlSize(.large)
|
|
119
|
+
|
|
120
|
+
Text(engine.mode.hint)
|
|
121
|
+
.font(.callout).foregroundStyle(.primary.opacity(0.7))
|
|
122
|
+
.multilineTextAlignment(.center)
|
|
123
|
+
.fixedSize(horizontal: false, vertical: true)
|
|
124
|
+
}
|
|
125
|
+
.frame(maxWidth: .infinity).padding(14).glassEffect(.clear)
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
Text(engine.statusMessage)
|
|
129
|
+
.font(.caption2).foregroundStyle(.secondary)
|
|
130
|
+
.lineLimit(2).truncationMode(.tail)
|
|
131
|
+
.frame(maxWidth: .infinity, alignment: .leading)
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// MARK: - Recent
|
|
136
|
+
|
|
137
|
+
private var recentList: some View {
|
|
138
|
+
Group {
|
|
139
|
+
if engine.recentTranscriptions.isEmpty {
|
|
140
|
+
VStack { Spacer()
|
|
141
|
+
Text("No recent transcriptions").font(.caption).foregroundStyle(.quaternary)
|
|
142
|
+
Spacer()
|
|
143
|
+
}.frame(maxWidth: .infinity)
|
|
144
|
+
} else {
|
|
145
|
+
ScrollView {
|
|
146
|
+
LazyVStack(alignment: .leading, spacing: 4) {
|
|
147
|
+
ForEach(engine.recentTranscriptions.indices, id: \.self) { i in
|
|
148
|
+
TranscriptionRow(item: engine.recentTranscriptions[i])
|
|
149
|
+
}
|
|
150
|
+
}.padding(.horizontal, 16).padding(.vertical, 6)
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// MARK: - Footer
|
|
157
|
+
|
|
158
|
+
private var footer: some View {
|
|
159
|
+
HStack {
|
|
160
|
+
SettingsLink { Image(systemName: "gear") }.buttonStyle(.borderless)
|
|
161
|
+
Spacer()
|
|
162
|
+
Button("Quit") { NSApplication.shared.terminate(nil) }
|
|
163
|
+
.buttonStyle(.borderless).foregroundStyle(.secondary)
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
private func fmt(_ t: TimeInterval) -> String {
|
|
168
|
+
String(format: "%d:%02d", Int(t) / 60, Int(t) % 60)
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
struct TranscriptionRow: View {
|
|
173
|
+
let item: TranscriptionResult
|
|
174
|
+
var body: some View {
|
|
175
|
+
HStack(alignment: .top, spacing: 8) {
|
|
176
|
+
Text(item.displayText).font(.caption).lineLimit(2)
|
|
177
|
+
.frame(maxWidth: .infinity, alignment: .leading)
|
|
178
|
+
Text({ let s = Date().timeIntervalSince(item.timestamp)
|
|
179
|
+
return s < 60 ? "now" : s < 3600 ? "\(Int(s/60))m" : "\(Int(s/3600))h"
|
|
180
|
+
}()).font(.caption2).foregroundStyle(.tertiary)
|
|
181
|
+
}
|
|
182
|
+
.padding(.vertical, 4).contentShape(Rectangle())
|
|
183
|
+
.onTapGesture {
|
|
184
|
+
NSPasteboard.general.clearContents()
|
|
185
|
+
NSPasteboard.general.setString(item.displayText, forType: .string)
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|