fix: fixes issue where Moments camera wouldn't properly start on desktop app (#2084)
This commit is contained in:
18
packages/desktop/app/javascripts/Main/Media/MediaManager.ts
Normal file
18
packages/desktop/app/javascripts/Main/Media/MediaManager.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { MediaManagerInterface } from './MediaManagerInterface'
|
||||
|
||||
const { systemPreferences } = require('electron')
|
||||
|
||||
export class MediaManager implements MediaManagerInterface {
|
||||
async askForMediaAccess(type: 'camera' | 'microphone'): Promise<boolean> {
|
||||
const permission = systemPreferences.getMediaAccessStatus(type)
|
||||
|
||||
if (permission === 'granted') {
|
||||
return true
|
||||
} else if (permission === 'denied') {
|
||||
return false
|
||||
}
|
||||
|
||||
const granted = await systemPreferences.askForMediaAccess(type)
|
||||
return granted
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
export interface MediaManagerInterface {
|
||||
askForMediaAccess(type: 'camera' | 'microphone'): Promise<boolean>
|
||||
}
|
||||
@@ -19,6 +19,7 @@ import { MenuManagerInterface } from '../Menus/MenuManagerInterface'
|
||||
import { Component, PackageManagerInterface } from '../Packages/PackageManagerInterface'
|
||||
import { SearchManagerInterface } from '../Search/SearchManagerInterface'
|
||||
import { RemoteDataInterface } from './DataInterface'
|
||||
import { MediaManagerInterface } from '../Media/MediaManagerInterface'
|
||||
|
||||
/**
|
||||
* Read https://github.com/electron/remote to understand how electron/remote works.
|
||||
@@ -34,6 +35,7 @@ export class RemoteBridge implements CrossProcessBridge {
|
||||
private data: RemoteDataInterface,
|
||||
private menus: MenuManagerInterface,
|
||||
private fileBackups: FileBackupsDevice,
|
||||
private media: MediaManagerInterface,
|
||||
) {}
|
||||
|
||||
get exposableValue(): CrossProcessBridge {
|
||||
@@ -73,6 +75,7 @@ export class RemoteBridge implements CrossProcessBridge {
|
||||
openFileBackup: this.openFileBackup.bind(this),
|
||||
getFileBackupReadToken: this.getFileBackupReadToken.bind(this),
|
||||
readNextChunk: this.readNextChunk.bind(this),
|
||||
askForMediaAccess: this.askForMediaAccess.bind(this),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -223,4 +226,8 @@ export class RemoteBridge implements CrossProcessBridge {
|
||||
public openFileBackup(record: FileBackupRecord): Promise<void> {
|
||||
return this.fileBackups.openFileBackup(record)
|
||||
}
|
||||
|
||||
askForMediaAccess(type: 'camera' | 'microphone'): Promise<boolean> {
|
||||
return this.media.askForMediaAccess(type)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import { createBackupsManager } from './Backups/BackupsManager'
|
||||
import { BackupsManagerInterface } from './Backups/BackupsManagerInterface'
|
||||
import { FilesBackupManager } from './FileBackups/FileBackupsManager'
|
||||
import { Keychain } from './Keychain/Keychain'
|
||||
import { MediaManager } from './Media/MediaManager'
|
||||
import { MenuManagerInterface } from './Menus/MenuManagerInterface'
|
||||
import { buildContextMenu, createMenuManager } from './Menus/Menus'
|
||||
import { initializePackageManager } from './Packages/PackageManager'
|
||||
@@ -74,6 +75,7 @@ export async function createWindowState({
|
||||
},
|
||||
services.menuManager,
|
||||
services.fileBackupsManager,
|
||||
services.mediaManager,
|
||||
)
|
||||
|
||||
const shouldOpenUrl = (url: string) => url.startsWith('http') || url.startsWith('mailto')
|
||||
@@ -203,6 +205,7 @@ async function createWindowServices(window: Electron.BrowserWindow, appState: Ap
|
||||
const updateManager = setupUpdates(window, appState, backupsManager)
|
||||
const trayManager = createTrayManager(window, appState.store)
|
||||
const spellcheckerManager = createSpellcheckerManager(appState.store, window.webContents, appLocale)
|
||||
const mediaManager = new MediaManager()
|
||||
|
||||
if (isTesting()) {
|
||||
handleTestMessage(MessageType.SpellCheckerManager, () => spellcheckerManager)
|
||||
@@ -228,6 +231,7 @@ async function createWindowServices(window: Electron.BrowserWindow, appState: Ap
|
||||
packageManager,
|
||||
searchManager,
|
||||
fileBackupsManager,
|
||||
mediaManager,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -49,4 +49,6 @@ export interface CrossProcessBridge extends FileBackupsDevice {
|
||||
onInitialDataLoad(): void
|
||||
|
||||
destroyAllData(): void
|
||||
|
||||
askForMediaAccess(type: 'camera' | 'microphone'): Promise<boolean>
|
||||
}
|
||||
|
||||
@@ -166,4 +166,8 @@ export class DesktopDevice extends WebOrDesktopDevice implements DesktopDeviceIn
|
||||
isDeviceDestroyed(): boolean {
|
||||
return false
|
||||
}
|
||||
|
||||
askForMediaAccess(type: 'camera' | 'microphone'): Promise<boolean> {
|
||||
return this.remoteBridge.askForMediaAccess(type)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,5 +10,7 @@
|
||||
<true/>
|
||||
<key>com.apple.security.cs.disable-library-validation</key>
|
||||
<true/>
|
||||
<key>com.apple.security.device.camera</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</plist>
|
||||
|
||||
@@ -104,6 +104,9 @@
|
||||
"hardenedRuntime": true,
|
||||
"entitlements": "./build/entitlements.mac.inherit.plist",
|
||||
"entitlementsInherit": "./build/entitlements.mac.inherit.plist",
|
||||
"extendInfo": {
|
||||
"NSCameraUsageDescription": "Standard Notes requires access to your camera to enable the Moments feature."
|
||||
},
|
||||
"target": [
|
||||
"dmg",
|
||||
"zip"
|
||||
|
||||
@@ -19,6 +19,8 @@ export interface WebClientRequiresDesktopMethods extends FileBackupsDevice {
|
||||
downloadBackup(): void | Promise<void>
|
||||
|
||||
get extensionsServerHost(): string
|
||||
|
||||
askForMediaAccess(type: 'camera' | 'microphone'): Promise<boolean>
|
||||
}
|
||||
|
||||
export interface DesktopClientRequiresWebMethods {
|
||||
|
||||
@@ -86,6 +86,20 @@ export class MomentsService extends AbstractViewController {
|
||||
message: 'Capturing Moment...',
|
||||
})
|
||||
|
||||
if (this.application.desktopDevice) {
|
||||
const granted = await this.application.desktopDevice.askForMediaAccess('camera')
|
||||
if (!granted) {
|
||||
dismissToast(toastId)
|
||||
addToast({
|
||||
type: ToastType.Error,
|
||||
message: 'Please enable Camera permissions for Standard Notes to enable Moments.',
|
||||
duration: 3000,
|
||||
})
|
||||
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
const { canvas, video, stream, width, height } = await preparePhotoOperation()
|
||||
|
||||
const filename = `Moment ${dateToStringStyle1(new Date())}.png`
|
||||
|
||||
Reference in New Issue
Block a user