Skip to content

Commit

Permalink
[core] Add and use application name
Browse files Browse the repository at this point in the history
Add customizable application name.
Display application name when no workspace is opened, instead of showing
the URL. It was particulary bad on Electron.

Also removes native menus when creating a new Electron BrowserWindow, which
will be re-added by the application when ready.

Signed-off-by: marechal-p <paul.marechal@ericsson.com>
  • Loading branch information
paul-marechal committed Nov 13, 2018
1 parent df3dd2c commit 1afd575
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## v0.3.17
- [plug-in] added `languages.registerCodeLensProvider` Plug-in API
- [core] `ctrl+alt+a` and `ctrl+alt+d` to switch tabs left/right
- [core] added `theia.applicationName` to application `package.json` and improved window title


## v0.3.16
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,19 +104,21 @@ process.env.LC_NUMERIC = 'C';
const { join } = require('path');
const { isMaster } = require('cluster');
const { fork } = require('child_process');
const { app, BrowserWindow, ipcMain } = require('electron');
const { app, BrowserWindow, ipcMain, Menu } = require('electron');
const applicationName = \`${this.pck.props.frontend.config.applicationName}\`;
const windows = [];
function createNewWindow(theUrl) {
const newWindow = new BrowserWindow({ width: 1024, height: 728, show: !!theUrl });
const newWindow = new BrowserWindow({ width: 1024, height: 728, show: !!theUrl, title: applicationName });
if (windows.length === 0) {
newWindow.webContents.on('new-window', (event, url, frameName, disposition, options) => {
// If the first electron window isn't visible, then all other new windows will remain invisible.
// https://github.com/electron/electron/issues/3751
options.show = true;
options.width = 1024;
options.height = 728;
options.title = applicationName;
});
}
windows.push(newWindow);
Expand Down Expand Up @@ -147,6 +149,9 @@ if (isMaster) {
createNewWindow(url);
});
app.on('ready', () => {
// Remove the default electron menus, waiting for the application to set its own.
Menu.setApplicationMenu(null);
// Check whether we are in bundled application or development mode.
// @ts-ignore
const devMode = process.defaultApp || /node_modules[\/]electron[\/]/.test(process.execPath);
Expand Down
9 changes: 8 additions & 1 deletion dev-packages/application-package/src/application-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ export namespace ApplicationProps {
config: {}
},
frontend: {
config: {}
config: {
applicationName: 'Theia'
}
}
};

Expand All @@ -93,6 +95,11 @@ export interface FrontendApplicationConfig extends ApplicationConfig {
*/
readonly defaultTheme?: string;

/**
* The name of the application. `Theia` by default.
*/
readonly applicationName: string;

}

/**
Expand Down
7 changes: 7 additions & 0 deletions examples/browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
"private": true,
"name": "@theia/example-browser",
"version": "0.3.16",
"theia": {
"frontend": {
"config": {
"applicationName": "Theia Browser Example"
}
}
},
"dependencies": {
"@theia/callhierarchy": "^0.3.16",
"@theia/console": "^0.3.16",
Expand Down
7 changes: 6 additions & 1 deletion examples/electron/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
"name": "@theia/example-electron",
"version": "0.3.16",
"theia": {
"target": "electron"
"target": "electron",
"frontend": {
"config": {
"applicationName": "Theia Electron Example"
}
}
},
"dependencies": {
"@theia/callhierarchy": "^0.3.16",
Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/common/application-protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ export interface ApplicationServer {
}

export interface ExtensionInfo {
name: string;
version: string;
readonly name: string;
readonly version: string;
}

export interface ApplicationInfo {
name: string;
version: string;
readonly name: string;
readonly version: string;
}
2 changes: 2 additions & 0 deletions packages/preferences/src/browser/preference-service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
********************************************************************************/

// tslint:disable:no-unused-expression
// tslint:disable:no-any

import { enableJSDOM } from '@theia/core/lib/browser/test/jsdom';

Expand Down Expand Up @@ -46,6 +47,7 @@ import { MockWorkspaceServer } from '@theia/workspace/lib/common/test/mock-works
import { MockWindowService } from '@theia/core/lib/browser/window/test/mock-window-service';
import { WorkspaceService } from '@theia/workspace/lib/browser/workspace-service';
import { WorkspacePreferences, createWorkspacePreferences } from '@theia/workspace/lib/browser/workspace-preferences';
import { ApplicationServer } from '@theia/core/lib/common/application-protocol';
import * as sinon from 'sinon';
import URI from '@theia/core/lib/common/uri';

Expand Down
19 changes: 14 additions & 5 deletions packages/workspace/src/browser/workspace-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { injectable, inject, postConstruct } from 'inversify';
import URI from '@theia/core/lib/common/uri';
import { FileSystem, FileStat } from '@theia/filesystem/lib/common';
import { FileSystemWatcher, FileChangeEvent } from '@theia/filesystem/lib/browser/filesystem-watcher';
import { ApplicationServer } from '@theia/core/lib/common/application-protocol';
import { WorkspaceServer } from '../common';
import { WindowService } from '@theia/core/lib/browser/window/window-service';
import { FrontendApplication, FrontendApplicationContribution } from '@theia/core/lib/browser';
Expand All @@ -26,6 +27,7 @@ import { ILogger, Disposable, DisposableCollection, Emitter, Event } from '@thei
import { WorkspacePreferences } from './workspace-preferences';
import * as jsoncparser from 'jsonc-parser';
import * as Ajv from 'ajv';
import { FrontendApplicationConfigProvider } from '@theia/core/lib/browser/frontend-application-config-provider';

export const THEIA_EXT = 'theia-workspace';
export const VSCODE_EXT = 'code-workspace';
Expand Down Expand Up @@ -64,6 +66,8 @@ export class WorkspaceService implements FrontendApplicationContribution {
@inject(WorkspacePreferences)
protected preferences: WorkspacePreferences;

protected applicationName = FrontendApplicationConfigProvider.get().applicationName;

@postConstruct()
protected async init(): Promise<void> {
const workspaceUri = await this.server.getMostRecentlyUsedWorkspace();
Expand Down Expand Up @@ -168,19 +172,24 @@ export class WorkspaceService implements FrontendApplicationContribution {
}
}

protected updateTitle(): void {
protected formatTitle(title?: string): string {
const name = this.applicationName;
return title ? `${title}${name}` : name;
}

protected updateTitle() {
let title: string | undefined;
if (this._workspace) {
const uri = new URI(this._workspace.uri);
const displayName = uri.displayName;
if (!this._workspace.isDirectory &&
(displayName.endsWith(`.${THEIA_EXT}`) || displayName.endsWith(`.${VSCODE_EXT}`))) {
document.title = displayName.slice(0, displayName.lastIndexOf('.'));
title = displayName.slice(0, displayName.lastIndexOf('.'));
} else {
document.title = displayName;
title = displayName;
}
} else {
document.title = window.location.href;
}
document.title = this.formatTitle(title);
}

/**
Expand Down

0 comments on commit 1afd575

Please sign in to comment.