-
Notifications
You must be signed in to change notification settings - Fork 321
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cloud/desktop mode switcher #6448
Changes from all commits
3cf7185
810615d
1970caf
4806ff3
1fce405
df4487e
efa3e1a
d0ddd31
857a36c
a967203
2a1ee22
b412c46
aaad9e0
eb53552
b1653ef
56a2579
5c2b112
25d0a1c
a2b8c16
29e336b
889e9db
db4c776
4bc378d
522562c
e0fd0b6
bb9730b
09ca400
4c56e7d
5e1a29d
db2aecc
bb6530f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,6 @@ import * as authentication from 'enso-authentication' | |
import * as contentConfig from 'enso-content-config' | ||
|
||
import * as app from '../../../../../target/ensogl-pack/linked-dist/index' | ||
import * as projectManager from './project_manager' | ||
import GLOBAL_CONFIG from '../../../../gui/config.yaml' assert { type: 'yaml' } | ||
|
||
const logger = app.log.logger | ||
|
@@ -119,15 +118,26 @@ function displayDeprecatedVersionDialog() { | |
} | ||
|
||
// ======================== | ||
// === Main Entry Point === | ||
// === Main entry point === | ||
// ======================== | ||
|
||
interface StringConfig { | ||
[key: string]: StringConfig | string | ||
} | ||
|
||
class Main { | ||
async main(inputConfig: StringConfig) { | ||
class Main implements AppRunner { | ||
app: app.App | null = null | ||
|
||
stopApp() { | ||
this.app?.stop() | ||
} | ||
|
||
async runApp(inputConfig?: StringConfig) { | ||
this.stopApp() | ||
|
||
/** FIXME: https://github.com/enso-org/enso/issues/6475 | ||
* Default values names are out of sync with values used in code. | ||
* Rather than setting fixed values here we need to fix default values in config. */ | ||
const config = Object.assign( | ||
{ | ||
loader: { | ||
|
@@ -139,7 +149,7 @@ class Main { | |
inputConfig | ||
) | ||
|
||
const appInstance = new app.App({ | ||
this.app = new app.App({ | ||
config, | ||
configOptions: contentConfig.OPTIONS, | ||
packageInfo: { | ||
|
@@ -148,75 +158,84 @@ class Main { | |
}, | ||
}) | ||
|
||
if (appInstance.initialized) { | ||
if (!this.app.initialized) { | ||
console.error('Failed to initialize the application.') | ||
} else { | ||
if (contentConfig.OPTIONS.options.dataCollection.value) { | ||
// TODO: Add remote-logging here. | ||
} | ||
if (!(await checkMinSupportedVersion(contentConfig.OPTIONS))) { | ||
displayDeprecatedVersionDialog() | ||
} else { | ||
if ( | ||
(contentConfig.OPTIONS.options.authentication.value || | ||
contentConfig.OPTIONS.groups.featurePreview.options.newDashboard.value) && | ||
contentConfig.OPTIONS.groups.startup.options.entry.value === | ||
contentConfig.OPTIONS.groups.startup.options.entry.default | ||
) { | ||
const hideAuth = () => { | ||
const auth = document.getElementById('dashboard') | ||
const ide = document.getElementById('root') | ||
if (auth) auth.style.display = 'none' | ||
if (ide) ide.style.display = '' | ||
} | ||
/** This package is an Electron desktop app (i.e., not in the Cloud), so | ||
* we're running on the desktop. */ | ||
/** TODO [NP]: https://github.com/enso-org/cloud-v2/issues/345 | ||
* `content` and `dashboard` packages **MUST BE MERGED INTO ONE**. The IDE | ||
* should only have one entry point. Right now, we have two. One for the cloud | ||
* and one for the desktop. Once these are merged, we can't hardcode the | ||
* platform here, and need to detect it from the environment. */ | ||
const platform = authentication.Platform.desktop | ||
/** FIXME [PB]: https://github.com/enso-org/cloud-v2/issues/366 | ||
* React hooks rerender themselves multiple times. It is resulting in multiple | ||
* Enso main scene being initialized. As a temporary workaround we check whether | ||
* appInstance was already ran. Target solution should move running appInstance | ||
* where it will be called only once. */ | ||
let appInstanceRan = false | ||
const onAuthenticated = () => { | ||
if ( | ||
!contentConfig.OPTIONS.groups.featurePreview.options.newDashboard.value | ||
) { | ||
hideAuth() | ||
if (!appInstanceRan) { | ||
appInstanceRan = true | ||
void appInstance.run() | ||
} | ||
} | ||
} | ||
authentication.run({ | ||
logger, | ||
platform, | ||
projectManager: projectManager.ProjectManager.default(), | ||
showDashboard: | ||
contentConfig.OPTIONS.groups.featurePreview.options.newDashboard.value, | ||
onAuthenticated, | ||
}) | ||
} else { | ||
void appInstance.run() | ||
} | ||
const email = contentConfig.OPTIONS.groups.authentication.options.email.value | ||
// The default value is `""`, so a truthiness check is most appropriate here. | ||
if (email) { | ||
logger.log(`User identified as '${email}'.`) | ||
} | ||
void this.app.run() | ||
} | ||
} | ||
} | ||
|
||
main(inputConfig?: StringConfig) { | ||
contentConfig.OPTIONS.loadAll([app.urlParams()]) | ||
const isUsingAuthentication = contentConfig.OPTIONS.options.authentication.value | ||
const isUsingNewDashboard = | ||
contentConfig.OPTIONS.groups.featurePreview.options.newDashboard.value | ||
const isOpeningMainEntryPoint = | ||
contentConfig.OPTIONS.groups.startup.options.entry.value === | ||
contentConfig.OPTIONS.groups.startup.options.entry.default | ||
if ((isUsingAuthentication || isUsingNewDashboard) && isOpeningMainEntryPoint) { | ||
const hideAuth = () => { | ||
const auth = document.getElementById('dashboard') | ||
const ide = document.getElementById('root') | ||
if (auth) { | ||
auth.style.display = 'none' | ||
} | ||
if (ide) { | ||
ide.hidden = false | ||
} | ||
} | ||
/** This package is an Electron desktop app (i.e., not in the Cloud), so | ||
* we're running on the desktop. */ | ||
/** TODO [NP]: https://github.com/enso-org/cloud-v2/issues/345 | ||
* `content` and `dashboard` packages **MUST BE MERGED INTO ONE**. The IDE | ||
* should only have one entry point. Right now, we have two. One for the cloud | ||
* and one for the desktop. */ | ||
const currentPlatform = contentConfig.OPTIONS.groups.startup.options.platform.value | ||
let platform = authentication.Platform.desktop | ||
if (currentPlatform === 'web') { | ||
platform = authentication.Platform.cloud | ||
} | ||
/** FIXME [PB]: https://github.com/enso-org/cloud-v2/issues/366 | ||
* React hooks rerender themselves multiple times. It is resulting in multiple | ||
* Enso main scene being initialized. As a temporary workaround we check whether | ||
* appInstance was already ran. Target solution should move running appInstance | ||
* where it will be called only once. */ | ||
let appInstanceRan = false | ||
const onAuthenticated = () => { | ||
if (!contentConfig.OPTIONS.groups.featurePreview.options.newDashboard.value) { | ||
hideAuth() | ||
if (!appInstanceRan) { | ||
appInstanceRan = true | ||
void this.runApp(inputConfig) | ||
} | ||
} | ||
} | ||
authentication.run({ | ||
appRunner: this, | ||
logger, | ||
platform, | ||
showDashboard: | ||
contentConfig.OPTIONS.groups.featurePreview.options.newDashboard.value, | ||
onAuthenticated, | ||
}) | ||
} else { | ||
console.error('Failed to initialize the application.') | ||
void this.runApp(inputConfig) | ||
} | ||
} | ||
} | ||
|
||
const API = new Main() | ||
|
||
// @ts-expect-error `globalConfig.windowAppScopeName` is not known at typecheck time. | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access | ||
window[GLOBAL_CONFIG.windowAppScopeName] = API | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What happened with this line? We are accessing the JS app from Rust via this variable. Why was it deleted? Was it moved somewhere? Such changes as this should be very clearly explained as they can break a lot of things. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. might be good to add a comment about this needing to be exposed to Rust There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @wdanilo are you sure that rust uses this global? this assignes Main to App also expose There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh yeah - the initial commit (the revert commit) already had the global removed so all QAs seemed to work fine without the global. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please, never remove lines that you are not 100% sure can be removed. If you want to refactor such a code, the PR description should have a very explicit information about it, so reviewers can be extra careful when checking this place. This removed line was used in Rust in several places, so this change was introducing regression. |
||
window[GLOBAL_CONFIG.windowAppScopeName] = new Main() |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just FYI @somebody1234 as you've been writing about it earlier. The fact that
loadAll
mutates the options rather than returning a new object containing them is wrong and it's so because when I was writing that I was unable to code that correctly in TS. However, some day we shiould change it to an immutable API.