Fix to convert electron platform name darwin to macos (#3573)
* Fix to convert electron platform name darwin to macos * Remove unneeded async * Fix to handle other possible platform strings * Add electron test for user sidebar menu text * Fix formatting
This commit is contained in:
34
e2e/playwright/user-sidebar-menu-tests.spec.ts
Normal file
34
e2e/playwright/user-sidebar-menu-tests.spec.ts
Normal file
@ -0,0 +1,34 @@
|
||||
import { test, expect } from '@playwright/test'
|
||||
|
||||
import { setupElectron, tearDown } from './test-utils'
|
||||
|
||||
test.afterEach(async ({ page }, testInfo) => {
|
||||
await tearDown(page, testInfo)
|
||||
})
|
||||
|
||||
test.describe('Electron user sidebar menu tests', () => {
|
||||
test(
|
||||
'User settings has correct shortcut',
|
||||
{ tag: '@electron' },
|
||||
async ({ browserName }, testInfo) => {
|
||||
const { electronApp, page } = await setupElectron({
|
||||
testInfo,
|
||||
folderSetupFn: async () => {},
|
||||
})
|
||||
|
||||
await page.setViewportSize({ width: 1200, height: 500 })
|
||||
|
||||
// Open the user sidebar menu.
|
||||
await page.getByTestId('user-sidebar-toggle').click()
|
||||
|
||||
// No space after "User settings" since it's textContent.
|
||||
const text =
|
||||
process.platform === 'darwin' ? 'User settings⌘,' : 'User settingsCtrl,'
|
||||
const userSettingsButton = page.getByTestId('user-settings')
|
||||
await expect(userSettingsButton).toBeVisible()
|
||||
await expect(userSettingsButton).toHaveText(text)
|
||||
|
||||
await electronApp.close()
|
||||
}
|
||||
)
|
||||
})
|
@ -7,12 +7,29 @@ export default function usePlatform() {
|
||||
const [platformName, setPlatformName] = useState<Platform>('')
|
||||
|
||||
useEffect(() => {
|
||||
async function getPlatform() {
|
||||
setPlatformName((window.electron.platform ?? '') as Platform)
|
||||
function getPlatform(): Platform {
|
||||
const platform = window.electron.platform ?? ''
|
||||
// https://nodejs.org/api/process.html#processplatform
|
||||
switch (platform) {
|
||||
case 'darwin':
|
||||
return 'macos'
|
||||
case 'win32':
|
||||
return 'windows'
|
||||
// We don't currently care to distinguish between these.
|
||||
case 'android':
|
||||
case 'freebsd':
|
||||
case 'linux':
|
||||
case 'openbsd':
|
||||
case 'sunos':
|
||||
return 'linux'
|
||||
default:
|
||||
console.error('Unknown platform:', platform)
|
||||
return ''
|
||||
}
|
||||
}
|
||||
|
||||
if (isDesktop()) {
|
||||
void getPlatform()
|
||||
setPlatformName(getPlatform())
|
||||
} else {
|
||||
if (navigator.userAgent.indexOf('Mac') !== -1) {
|
||||
setPlatformName('macos')
|
||||
|
Reference in New Issue
Block a user