@hasna/recordings 0.1.3 → 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/dist/mcp/index.js +17 -2
- package/package.json +4 -4
- package/src/db/database.ts +8 -0
- package/src/db/recordings.ts +8 -2
- package/src/mcp/index.ts +6 -0
- 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/src/types/index.ts +6 -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/dist/mcp/index.js
CHANGED
|
@@ -4190,6 +4190,12 @@ var MIGRATIONS = [
|
|
|
4190
4190
|
CREATE INDEX IF NOT EXISTS idx_recordings_created ON recordings(created_at);
|
|
4191
4191
|
CREATE INDEX IF NOT EXISTS idx_recordings_mode ON recordings(processing_mode);
|
|
4192
4192
|
CREATE INDEX IF NOT EXISTS idx_recording_tags_tag ON recording_tags(tag);
|
|
4193
|
+
`,
|
|
4194
|
+
`
|
|
4195
|
+
ALTER TABLE recordings ADD COLUMN goal TEXT;
|
|
4196
|
+
ALTER TABLE recordings ADD COLUMN role TEXT;
|
|
4197
|
+
ALTER TABLE recordings ADD COLUMN task_list_id TEXT;
|
|
4198
|
+
INSERT OR IGNORE INTO _migrations (id) VALUES (2);
|
|
4193
4199
|
`
|
|
4194
4200
|
];
|
|
4195
4201
|
function getDatabase(dbPath) {
|
|
@@ -4239,6 +4245,9 @@ function parseRow(row) {
|
|
|
4239
4245
|
agent_id: row["agent_id"] || null,
|
|
4240
4246
|
project_id: row["project_id"] || null,
|
|
4241
4247
|
session_id: row["session_id"] || null,
|
|
4248
|
+
goal: row["goal"] || null,
|
|
4249
|
+
role: row["role"] || null,
|
|
4250
|
+
task_list_id: row["task_list_id"] || null,
|
|
4242
4251
|
metadata: JSON.parse(row["metadata"] || "{}"),
|
|
4243
4252
|
created_at: row["created_at"]
|
|
4244
4253
|
};
|
|
@@ -4248,8 +4257,8 @@ function createRecording(input, db) {
|
|
|
4248
4257
|
const id = crypto.randomUUID();
|
|
4249
4258
|
const tagsJson = JSON.stringify(input.tags || []);
|
|
4250
4259
|
const metadataJson = JSON.stringify(input.metadata || {});
|
|
4251
|
-
d.query(`INSERT INTO recordings (id, audio_path, raw_text, processed_text, processing_mode, model_used, enhancement_model, duration_ms, language, tags, agent_id, project_id, session_id, metadata)
|
|
4252
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`).run(id, input.audio_path || null, input.raw_text, input.processed_text || null, input.processing_mode || "raw", input.model_used || "gpt-4o-mini-transcribe", input.enhancement_model || null, input.duration_ms || 0, input.language || null, tagsJson, input.agent_id || null, input.project_id || null, input.session_id || null, metadataJson);
|
|
4260
|
+
d.query(`INSERT INTO recordings (id, audio_path, raw_text, processed_text, processing_mode, model_used, enhancement_model, duration_ms, language, tags, agent_id, project_id, session_id, goal, role, task_list_id, metadata)
|
|
4261
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`).run(id, input.audio_path || null, input.raw_text, input.processed_text || null, input.processing_mode || "raw", input.model_used || "gpt-4o-mini-transcribe", input.enhancement_model || null, input.duration_ms || 0, input.language || null, tagsJson, input.agent_id || null, input.project_id || null, input.session_id || null, input.goal || null, input.role || null, input.task_list_id || null, metadataJson);
|
|
4253
4262
|
if (input.tags && input.tags.length > 0) {
|
|
4254
4263
|
const insertTag = d.query("INSERT OR IGNORE INTO recording_tags (recording_id, tag) VALUES (?, ?)");
|
|
4255
4264
|
for (const tag of input.tags) {
|
|
@@ -4700,6 +4709,9 @@ server.tool("save_recording", "Save text as recording. Auto-enhances if needed."
|
|
|
4700
4709
|
agent_id: exports_external.string().optional(),
|
|
4701
4710
|
project_id: exports_external.string().optional(),
|
|
4702
4711
|
session_id: exports_external.string().optional(),
|
|
4712
|
+
goal: exports_external.string().optional().describe("Goal or purpose of this recording session (e.g. 'code review for PR #123')"),
|
|
4713
|
+
role: exports_external.string().optional().describe("Agent role for this session (e.g. 'dev agent for connectdev')"),
|
|
4714
|
+
task_list_id: exports_external.string().optional().describe("Task list ID to bind this recording to"),
|
|
4703
4715
|
metadata: exports_external.record(exports_external.unknown()).optional()
|
|
4704
4716
|
}, async (args) => {
|
|
4705
4717
|
try {
|
|
@@ -4724,6 +4736,9 @@ server.tool("save_recording", "Save text as recording. Auto-enhances if needed."
|
|
|
4724
4736
|
agent_id: args.agent_id,
|
|
4725
4737
|
project_id: args.project_id,
|
|
4726
4738
|
session_id: args.session_id,
|
|
4739
|
+
goal: args.goal,
|
|
4740
|
+
role: args.role,
|
|
4741
|
+
task_list_id: args.task_list_id,
|
|
4727
4742
|
metadata: args.metadata
|
|
4728
4743
|
});
|
|
4729
4744
|
const output = processedText || args.text;
|
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
|
}
|
package/src/db/database.ts
CHANGED
|
@@ -63,6 +63,14 @@ const MIGRATIONS = [
|
|
|
63
63
|
CREATE INDEX IF NOT EXISTS idx_recordings_mode ON recordings(processing_mode);
|
|
64
64
|
CREATE INDEX IF NOT EXISTS idx_recording_tags_tag ON recording_tags(tag);
|
|
65
65
|
`,
|
|
66
|
+
|
|
67
|
+
// Migration 2: session tagging attributes
|
|
68
|
+
`
|
|
69
|
+
ALTER TABLE recordings ADD COLUMN goal TEXT;
|
|
70
|
+
ALTER TABLE recordings ADD COLUMN role TEXT;
|
|
71
|
+
ALTER TABLE recordings ADD COLUMN task_list_id TEXT;
|
|
72
|
+
INSERT OR IGNORE INTO _migrations (id) VALUES (2);
|
|
73
|
+
`,
|
|
66
74
|
];
|
|
67
75
|
|
|
68
76
|
export function getDatabase(dbPath?: string): Database {
|
package/src/db/recordings.ts
CHANGED
|
@@ -22,6 +22,9 @@ function parseRow(row: Record<string, unknown>): Recording {
|
|
|
22
22
|
agent_id: (row["agent_id"] as string) || null,
|
|
23
23
|
project_id: (row["project_id"] as string) || null,
|
|
24
24
|
session_id: (row["session_id"] as string) || null,
|
|
25
|
+
goal: (row["goal"] as string) || null,
|
|
26
|
+
role: (row["role"] as string) || null,
|
|
27
|
+
task_list_id: (row["task_list_id"] as string) || null,
|
|
25
28
|
metadata: JSON.parse((row["metadata"] as string) || "{}") as Record<string, unknown>,
|
|
26
29
|
created_at: row["created_at"] as string,
|
|
27
30
|
};
|
|
@@ -37,8 +40,8 @@ export function createRecording(
|
|
|
37
40
|
const metadataJson = JSON.stringify(input.metadata || {});
|
|
38
41
|
|
|
39
42
|
d.query(
|
|
40
|
-
`INSERT INTO recordings (id, audio_path, raw_text, processed_text, processing_mode, model_used, enhancement_model, duration_ms, language, tags, agent_id, project_id, session_id, metadata)
|
|
41
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`
|
|
43
|
+
`INSERT INTO recordings (id, audio_path, raw_text, processed_text, processing_mode, model_used, enhancement_model, duration_ms, language, tags, agent_id, project_id, session_id, goal, role, task_list_id, metadata)
|
|
44
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`
|
|
42
45
|
).run(
|
|
43
46
|
id,
|
|
44
47
|
input.audio_path || null,
|
|
@@ -53,6 +56,9 @@ export function createRecording(
|
|
|
53
56
|
input.agent_id || null,
|
|
54
57
|
input.project_id || null,
|
|
55
58
|
input.session_id || null,
|
|
59
|
+
input.goal || null,
|
|
60
|
+
input.role || null,
|
|
61
|
+
input.task_list_id || null,
|
|
56
62
|
metadataJson
|
|
57
63
|
);
|
|
58
64
|
|
package/src/mcp/index.ts
CHANGED
|
@@ -152,6 +152,9 @@ server.tool(
|
|
|
152
152
|
agent_id: z.string().optional(),
|
|
153
153
|
project_id: z.string().optional(),
|
|
154
154
|
session_id: z.string().optional(),
|
|
155
|
+
goal: z.string().optional().describe("Goal or purpose of this recording session (e.g. 'code review for PR #123')"),
|
|
156
|
+
role: z.string().optional().describe("Agent role for this session (e.g. 'dev agent for connectdev')"),
|
|
157
|
+
task_list_id: z.string().optional().describe("Task list ID to bind this recording to"),
|
|
155
158
|
metadata: z.record(z.unknown()).optional(),
|
|
156
159
|
},
|
|
157
160
|
async (args) => {
|
|
@@ -179,6 +182,9 @@ server.tool(
|
|
|
179
182
|
agent_id: args.agent_id,
|
|
180
183
|
project_id: args.project_id,
|
|
181
184
|
session_id: args.session_id,
|
|
185
|
+
goal: args.goal,
|
|
186
|
+
role: args.role,
|
|
187
|
+
task_list_id: args.task_list_id,
|
|
182
188
|
metadata: args.metadata,
|
|
183
189
|
});
|
|
184
190
|
|
|
@@ -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>
|