Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 1 addition & 19 deletions app/utilities/auth/githubOAuth.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const GITHUB_OAUTH_URL = 'https://github.com/login/oauth/authorize'
const ELECTRON_ABORTED_LOAD_ERROR_CODE = -3
const WINDOWS_GITHUB_OAUTH_DISABLED_CHROMIUM_FEATURES = ['RendererCodeIntegrity']

function normalizeScopes (scopes = []) {
if (Array.isArray(scopes)) {
Expand Down Expand Up @@ -100,20 +99,6 @@ function shouldIgnoreGitHubOAuthLoadFailure ({
return isAbortedLoadError(errorCode, errorDescription) || isMainFrame === false
}

function shouldSandboxGitHubOAuthWindow (platform = process.platform) {
return platform !== 'win32'
}

function shouldDisableGitHubOAuthHardwareAccelerationWorkaround (platform = process.platform) {
return platform === 'win32'
}

function getGitHubOAuthDisabledChromiumFeaturesWorkaround (platform = process.platform) {
if (platform !== 'win32') return []

return WINDOWS_GITHUB_OAUTH_DISABLED_CHROMIUM_FEATURES.slice()
}

function isAbortedLoadError (errorCode, errorDescription) {
return Number(errorCode) === ELECTRON_ABORTED_LOAD_ERROR_CODE ||
/\bERR_ABORTED\b|\(-3\)/.test(String(errorDescription || ''))
Expand All @@ -132,8 +117,5 @@ module.exports = {
buildGitHubOAuthUrl,
describeGitHubOAuthUrl,
parseGitHubOAuthCallback,
shouldIgnoreGitHubOAuthLoadFailure,
shouldDisableGitHubOAuthHardwareAccelerationWorkaround,
getGitHubOAuthDisabledChromiumFeaturesWorkaround,
shouldSandboxGitHubOAuthWindow
shouldIgnoreGitHubOAuthLoadFailure
}
16 changes: 7 additions & 9 deletions configs/electronLanguages.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
const scriptSpecificChineseResourceSuffixes = {
Hans: [67, 78],
Hant: [84, 87]
// Electron packages Chromium locale resources by .pak filename, which does not
// always match Lepton's app-facing locale id.
const electronLanguageOverrides = {
en: 'en-US',
'zh-Hans': 'zh-CN',
'zh-Hant': 'zh-TW'
}

function toElectronLanguage (locale) {
const [language, script] = locale.split('-')
const resourceSuffix = scriptSpecificChineseResourceSuffixes[script]

return resourceSuffix
? [language, String.fromCharCode(...resourceSuffix)].join('_')
: locale
return electronLanguageOverrides[locale] || locale
}

function getElectronLanguages (supportedLocales) {
Expand Down
29 changes: 2 additions & 27 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,14 @@ const {
buildGitHubOAuthUrl,
describeGitHubOAuthUrl,
parseGitHubOAuthCallback,
shouldIgnoreGitHubOAuthLoadFailure,
shouldDisableGitHubOAuthHardwareAccelerationWorkaround,
getGitHubOAuthDisabledChromiumFeaturesWorkaround,
shouldSandboxGitHubOAuthWindow
shouldIgnoreGitHubOAuthLoadFailure
} = require('./app/utilities/auth/githubOAuth')
const {
clearGitHubAuthWindowStorageAndDestroy
} = require('./app/utilities/auth/githubAuthWindow')
const { applyDefaultZoomPercent } = require('./app/utilities/zoom')

const logger = createMainLogger()
applyGitHubOAuthRenderWorkarounds()
const electronLocalStorage = createElectronLocalStorage({
getUserDataPath: () => app.getPath('userData')
})
Expand Down Expand Up @@ -86,25 +82,6 @@ const MACOS_TRAY_ICON_SIZE = 18

const shortcuts = nconf.get('shortcuts')

function applyGitHubOAuthRenderWorkarounds () {
const disableHardwareAcceleration = shouldDisableGitHubOAuthHardwareAccelerationWorkaround(process.platform)
const disabledChromiumFeatures = getGitHubOAuthDisabledChromiumFeaturesWorkaround(process.platform)
if (!disableHardwareAcceleration && disabledChromiumFeatures.length === 0) return

if (disabledChromiumFeatures.length > 0) {
app.commandLine.appendSwitch('disable-features', disabledChromiumFeatures.join(','))
}

if (disableHardwareAcceleration) {
app.disableHardwareAcceleration()
}

logger.info('[auth] Applied Electron render workarounds for Windows GitHub OAuth: ' + JSON.stringify({
disabledChromiumFeatures,
hardwareAccelerationDisabled: disableHardwareAcceleration
}))
}

function getConfigPath() {
if (process && process.env && process.env.XDG_CONFIG_HOME) {
return path.join(process.env.XDG_CONFIG_HOME, '.leptonrc')
Expand Down Expand Up @@ -727,7 +704,6 @@ function startGitHubAuthFlow ({ clientId, scopes } = {}) {
})
}

const sandboxAuthWindow = shouldSandboxGitHubOAuthWindow(process.platform)
const authWindow = new BrowserWindow({
parent: mainWindow,
width: 400,
Expand All @@ -737,7 +713,7 @@ function startGitHubAuthFlow ({ clientId, scopes } = {}) {
nodeIntegration: false,
enableRemoteModule: false,
contextIsolation: true,
sandbox: sandboxAuthWindow,
sandbox: true,
spellcheck: false
}
})
Expand All @@ -763,7 +739,6 @@ function startGitHubAuthFlow ({ clientId, scopes } = {}) {
hasClientId: Boolean(clientId),
clientIdLength: clientId.length,
scopeCount: Array.isArray(scopes) ? scopes.length : 0,
sandbox: sandboxAuthWindow,
authorizeUrl: describeGitHubOAuthUrl(authUrl)
}))

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Lepton",
"version": "2.0.0-beta.8",
"version": "2.0.0-beta.14",
"description": "Democratizing Code Snippets Management (macOS/Win/Linux)",
"productName": "Lepton",
"main": "main.js",
Expand Down
24 changes: 1 addition & 23 deletions tests/utilities/githubOAuth.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ const {
buildGitHubOAuthUrl,
describeGitHubOAuthUrl,
parseGitHubOAuthCallback,
shouldIgnoreGitHubOAuthLoadFailure,
shouldDisableGitHubOAuthHardwareAccelerationWorkaround,
getGitHubOAuthDisabledChromiumFeaturesWorkaround,
shouldSandboxGitHubOAuthWindow
shouldIgnoreGitHubOAuthLoadFailure
} = githubOAuth

describe('GitHub OAuth utility', () => {
Expand Down Expand Up @@ -101,23 +98,4 @@ describe('GitHub OAuth utility', () => {
isMainFrame: true
})).toBe(false)
})

it('uses a non-sandboxed OAuth auth window on Windows', () => {
expect(shouldSandboxGitHubOAuthWindow('win32')).toBe(false)
expect(shouldSandboxGitHubOAuthWindow('darwin')).toBe(true)
expect(shouldSandboxGitHubOAuthWindow('linux')).toBe(true)
})

it('disables hardware acceleration only for the Windows OAuth rendering workaround', () => {
expect(shouldDisableGitHubOAuthHardwareAccelerationWorkaround('win32')).toBe(true)
expect(shouldDisableGitHubOAuthHardwareAccelerationWorkaround('darwin')).toBe(false)
expect(shouldDisableGitHubOAuthHardwareAccelerationWorkaround('linux')).toBe(false)
})

it('disables Chromium renderer code integrity only for the Windows OAuth rendering workaround', () => {
expect(getGitHubOAuthDisabledChromiumFeaturesWorkaround('win32'))
.toEqual(['RendererCodeIntegrity'])
expect(getGitHubOAuthDisabledChromiumFeaturesWorkaround('darwin')).toEqual([])
expect(getGitHubOAuthDisabledChromiumFeaturesWorkaround('linux')).toEqual([])
})
})
21 changes: 18 additions & 3 deletions tests/utilities/i18n.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,28 @@ describe('i18n utilities', () => {
expect(builderConfig.electronLanguages).toEqual(getElectronLanguages(getSupportedLocales()))
})

it('maps script-specific Chinese locales to Electron resource names', () => {
it('maps app locales to Electron resource names', () => {
expect(getElectronLanguages([
{ code: 'en' },
{ code: 'zh-Hans' },
{ code: 'zh-Hant' }
])).toEqual([
['zh', String.fromCharCode(67, 78)].join('_'),
['zh', String.fromCharCode(84, 87)].join('_')
'en-US',
'zh-CN',
'zh-TW'
])
})

it('maps every supported locale to the expected Electron resource names', () => {
expect(getElectronLanguages(getSupportedLocales())).toEqual([
'en-US',
'es',
'fr',
'ja',
'ko',
'tr',
'zh-CN',
'zh-TW'
])
})

Expand Down
Loading