Browse Source

feat: add getNativePickerSource() API option

Keeley Hammond 7 months ago
parent
commit
d1671d3112
1 changed files with 21 additions and 0 deletions
  1. 21 0
      lib/browser/api/desktop-capturer.ts

+ 21 - 0
lib/browser/api/desktop-capturer.ts

@@ -15,6 +15,27 @@ function isValid (options: Electron.SourcesOptions) {
 
 export { isDisplayMediaSystemPickerAvailable };
 
+export async function getNativePickerSource () {
+  if (process.platform !== 'darwin') {
+    console.error('Native system picker option is currently only supported on MacOS');
+  }
+
+  if (!isDisplayMediaSystemPickerAvailable) {
+    console.error(`Native system picker unavailable. 
+      Note: This is an experimental API; please check the API documentation for updated restrictions`);
+  }
+
+  // Pass in the needed options for a more native experience
+  // screen & windows by default, no thumbnails, since the native picker doesn't return them
+  const options: Electron.SourcesOptions = {
+    types: ['screen', 'window'],
+    thumbnailSize: { width: 0, height: 0 },
+    fetchWindowIcons: false
+  };
+
+  return await getSources(options);
+}
+
 export async function getSources (args: Electron.SourcesOptions) {
   if (!isValid(args)) throw new Error('Invalid options');