2023-02-20 20:57:38 +00:00
|
|
|
import { fetchWithSession } from '@electron/internal/browser/api/net-fetch';
|
2024-01-04 21:20:37 +00:00
|
|
|
import { net } from 'electron/main';
|
2023-03-20 14:34:49 +00:00
|
|
|
const { fromPartition, fromPath, Session } = process._linkedBinding('electron_browser_session');
|
2024-09-10 23:05:57 +00:00
|
|
|
const { isDisplayMediaSystemPickerAvailable } = process._linkedBinding('electron_browser_desktop_capturer');
|
|
|
|
|
|
|
|
// Fake video source that activates the native system picker
|
|
|
|
// This is used to get around the need for a screen/window
|
|
|
|
// id in Chrome's desktopCapturer.
|
|
|
|
let fakeVideoSourceId = -1;
|
|
|
|
const systemPickerVideoSource = Object.create(null);
|
|
|
|
Object.defineProperty(systemPickerVideoSource, 'id', {
|
|
|
|
get () {
|
|
|
|
return `window:${fakeVideoSourceId--}:0`;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
systemPickerVideoSource.name = '';
|
|
|
|
Object.freeze(systemPickerVideoSource);
|
2023-02-20 20:57:38 +00:00
|
|
|
|
|
|
|
Session.prototype.fetch = function (input: RequestInfo, init?: RequestInit) {
|
2024-01-04 21:20:37 +00:00
|
|
|
return fetchWithSession(input, init, this, net.request);
|
2023-02-20 20:57:38 +00:00
|
|
|
};
|
2020-05-22 19:46:22 +00:00
|
|
|
|
2024-09-10 23:05:57 +00:00
|
|
|
Session.prototype.setDisplayMediaRequestHandler = function (handler, opts) {
|
|
|
|
if (!handler) return this._setDisplayMediaRequestHandler(handler, opts);
|
|
|
|
|
|
|
|
this._setDisplayMediaRequestHandler(async (req, callback) => {
|
|
|
|
if (opts && opts.useSystemPicker && isDisplayMediaSystemPickerAvailable()) {
|
|
|
|
return callback({ video: systemPickerVideoSource });
|
|
|
|
}
|
|
|
|
|
|
|
|
return handler(req, callback);
|
|
|
|
}, opts);
|
|
|
|
};
|
|
|
|
|
2020-05-22 19:46:22 +00:00
|
|
|
export default {
|
|
|
|
fromPartition,
|
2023-03-20 14:34:49 +00:00
|
|
|
fromPath,
|
2020-05-22 19:46:22 +00:00
|
|
|
get defaultSession () {
|
|
|
|
return fromPartition('');
|
|
|
|
}
|
|
|
|
};
|