kap-selfie 1.2.1
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/index.html +86 -0
- package/index.js +170 -0
- package/package.json +41 -0
- package/permissions +0 -0
- package/readme.md +24 -0
- package/video-devices +0 -0
package/index.html
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
|
|
3
|
+
<html lang="en">
|
|
4
|
+
<head>
|
|
5
|
+
<meta charset="utf-8">
|
|
6
|
+
|
|
7
|
+
<style>
|
|
8
|
+
body,
|
|
9
|
+
html,
|
|
10
|
+
.container {
|
|
11
|
+
margin: 0;
|
|
12
|
+
width: 100vw;
|
|
13
|
+
height: 100vh;
|
|
14
|
+
-webkit-app-region: drag;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
video {
|
|
18
|
+
width: 100%;
|
|
19
|
+
height: 100%;
|
|
20
|
+
object-fit: cover;
|
|
21
|
+
-webkit-app-region: drag;
|
|
22
|
+
transition: opacity 0.2s ease-in-out;
|
|
23
|
+
}
|
|
24
|
+
</style>
|
|
25
|
+
</head>
|
|
26
|
+
|
|
27
|
+
<body>
|
|
28
|
+
<div class="container">
|
|
29
|
+
<video id="preview" autoplay="true"></video>
|
|
30
|
+
</div>
|
|
31
|
+
</body>
|
|
32
|
+
|
|
33
|
+
<script>
|
|
34
|
+
const electron = require('electron');
|
|
35
|
+
const {ipcRenderer} = electron;
|
|
36
|
+
|
|
37
|
+
electron.remote.getCurrentWindow().setIgnoreMouseEvents(true, {forward: true});
|
|
38
|
+
|
|
39
|
+
const video = document.querySelector('#preview');
|
|
40
|
+
|
|
41
|
+
ipcRenderer.on('data', (_, {videoDeviceName, hoverOpacity, borderRadius}) => {
|
|
42
|
+
const css = `
|
|
43
|
+
video {
|
|
44
|
+
border-radius: ${borderRadius};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
video:hover {
|
|
48
|
+
opacity: ${hoverOpacity};
|
|
49
|
+
}
|
|
50
|
+
`;
|
|
51
|
+
|
|
52
|
+
const style = document.createElement('style');
|
|
53
|
+
style.appendChild(document.createTextNode(css));
|
|
54
|
+
document.querySelector('head').appendChild(style);
|
|
55
|
+
|
|
56
|
+
navigator.mediaDevices.enumerateDevices().then(devices => {
|
|
57
|
+
const videoDevices = devices.filter(d => d.kind === 'videoinput');
|
|
58
|
+
const [defaultDevice] = videoDevices;
|
|
59
|
+
|
|
60
|
+
const device = (
|
|
61
|
+
videoDeviceName && videoDevices.find(d => d.label.includes(videoDeviceName))
|
|
62
|
+
) || defaultDevice;
|
|
63
|
+
|
|
64
|
+
if (!device) {
|
|
65
|
+
ipcRenderer.send('kap-camera-mount');
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const {deviceId} = device;
|
|
70
|
+
|
|
71
|
+
navigator.mediaDevices.getUserMedia({video: {deviceId}}).then(stream => {
|
|
72
|
+
video.srcObject = stream;
|
|
73
|
+
ipcRenderer.send('kap-camera-mount');
|
|
74
|
+
}).catch(() => ipcRenderer.send('kap-camera-mount'));
|
|
75
|
+
}).catch(() => ipcRenderer.send('kap-camera-mount'));
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
video.addEventListener('mouseenter', event => {
|
|
79
|
+
if (event.metaKey) {
|
|
80
|
+
electron.remote.getCurrentWindow().setIgnoreMouseEvents(false);
|
|
81
|
+
} else {
|
|
82
|
+
electron.remote.getCurrentWindow().setIgnoreMouseEvents(true, {forward: true});
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
</script>
|
|
86
|
+
</html>
|
package/index.js
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
'use-strict';
|
|
2
|
+
|
|
3
|
+
const util = require('electron-util');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const {BrowserWindow, screen, ipcMain, dialog, shell, app} = require('electron');
|
|
6
|
+
const execa = require('execa');
|
|
7
|
+
|
|
8
|
+
const binary = path.join(util.fixPathForAsarUnpack(__dirname), 'video-devices');
|
|
9
|
+
const permissionsBinary = path.join(util.fixPathForAsarUnpack(__dirname), 'permissions');
|
|
10
|
+
const contentPath = path.join(util.fixPathForAsarUnpack(__dirname), 'index.html');
|
|
11
|
+
const PADDING = 20;
|
|
12
|
+
|
|
13
|
+
const devices = ['Default'];
|
|
14
|
+
|
|
15
|
+
try {
|
|
16
|
+
devices.push(...execa.sync(binary).stdout.trim().split('\n'));
|
|
17
|
+
} catch {}
|
|
18
|
+
|
|
19
|
+
const config = {
|
|
20
|
+
deviceName: {
|
|
21
|
+
title: 'Device',
|
|
22
|
+
description: 'Which device to display.',
|
|
23
|
+
enum: devices,
|
|
24
|
+
required: true,
|
|
25
|
+
default: 'Default'
|
|
26
|
+
},
|
|
27
|
+
borderRadius: {
|
|
28
|
+
title: 'Border Radius',
|
|
29
|
+
description: 'Any valid `border-radius` value, like `10px` or `50%`.',
|
|
30
|
+
type: 'string',
|
|
31
|
+
required: true,
|
|
32
|
+
default: '50%'
|
|
33
|
+
},
|
|
34
|
+
hoverOpacity: {
|
|
35
|
+
title: 'Hover Opacity',
|
|
36
|
+
description: 'Opacity of the window on when moused over.',
|
|
37
|
+
type: 'number',
|
|
38
|
+
minimum: 0,
|
|
39
|
+
maximum: 1,
|
|
40
|
+
default: 0.6,
|
|
41
|
+
required: true
|
|
42
|
+
},
|
|
43
|
+
width: {
|
|
44
|
+
title: 'Width',
|
|
45
|
+
description: 'Width of the window.',
|
|
46
|
+
type: 'number',
|
|
47
|
+
minimum: 0,
|
|
48
|
+
default: 128,
|
|
49
|
+
required: true
|
|
50
|
+
},
|
|
51
|
+
height: {
|
|
52
|
+
title: 'Height',
|
|
53
|
+
description: 'Height of the window.',
|
|
54
|
+
type: 'number',
|
|
55
|
+
minimum: 0,
|
|
56
|
+
default: 128,
|
|
57
|
+
required: true
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const getBounds = (cropArea, screenBounds, {width, height}) => {
|
|
62
|
+
return {
|
|
63
|
+
x: cropArea.x + screenBounds.x + cropArea.width - width - PADDING,
|
|
64
|
+
y: screenBounds.height - (cropArea.y + cropArea.height) + screenBounds.y + cropArea.height - height - PADDING,
|
|
65
|
+
width,
|
|
66
|
+
height
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const willStartRecording = async ({state, config, apertureOptions: {screenId, cropArea}}) => {
|
|
71
|
+
const hasPermissions = await ensureCameraPermission();
|
|
72
|
+
|
|
73
|
+
if (!hasPermissions) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const screens = screen.getAllDisplays();
|
|
78
|
+
const {bounds} = screens.find(s => s.id === screenId) || {};
|
|
79
|
+
|
|
80
|
+
const position = getBounds(cropArea, bounds, {
|
|
81
|
+
width: config.get('width'),
|
|
82
|
+
height: config.get('height')
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
state.window = new BrowserWindow({
|
|
86
|
+
...position,
|
|
87
|
+
closable: false,
|
|
88
|
+
minimizable: false,
|
|
89
|
+
alwaysOnTop: true,
|
|
90
|
+
frame: false,
|
|
91
|
+
transparent: true,
|
|
92
|
+
titleBarStyle: 'customButtonsOnHover',
|
|
93
|
+
webPreferences: {nodeIntegration: true, contextIsolation: false, enableRemoteModule: true}
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
state.window.loadFile(contentPath);
|
|
97
|
+
|
|
98
|
+
// state.window.openDevTools({mode: 'detach'});
|
|
99
|
+
|
|
100
|
+
state.window.webContents.on('did-finish-load', () => {
|
|
101
|
+
state.window.webContents.send('data', {
|
|
102
|
+
videoDeviceName: config.get('deviceName'),
|
|
103
|
+
hoverOpacity: config.get('hoverOpacity'),
|
|
104
|
+
borderRadius: config.get('borderRadius')
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
return new Promise(resolve => {
|
|
109
|
+
ipcMain.on('kap-camera-mount', resolve);
|
|
110
|
+
|
|
111
|
+
// Resolve after 5 seconds to not block recording if for some reason there's no event
|
|
112
|
+
setTimeout(resolve, 5000);
|
|
113
|
+
});
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
const didStopRecording = ({state}) => {
|
|
117
|
+
if (state.window) {
|
|
118
|
+
state.window.destroy();
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
const configDescription =
|
|
123
|
+
`Create a window showing the selected camera on the bottom-left corner of the recording.
|
|
124
|
+
The window is click-through and its hover opacity and size can be adjusted.
|
|
125
|
+
|
|
126
|
+
To move the window, hold Command before you hover over it, then click and drag it anywhere on the screen.
|
|
127
|
+
`;
|
|
128
|
+
|
|
129
|
+
const openSystemPreferences = path => shell.openExternal(`x-apple.systempreferences:com.apple.preference.security?${path}`);
|
|
130
|
+
|
|
131
|
+
const hasCameraPermission = async () => {
|
|
132
|
+
try {
|
|
133
|
+
return (await execa(permissionsBinary)).stdout === 'true';
|
|
134
|
+
} catch {
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const ensureCameraPermission = async () => {
|
|
140
|
+
const hasPermission = await hasCameraPermission();
|
|
141
|
+
|
|
142
|
+
if (hasPermission) {
|
|
143
|
+
return true;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const {response} = await dialog.showMessageBox({
|
|
147
|
+
type: 'warning',
|
|
148
|
+
buttons: ['Open System Preferences', 'Cancel'],
|
|
149
|
+
defaultId: 0,
|
|
150
|
+
message: 'kap-camera cannot access the camera.',
|
|
151
|
+
detail: 'kap-camera requires camera access to be able to show the contents of the webcam. You can grant this in the System Preferences. Afterwards, launch Kap for the changes to take effect.',
|
|
152
|
+
cancelId: 1
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
if (response === 0) {
|
|
156
|
+
await openSystemPreferences('Privacy_Camera');
|
|
157
|
+
app.quit();
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
return false;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
exports.recordServices = [{
|
|
164
|
+
title: 'Show Camera',
|
|
165
|
+
config,
|
|
166
|
+
configDescription,
|
|
167
|
+
willStartRecording,
|
|
168
|
+
didStopRecording,
|
|
169
|
+
willEnable: ensureCameraPermission
|
|
170
|
+
}];
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "kap-selfie",
|
|
3
|
+
"version": "1.2.1",
|
|
4
|
+
"main": "index.js",
|
|
5
|
+
"description": "Show a camera while recording.",
|
|
6
|
+
"repository": "karaggeorge/kap-camera",
|
|
7
|
+
"author": {
|
|
8
|
+
"name": "George Karagkiaouris",
|
|
9
|
+
"email": "gkaragkiaouris2@gmail.com",
|
|
10
|
+
"url": "https://gkaragkiaouris.tech"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [
|
|
13
|
+
"kap-plugin",
|
|
14
|
+
"camera",
|
|
15
|
+
"face",
|
|
16
|
+
"webcam",
|
|
17
|
+
"recording"
|
|
18
|
+
],
|
|
19
|
+
"kap": {
|
|
20
|
+
"version": ">=3.3.2"
|
|
21
|
+
},
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"scripts": {
|
|
24
|
+
"build-devices": "swiftc -o video-devices-arm64 -target arm64-apple-macosx14.0 video-devices.swift && swiftc -o video-devices-x86_64 -target x86_64-apple-macosx14.0 video-devices.swift && lipo -create video-devices-arm64 video-devices-x86_64 -output video-devices && rm video-devices-arm64 video-devices-x86_64",
|
|
25
|
+
"build-permissions": "swiftc -o permissions-arm64 -target arm64-apple-macosx14.0 permissions.swift && swiftc -o permissions-x86_64 -target x86_64-apple-macosx14.0 permissions.swift && lipo -create permissions-arm64 permissions-x86_64 -output permissions && rm permissions-arm64 permissions-x86_64",
|
|
26
|
+
"build": "yarn run build-devices && yarn run build-permissions"
|
|
27
|
+
},
|
|
28
|
+
"files": [
|
|
29
|
+
"index.js",
|
|
30
|
+
"video-devices",
|
|
31
|
+
"permissions",
|
|
32
|
+
"index.html"
|
|
33
|
+
],
|
|
34
|
+
"peerDependencies": {
|
|
35
|
+
"electron": "*"
|
|
36
|
+
},
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"electron-util": "^0.14.2",
|
|
39
|
+
"execa": "^4.0.3"
|
|
40
|
+
}
|
|
41
|
+
}
|
package/permissions
ADDED
|
Binary file
|
package/readme.md
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# kap-selfie
|
|
2
|
+
|
|
3
|
+
> [Kap](https://github.com/wulkano/kap) plugin - Show a camera while recording
|
|
4
|
+
|
|
5
|
+
A fork of [karaggeorge/kap-camera](https://github.com/karaggeorge/kap-camera) with fixes for modern macOS (14+) and Apple Silicon.
|
|
6
|
+
|
|
7
|
+
## What was fixed
|
|
8
|
+
|
|
9
|
+
- **Deprecated Swift API**: Replaced `AVCaptureDevice.devices(for:)` with `AVCaptureDevice.DiscoverySession` using `.builtInWideAngleCamera`, `.external`, and `.continuityCamera` device types.
|
|
10
|
+
- **Build target**: Universal binary supporting both Apple Silicon (arm64) and Intel (x86_64), targeting macOS 14.0.
|
|
11
|
+
- **Electron compatibility**: Added `contextIsolation: false` and `enableRemoteModule: true` to `webPreferences` for Electron 13+.
|
|
12
|
+
|
|
13
|
+
## Install
|
|
14
|
+
|
|
15
|
+
In the `Kap` menu, go to `Preferences…`, select the `Plugins` pane, search for `kap-selfie`, and toggle it.
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
In the cropper or by right-clicking the tray icon, click the `…` icon, then `Plugins` and make sure `Show Camera` is enabled.
|
|
20
|
+
|
|
21
|
+
The plugin creates a window showing the selected camera on the bottom-left corner of the recording.
|
|
22
|
+
The window is click-through and its hover opacity and size can be adjusted.
|
|
23
|
+
|
|
24
|
+
To move the window, hold Command before you hover over it, then click and drag it anywhere on the screen.
|
package/video-devices
ADDED
|
Binary file
|