Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f78d85d

Browse files
author
Akos Kitta
committedAug 9, 2022
Replaced the splash screen with a preload.
Added a bare minimum example. Closes #193 Closes #324 Closes #327 Closes #717 Closes #851 Signed-off-by: Akos Kitta <[email protected]>
1 parent 54db9bb commit f78d85d

File tree

15 files changed

+154
-432
lines changed

15 files changed

+154
-432
lines changed
 

‎.vscode/launch.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
"--no-app-auto-install",
2121
"--plugins=local-dir:../plugins",
2222
"--hosted-plugin-inspect=9339",
23-
"--nosplash",
2423
"--content-trace",
2524
"--open-devtools"
2625
],

‎arduino-ide-extension/src/electron-browser/theia/core/electron-window-module.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@ import {
66
ElectronMainWindowServiceExt,
77
electronMainWindowServiceExtPath,
88
} from '../../../electron-common/electron-main-window-service-ext';
9-
import {
10-
SplashService,
11-
splashServicePath,
12-
} from '../../../electron-common/splash-service';
139
import { ElectronWindowService } from './electron-window-service';
1410

1511
export default new ContainerModule((bind, unbind, isBound, rebind) => {
@@ -24,9 +20,4 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
2420
)
2521
)
2622
.inSingletonScope();
27-
bind(SplashService)
28-
.toDynamicValue(({ container }) =>
29-
ElectronIpcConnectionProvider.createProxy(container, splashServicePath)
30-
)
31-
.inSingletonScope();
3223
});

‎arduino-ide-extension/src/electron-browser/theia/core/electron-window-service.ts

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
1-
import {
2-
inject,
3-
injectable,
4-
postConstruct,
5-
} from '@theia/core/shared/inversify';
61
import * as remote from '@theia/core/electron-shared/@electron/remote';
7-
import { FrontendApplicationStateService } from '@theia/core/lib/browser/frontend-application-state';
82
import {
93
ConnectionStatus,
104
ConnectionStatusService,
115
} from '@theia/core/lib/browser/connection-status-service';
12-
import { ElectronWindowService as TheiaElectronWindowService } from '@theia/core/lib/electron-browser/window/electron-window-service';
13-
import { SplashService } from '../../../electron-common/splash-service';
146
import { nls } from '@theia/core/lib/common';
7+
import { ElectronWindowService as TheiaElectronWindowService } from '@theia/core/lib/electron-browser/window/electron-window-service';
8+
import {
9+
inject,
10+
injectable,
11+
postConstruct,
12+
} from '@theia/core/shared/inversify';
1513
import { WindowServiceExt } from '../../../browser/theia/core/window-service-ext';
1614
import { ElectronMainWindowServiceExt } from '../../../electron-common/electron-main-window-service-ext';
1715

@@ -23,20 +21,14 @@ export class ElectronWindowService
2321
@inject(ConnectionStatusService)
2422
private readonly connectionStatusService: ConnectionStatusService;
2523

26-
@inject(SplashService)
27-
private readonly splashService: SplashService;
28-
29-
@inject(FrontendApplicationStateService)
30-
private readonly appStateService: FrontendApplicationStateService;
31-
3224
@inject(ElectronMainWindowServiceExt)
3325
private readonly mainWindowServiceExt: ElectronMainWindowServiceExt;
3426

3527
@postConstruct()
3628
protected override init(): void {
37-
this.appStateService
38-
.reachedAnyState('initialized_layout')
39-
.then(() => this.splashService.requestClose());
29+
// NOOP
30+
// Does not listen on Theia's `window.zoomLevel` changes.
31+
// TODO: IDE2 must switch to the Theia preferences and drop the custom one.
4032
}
4133

