Skip to content

Commit

Permalink
deps: Upgrade Electron to v5.0.0 (#1727)
Browse files Browse the repository at this point in the history
Upgrade Electron to v5.0.0 and all dependencies necessary for them to compile and run.
Also fix issues coming from those upgrades.
  • Loading branch information
taratatach authored Oct 16, 2019
2 parents 425f1cf + adff7a9 commit 0968c7a
Show file tree
Hide file tree
Showing 14 changed files with 389 additions and 408 deletions.
115 changes: 81 additions & 34 deletions core/local/chokidar/analysis.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import type {
LocalFileDeletion,
LocalFileMove
} from './local_change'
import type { InitialScan } from './initial_scan'
*/

const log = logger({
Expand All @@ -55,12 +56,15 @@ const log = logger({

module.exports = function analysis(
events /*: LocalEvent[] */,
pendingChanges /*: LocalChange[] */
{
pendingChanges,
initialScan
} /*: { pendingChanges: LocalChange[], initialScan: ?InitialScan } */
) /*: LocalChange[] */ {
const changes /*: LocalChange[] */ = analyseEvents(events, pendingChanges)
sortBeforeSquash(changes)
squashMoves(changes)
finalSort(changes)
sortChanges(changes, initialScan != null)
return separatePendingChanges(changes, pendingChanges)
}

Expand Down Expand Up @@ -394,79 +398,118 @@ function separatePendingChanges(
return []
}

const finalSorter = (a /*: LocalChange */, b /*: LocalChange */) => {
if (a.wip && !b.wip) return -1
if (b.wip && !a.wip) return 1
const aFirst = -1
const bFirst = 1

const initialScanSorter = (a /*: LocalChange */, b /*: LocalChange */) => {
if (a.wip && !b.wip) return aFirst
if (b.wip && !a.wip) return bFirst

if (localChange.isChildAdd(a, b)) return aFirst
if (localChange.isChildAdd(b, a)) return bFirst

if (
(a.type === 'FileDeletion' || a.type === 'DirDeletion') &&
b.type !== 'FileDeletion' &&
b.type !== 'DirDeletion'
)
return bFirst
if (
(b.type === 'FileDeletion' || b.type === 'DirDeletion') &&
a.type !== 'FileDeletion' &&
a.type !== 'DirDeletion'
)
return aFirst

if (localChange.lower(localChange.addPath(a), localChange.addPath(b)))
return aFirst
if (localChange.lower(localChange.addPath(b), localChange.addPath(a)))
return bFirst
if (localChange.lower(localChange.addPath(b), localChange.updatePath(a)))
return bFirst
if (localChange.lower(localChange.addPath(a), localChange.updatePath(b)))
return aFirst

// if there isnt 2 add paths, sort by del path
if (localChange.lower(localChange.delPath(b), localChange.delPath(a)))
return aFirst

return bFirst
}

const defaultSorter = (a /*: LocalChange */, b /*: LocalChange */) => {
if (a.wip && !b.wip) return aFirst
if (b.wip && !a.wip) return bFirst

// b is deleting something which is a children of what a adds
if (
!localChange.addPath(b) &&
localChange.childOf(localChange.addPath(a), localChange.delPath(b))
)
return 1
return bFirst
// a is deleting something which is a children of what b adds
if (
!localChange.addPath(a) &&
localChange.childOf(localChange.addPath(b), localChange.delPath(a))
)
return -1
return aFirst

// b is moving something which is a children of what a adds
// b is moving something which is a child of what a adds
if (localChange.childOf(localChange.addPath(a), localChange.delPath(b)))
return -1
// a is deleting or moving something which is a children of what b adds
return aFirst
// a is deleting or moving something which is a child of what b adds
if (localChange.childOf(localChange.addPath(b), localChange.delPath(a)))
return 1
return bFirst

// if one change is a child of another, it takes priority
if (localChange.isChildAdd(a, b)) return -1
if (localChange.isChildUpdate(a, b)) return -1
if (localChange.isChildDelete(b, a)) return -1
if (localChange.isChildAdd(b, a)) return 1
if (localChange.isChildUpdate(b, a)) return 1
if (localChange.isChildDelete(a, b)) return 1
// if one change is a parent of another, it takes priority
if (localChange.isChildAdd(a, b)) return aFirst
if (localChange.isChildUpdate(a, b)) return aFirst
if (localChange.isChildDelete(b, a)) return aFirst
if (localChange.isChildAdd(b, a)) return bFirst
if (localChange.isChildUpdate(b, a)) return bFirst
if (localChange.isChildDelete(a, b)) return bFirst

// a is deleted what b added
if (localChange.delPath(a) === localChange.addPath(b)) return -1
if (localChange.delPath(a) === localChange.addPath(b)) return aFirst
// b is deleting what a added
if (localChange.delPath(b) === localChange.addPath(a)) return 1
if (localChange.delPath(b) === localChange.addPath(a)) return bFirst

// both adds at same path (seen with move + add)
if (
localChange.addPath(a) &&
localChange.addPath(a) === localChange.addPath(b)
)
return -1
return aFirst
// both deletes at same path (seen with delete + move)
if (
localChange.delPath(a) &&
localChange.delPath(a) === localChange.delPath(b)
)
return 1
return bFirst

// otherwise, order by add path
if (localChange.lower(localChange.addPath(a), localChange.addPath(b)))
return -1
return aFirst
if (localChange.lower(localChange.addPath(b), localChange.addPath(a)))
return 1
return bFirst
if (localChange.lower(localChange.updatePath(a), localChange.addPath(b)))
return -1
return aFirst
if (localChange.lower(localChange.addPath(b), localChange.updatePath(a)))
return 1
return bFirst
if (localChange.lower(localChange.addPath(a), localChange.updatePath(b)))
return -1
return aFirst
if (localChange.lower(localChange.updatePath(b), localChange.addPath(a)))
return 1
return bFirst
if (localChange.lower(localChange.updatePath(a), localChange.updatePath(b)))
return -1
return aFirst
if (localChange.lower(localChange.updatePath(b), localChange.updatePath(a)))
return 1
return bFirst

// if there isnt 2 add paths, sort by del path
if (localChange.lower(localChange.delPath(b), localChange.delPath(a)))
return -1
return aFirst

return 1
return bFirst
}

/** Final sort to ensure multiple changes at the same paths can be merged.
Expand All @@ -475,9 +518,13 @@ const finalSorter = (a /*: LocalChange */, b /*: LocalChange */) => {
*
* - Hard to change without breaking things.
*/
function finalSort(changes /*: LocalChange[] */) {
function sortChanges(
changes /*: LocalChange[] */,
isInitialScan /*: boolean */
) {
log.trace('Final sort...')
const stopMeasure = measureTime('LocalWatcher#finalSort')
changes.sort(finalSorter)
if (isInitialScan) changes.sort(initialScanSorter)
else changes.sort(defaultSorter)
stopMeasure()
}
4 changes: 2 additions & 2 deletions core/local/chokidar/local_change.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,8 @@ function delPath(a /*: LocalChange */) /*: ?string */ {
function updatePath(a /*: LocalChange */) /*: ?string */ {
return isUpdate(a) ? a.path : null
}
function childOf(p1 /*: ?string */, p2 /*: ?string */) /*: boolean */ {
return p1 != null && p2 != null && p2 !== p1 && p2.startsWith(p1 + path.sep)
function childOf(p /*: ?string */, c /*: ?string */) /*: boolean */ {
return p != null && c != null && c !== p && c.startsWith(p + path.sep)
}
function lower(p1 /*: ?string */, p2 /*: ?string */) /*: boolean */ {
return p1 != null && p2 != null && p2 !== p1 && p1 < p2
Expand Down
5 changes: 1 addition & 4 deletions core/local/chokidar/watcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,7 @@ class LocalWatcher {
)
log.trace('Done with events preparation.')

const changes /*: LocalChange[] */ = analysis(
preparedEvents,
this.pendingChanges
)
const changes /*: LocalChange[] */ = analysis(preparedEvents, this)

// TODO: Don't even acquire lock changes list is empty
// FIXME: Shouldn't we acquire the lock before preparing the events?
Expand Down
4 changes: 2 additions & 2 deletions gui/elm/Window/Tray/Dashboard.elm
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,11 @@ renderFile helpers model file =
, onClick (OpenFile file)
]
[ div [ class ("file-type file-type-" ++ file.icon) ] []
, span [ class "file-name-wrapper" ]
, span [ class "file-line-content file-name-wrapper" ]
[ span [ class "file-name-name" ] [ text basename ]
, span [ class "file-name-ext" ] [ text extname ]
]
, span [ class "file-extra" ]
, span [ class "file-line-content file-extra" ]
[ span [ class "file-time-ago" ] [ text (helpers.distance_of_time_in_words file.updated model.now) ]
, text file.path
]
Expand Down
33 changes: 15 additions & 18 deletions gui/js/onboarding.window.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ module.exports = class OnboardingWM extends WindowManager {
return {
title: 'ONBOARDING',
center: true,
'auto-hide-menu-bar': true,
width: ONBOARDING_SCREEN_WIDTH,
height: ONBOARDING_SCREEN_HEIGHT
}
Expand Down Expand Up @@ -88,30 +87,28 @@ module.exports = class OnboardingWM extends WindowManager {
// and if the user hasn't moved the window before
this.centerOnScreen(LOGIN_SCREEN_WIDTH, LOGIN_SCREEN_HEIGHT)
this.win.loadURL(url)
this.win.webContents.on(
'did-get-response-details',
(event, status, newUrl, originalUrl, httpResponseCode) => {
if (newUrl.match(/\/auth\/authorize\?/) && httpResponseCode === 200) {
session.defaultSession.webRequest.onResponseStarted(
[/\/auth\/authorize\?/],
({ statusCode }) => {
if (statusCode === 200) {
// TODO only centerOnScreen if needed to display the whole oauth screen
// and if the user hasn't moved the window before
this.centerOnScreen(OAUTH_SCREEN_WIDTH, OAUTH_SCREEN_HEIGHT)
// Unsubscribe from the event
session.defaultSession.webRequest.onResponseStarted(null)
}
}
)
this.win.webContents.on(
'did-get-redirect-request',
(event, oldUrl, newUrl) => {
if (newUrl.match('file://')) {
// TODO only centerOnScreen if needed to display the whole folder screen
// and if the user hasn't moved the window before
this.centerOnScreen(
ONBOARDING_SCREEN_WIDTH,
ONBOARDING_SCREEN_HEIGHT
)
resolveP(newUrl)
}
session.defaultSession.webRequest.onBeforeRedirect(({ redirectURL }) => {
if (redirectURL.match(/^file:\/\//)) {
// TODO only centerOnScreen if needed to display the whole folder screen
// and if the user hasn't moved the window before
this.centerOnScreen(ONBOARDING_SCREEN_WIDTH, ONBOARDING_SCREEN_HEIGHT)
resolveP(redirectURL)
// Unsubscribe from the event
session.defaultSession.webRequest.onBeforeRedirect(null)
}
)
})
return promise
}
desktop.registerRemote(cozyUrl, arg.location, onRegistered).then(
Expand Down
5 changes: 5 additions & 0 deletions gui/js/window_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,17 @@ module.exports = class WindowManager {
create() {
this.log.debug('create')
const opts = this.windowOptions()
opts.webPreferences = {
...opts.webPreferences,
nodeIntegration: true
}
// https://github.com/AppImage/AppImageKit/wiki/Bundling-Electron-apps
if (process.platform === 'linux') {
opts.icon = path.join(__dirname, '../images/icon.png')
}
this.win = new BrowserWindow({
...opts,
autoHideMenuBar: true,
show: false
})
this.win.on('unresponsive', () => {
Expand Down
45 changes: 23 additions & 22 deletions gui/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ const log = Desktop.logger({
})
process.on('uncaughtException', err => log.error(err))

const mainInstance = app.requestSingleInstanceLock()
if (!mainInstance && !process.env.COZY_DESKTOP_PROPERTY_BASED_TESTING) {
log.warn('Cozy Drive is already running. Exiting...')
app.exit()
}

let desktop
let state = 'not-configured'
let errorMessage = ''
Expand Down Expand Up @@ -67,7 +73,7 @@ const showWindowStartApp = () => {

const showWindow = bounds => {
if (revokedAlertShown || syncDirUnlinkedShown) return
if (updaterWindow.shown()) return updaterWindow.focus()
if (updaterWindow && updaterWindow.shown()) return updaterWindow.focus()
if (!desktop.config.syncPath) {
onboardingWindow.show(bounds)
// registration is done, but we need a syncPath
Expand Down Expand Up @@ -320,17 +326,13 @@ const startSync = force => {
})
}

if (!process.env.COZY_DESKTOP_PROPERTY_BASED_TESTING) {
const shouldExit = app.makeSingleInstance(() => showWindow())
if (shouldExit) {
log.warn('Cozy Drive is already running. Exiting...')
app.exit()
}
}

const dumbhash = k =>
k.split('').reduce((a, c) => ((a << 5) - a + c.charCodeAt(0)) | 0)

app.on('second-instance', () => {
showWindow()
})

app.on('ready', () => {
// Once configured and running in the tray, the app doesn't need to be
// visible anymore in macOS dock (and cmd+tab), even when the tray popover
Expand Down Expand Up @@ -368,24 +370,23 @@ app.on('ready', () => {
onboardingWindow.hide()
trayWindow.show().then(() => startSync())
})
log.trace('Setting up updater WM...')
updaterWindow = new UpdaterWM(app, desktop)
updaterWindow.onUpToDate(() => {
updaterWindow.hide()
showWindowStartApp()
})
if (process.env.COZY_DESKTOP_PROPERTY_BASED_TESTING) {
updaterWindow.hide()
showWindowStartApp()
} else {
if (app.isPackaged) {
log.trace('Setting up updater WM...')
updaterWindow = new UpdaterWM(app, desktop)
updaterWindow.onUpToDate(() => {
updaterWindow.hide()
showWindowStartApp()
})
updaterWindow.checkForUpdates()
setInterval(() => {
updaterWindow.checkForUpdates()
}, DAILY)
} else {
showWindowStartApp()
}

// Os X wants all application to have a menu
Menu.setApplicationMenu(buildAppMenu(app))
setInterval(() => {
updaterWindow.checkForUpdates()
}, DAILY)

// On OS X it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
Expand Down
Loading

0 comments on commit 0968c7a

Please sign in to comment.