4234
protected shouldUnload(): boolean {

‎arduino-ide-extension/src/electron-common/splash-service.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.

‎arduino-ide-extension/src/electron-main/arduino-electron-main-module.ts

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,8 @@ import {
1616
ElectronMainWindowServiceExt,
1717
electronMainWindowServiceExtPath,
1818
} from '../electron-common/electron-main-window-service-ext';
19-
import {
20-
SplashService,
21-
splashServicePath,
22-
} from '../electron-common/splash-service';
2319
import { ElectronMainWindowServiceExtImpl } from './electron-main-window-service-ext-impl';
2420
import { IDEUpdaterImpl } from './ide-updater/ide-updater-impl';
25-
import { SplashServiceImpl } from './splash/splash-service-impl';
2621
import { ElectronMainApplication } from './theia/electron-main-application';
2722
import { ElectronMainWindowServiceImpl } from './theia/electron-main-window-service';
2823
import { TheiaElectronWindow } from './theia/theia-electron-window';
@@ -34,17 +29,6 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
3429
bind(ElectronMainWindowServiceImpl).toSelf().inSingletonScope();
3530
rebind(ElectronMainWindowService).toService(ElectronMainWindowServiceImpl);
3631

37-
bind(SplashServiceImpl).toSelf().inSingletonScope();
38-
bind(SplashService).toService(SplashServiceImpl);
39-
bind(ElectronConnectionHandler)
40-
.toDynamicValue(
41-
(context) =>
42-
new JsonRpcConnectionHandler(splashServicePath, () =>
43-
context.container.get(SplashService)
44-
)
45-
)
46-
.inSingletonScope();
47-
4832
// IDE updater bindings
4933
bind(IDEUpdaterImpl).toSelf().inSingletonScope();
5034
bind(IDEUpdater).toService(IDEUpdaterImpl);

‎arduino-ide-extension/src/electron-main/splash/splash-screen.ts

Lines changed: 0 additions & 158 deletions
This file was deleted.

‎arduino-ide-extension/src/electron-main/splash/splash-service-impl.ts

Lines changed: 0 additions & 20 deletions
This file was deleted.

‎arduino-ide-extension/src/electron-main/splash/static/splash.html

Lines changed: 0 additions & 25 deletions
This file was deleted.
Binary file not shown.

‎arduino-ide-extension/src/electron-main/theia/electron-main-application.ts

Lines changed: 2 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,22 @@
1-
import { inject, injectable } from '@theia/core/shared/inversify';
1+
import { injectable } from '@theia/core/shared/inversify';
22
import {
33
app,
44
BrowserWindow,
5-
BrowserWindowConstructorOptions,
65
contentTracing,
76
ipcMain,
8-
screen,
97
Event as ElectronEvent,
108
} from '@theia/core/electron-shared/electron';
119
import { fork } from 'child_process';
1210
import { AddressInfo } from 'net';
1311
import { join, dirname } from 'path';
1412
import * as fs from 'fs-extra';
15-
import { initSplashScreen } from '../splash/splash-screen';
1613
import { MaybePromise } from '@theia/core/lib/common/types';
1714
import { ElectronSecurityToken } from '@theia/core/lib/electron-common/electron-token';
1815
import { FrontendApplicationConfig } from '@theia/application-package/lib/application-props';
1916
import {
2017
ElectronMainApplication as TheiaElectronMainApplication,
2118
ElectronMainExecutionParams,
2219
} from '@theia/core/lib/electron-main/electron-main-application';
23-
import { SplashServiceImpl } from '../splash/splash-service-impl';
2420
import { URI } from '@theia/core/shared/vscode-uri';
2521
import { Deferred } from '@theia/core/lib/common/promise-util';
2622
import * as os from '@theia/core/lib/common/os';
@@ -42,14 +38,6 @@ interface WorkspaceOptions {
4238

4339
const WORKSPACES = 'workspaces';
4440

45-
/**
46-
* Purely a dev thing. If you start the app with the `--nosplash` argument,
47-
* then you won't have the splash screen (which is always on top :confused:) and can debug the app at startup.
48-
* Note: if you start the app from VS Code with the `App (Electron)` config, the splash screen will be disabled.
49-
*/
50-
const APP_STARTED_WITH_NOSPLASH =
51-
typeof process !== 'undefined' && process.argv.indexOf('--nosplash') !== -1;
52-
5341
/**
5442
* If the app is started with `--open-devtools` argument, the `Dev Tools` will be opened.
5543
*/
@@ -70,9 +58,6 @@ export class ElectronMainApplication extends TheiaElectronMainApplication {
7058
private _firstWindowId: number | undefined;
7159
private openFilePromise = new Deferred();
7260

73-
@inject(SplashServiceImpl)
74-
private readonly splashService: SplashServiceImpl;
75-
7661
override async start(config: FrontendApplicationConfig): Promise<void> {
7762
// Explicitly set the app name to have better menu items on macOS. ("About", "Hide", and "Quit")
7863
// See: https://github.com/electron-userland/electron-builder/issues/2468
@@ -289,69 +274,10 @@ export class ElectronMainApplication extends TheiaElectronMainApplication {
289274
super.onSecondInstance(event, argv, cwd);
290275
}
291276

292-
/**
293-
* Use this rather than creating `BrowserWindow` instances from scratch, since some security parameters need to be set, this method will do it.
294-
*
295-
* @param options
296-
*/
297277
override async createWindow(
298278
asyncOptions: MaybePromise<TheiaBrowserWindowOptions> = this.getDefaultTheiaWindowOptions()
299279
): Promise<BrowserWindow> {
300-
let options = await asyncOptions;
301-
options = this.avoidOverlap(options);
302-
let electronWindow: BrowserWindow | undefined;
303-
if (this.windows.size || APP_STARTED_WITH_NOSPLASH) {
304-
electronWindow = await this.doCreateWindow(options);
305-
} else {
306-
const { bounds } = screen.getDisplayNearestPoint(
307-
screen.getCursorScreenPoint()
308-
);
309-
const splashHeight = 450;
310-
const splashWidth = 600;
311-
const splashY = Math.floor(bounds.y + (bounds.height - splashHeight) / 2);
312-
const splashX = Math.floor(bounds.x + (bounds.width - splashWidth) / 2);
313-
const splashScreenOpts: BrowserWindowConstructorOptions = {
314-
height: splashHeight,
315-
width: splashWidth,
316-
x: splashX,
317-
y: splashY,
318-
transparent: true,
319-
alwaysOnTop: true,
320-
focusable: false,
321-
minimizable: false,
322-
maximizable: false,
323-
hasShadow: false,
324-
resizable: false,
325-
};
326-
electronWindow = await initSplashScreen(
327-
{
328-
windowOpts: options,
329-
templateUrl: join(
330-
__dirname,
331-
'..',
332-
'..',
333-
'..',
334-
'src',
335-
'electron-main',
336-
'splash',
337-
'static',
338-
'splash.html'
339-
),
340-
delay: 0,
341-
minVisible: 2000,
342-
splashScreenOpts,
343-
},
344-
(windowOptions) => this.doCreateWindow(windowOptions),
345-
this.splashService.onCloseRequested
346-
);
347-
}
348-
return electronWindow;
349-
}
350-
351-
private async doCreateWindow(
352-
options: TheiaBrowserWindowOptions
353-
): Promise<BrowserWindow> {
354-
const electronWindow = await super.createWindow(options);
280+
const electronWindow = await super.createWindow(asyncOptions);
355281
if (APP_STARTED_WITH_DEV_TOOLS) {
356282
electronWindow.webContents.openDevTools();
357283
}

‎electron-app/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
},
6262
"generator": {
6363
"config": {
64-
"preloadTemplate": "<div class='theia-preload' style='background-color: rgb(237, 241, 242);'></div>"
64+
"preloadTemplate": "./resources/preload.html"
6565
}
6666
}
6767
}

‎electron-app/resources/preload.html

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
<html>
2+
3+
<head>
4+
<style>
5+
:root {
6+
--arduino-color: #008184;
7+
}
8+
9+
/* The colors are hard-coded and based on the `editor.background` and `editor.foreground` values from `./arduino-ide-extension/src/browser/data/default.color-theme.json` */
10+
@media (prefers-color-scheme: light) {
11+
html {
12+
background: #ffffff;
13+
}
14+
}
15+
16+
/* The colors are hard-coded and based on the `editor.background` and `editor.foreground` values from `./arduino-ide-extension/src/browser/data/dark.color-theme.json` */
17+
@media (prefers-color-scheme: dark) {
18+
html {
19+
background: #1f272a;
20+
}
21+
}
22+
23+
.theia-preload {
24+
position: absolute;
25+
top: 0;
26+
left: 0;
27+
right: 0;
28+
bottom: 0;
29+
30+
/* Above styles copied from https://github.com/eclipse-theia/theia/blob/5aeef6c0c683b4e91713ab736957e6655b486adc/packages/core/src/browser/style/index.css#L147-L161 */
31+
/* Otherwise, there is a flickering when Theia's CSS loads. */
32+
33+
background-image: none;
34+
}
35+
36+
.theia-preload::after {
37+
/* remove default loading animation */
38+
content: none;
39+
}
40+
41+
.spinner-container {
42+
display: flex;
43+
flex-direction: center;
44+
align-self: center;
45+
justify-content: center;
46+
height: 100vh;
47+
width: 100vw;
48+
}
49+
50+
.custom-spinner {
51+
align-self: center;
52+
}
53+
54+
#logo-arduino {
55+
position: absolute;
56+
left: calc(50% - 100px);
57+
}
58+
59+
.plus,
60+
.minus {
61+
fill: var(--arduino-color);
62+
}
63+
64+
.loop {
65+
fill: none;
66+
stroke: var(--arduino-color);
67+
stroke-miterlimit: 10;
68+
stroke-width: 72.11px;
69+
stroke-dasharray: 2500;
70+
stroke-dashoffset: 2500;
71+
animation: dash 2.3s ease-in-out infinite;
72+
}
73+
74+
@keyframes dash {
75+
from {
76+
stroke-dashoffset: 5000;
77+
}
78+
79+
to {
80+
stroke-dashoffset: 2000;
81+
}
82+
83+
to {
84+
stroke-dashoffset: 0;
85+
}
86+
}
87+
</style>
88+
89+
</head>
90+
91+
<body>
92+
<div class='spinner-container'>
93+
<div class='custom-spinner'>
94+
<svg id="arduino-logo" xmlns="http://www.w3.org/2000/svg" width="200px" height="100%"
95+
viewBox="0 0 821.27 566.24">
96+
<g id="traccia-loop">
97+
<path class="loop"
98+
d="M960,449.62l-28,50.66c-29.35,43.15-79.66,96.78-152.66,107.26a188.26,188.26,0,0,1-26.14,1.78c-92,0-166.78-71.64-166.78-159.7s74.86-159.7,166.87-159.7a180.62,180.62,0,0,1,26,1.83c65.21,9.3,112.32,53,142.56,93a213.75,213.75,0,0,1,16.52,25.65l45.53,82.31A158.69,158.69,0,0,0,994,508.77c29.92,41.4,78.28,89,146.55,98.76a189.83,189.83,0,0,0,26.26,1.79c92,0,166.77-71.64,166.77-159.7s-74.85-159.7-166.86-159.7a183.49,183.49,0,0,0-26.1,1.84c-73,10.42-123.26,64-152.54,107.09L960,449.62"
99+
transform="translate(-550.35 -252.49)" />
100+
</g>
101+
<g id="minus" data-name="-">
102+
<rect class="minus" x="143.14" y="178.03" width="121.88" height="39.29" />
103+
</g>
104+
<g id="plus" data-name="+">
105+
<polygon class="plus"
106+
points="630.62 217.32 671.82 217.32 671.82 178.03 630.62 178.03 630.62 136.7 591.24 136.7 591.24 178.03 549.97 178.03 549.97 217.32 591.24 217.32 591.24 258.65 630.62 258.65 630.62 217.32" />
107+
</g>
108+
</svg>
109+
</div>
110+
</div>
111+
</body>
112+
113+
</html>

‎electron/.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,8 @@ dist/
1515
electron-builder.env
1616

1717
# The generated `package.json` under the `build` folder.
18-
build/package.json
18+
build/package.json
19+
20+
# Resources the packager copies from dev to prod
21+
build/resources/preload.html
22+
build/patch/frontend/index.js

‎electron/build/patch/frontend/index.js

Lines changed: 0 additions & 100 deletions
This file was deleted.

‎electron/packager/index.js

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@
77
const glob = require('glob');
88
const isCI = require('is-ci');
99
shell.env.THEIA_ELECTRON_SKIP_REPLACE_FFMPEG = '1'; // Do not run the ffmpeg validation for the packager.
10+
// Note, this will crash on PI if the available memory is less than desired heap size.
11+
// https://github.com/shelljs/shelljs/issues/1024#issuecomment-1001552543
1012
shell.env.NODE_OPTIONS = '--max_old_space_size=4096'; // Increase heap size for the CI
1113
shell.env.PUPPETEER_SKIP_CHROMIUM_DOWNLOAD = 'true'; // Skip download and avoid `ERROR: Failed to download Chromium`.
1214
const template = require('./config').generateTemplate(
1315
new Date().toISOString()
1416
);
1517
const utils = require('./utils');
1618
const merge = require('deepmerge');
17-
const { isRelease, isElectronPublish, getChannelFile } = utils;
19+
const { isRelease, getChannelFile } = utils;
1820
const { version } = template;
1921
const { productName } = template.build;
2022

@@ -58,6 +60,11 @@
5860
.filter((filename) => resourcesToKeep.indexOf(filename) === -1)
5961
.forEach((filename) => rm('-rf', path('..', 'build', filename)));
6062

63+
// Clean up the `./electron/build/patch` and `./electron/build/resources` folder with Git.
64+
// To avoid file duplication between bundled app and dev mode, some files are copied from `./electron-app` to `./electron/build` folder.
65+
const foldersToSyncFromDev = ['patch', 'resources'];
66+
foldersToSyncFromDev.forEach(filename => shell.exec(`git -C ${path('..', 'build', filename)} clean -ffxdq`, { async: false }));
67+
6168
const extensions = require('./extensions.json');
6269
echo(
6370
`Building the application with the following extensions:\n${extensions
@@ -70,20 +77,28 @@
7077
// Copy the following items into the `working-copy` folder. Make sure to reuse the `yarn.lock`. |
7178
//----------------------------------------------------------------------------------------------+
7279
mkdir('-p', path('..', workingCopy));
73-
for (const name of [
80+
for (const filename of [
7481
...allDependencies,
7582
'yarn.lock',
7683
'package.json',
7784
'lerna.json',
7885
'i18n'
7986
]) {
80-
cp('-rf', path(rootPath, name), path('..', workingCopy));
87+
cp('-rf', path(rootPath, filename), path('..', workingCopy));
88+
}
89+
90+
//---------------------------------------------------------------------------------------------+
91+
// Copy the patched `index.js` for the frontend, the Theia preload, etc. from `./electron-app` |
92+
//---------------------------------------------------------------------------------------------+
93+
for (const filename of foldersToSyncFromDev) {
94+
cp('-rf', path('..', workingCopy, 'electron-app', filename), path('..', 'build'));
8195
}
8296

8397
//----------------------------------------------+
8498
// Sanity check: all versions must be the same. |
8599
//----------------------------------------------+
86100
verifyVersions(allDependencies);
101+
87102
//----------------------------------------------------------------------+
88103
// Use the nightly patch version if not a release but requires publish. |
89104
//----------------------------------------------------------------------+
@@ -438,6 +453,12 @@ ${fs.readFileSync(path('..', 'build', 'package.json')).toString()}
438453
}
439454
}
440455

456+
/**
457+
* @param {import('fs').PathLike} file
458+
* @param {string|undefined} [algorithm="sha512"]
459+
* @param {BufferEncoding|undefined} [encoding="base64"]
460+
* @param {object|undefined} [options]
461+
*/
441462
async function hashFile(
442463
file,
443464
algorithm = 'sha512',

0 commit comments

Comments
 (0)
Please sign in to comment.