This commit is contained in:
João Moreno 2020-02-14 11:10:34 +01:00 committed by GitHub
parent 8bac008949
commit 7bc12be746
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 51 additions and 29 deletions

View file

@ -127,39 +127,41 @@ export class ProductContribution implements IWorkbenchContribution {
@IHostService hostService: IHostService,
@IProductService productService: IProductService
) {
if (!hostService.hasFocus) {
return;
}
hostService.hadLastFocus().then(hadLastFocus => {
if (!hadLastFocus) {
return;
}
const lastVersion = storageService.get(ProductContribution.KEY, StorageScope.GLOBAL, '');
const shouldShowReleaseNotes = configurationService.getValue<boolean>('update.showReleaseNotes');
const lastVersion = storageService.get(ProductContribution.KEY, StorageScope.GLOBAL, '');
const shouldShowReleaseNotes = configurationService.getValue<boolean>('update.showReleaseNotes');
// was there an update? if so, open release notes
const releaseNotesUrl = productService.releaseNotesUrl;
if (shouldShowReleaseNotes && !environmentService.args['skip-release-notes'] && releaseNotesUrl && lastVersion && productService.version !== lastVersion) {
showReleaseNotes(instantiationService, productService.version)
.then(undefined, () => {
notificationService.prompt(
severity.Info,
nls.localize('read the release notes', "Welcome to {0} v{1}! Would you like to read the Release Notes?", productService.nameLong, productService.version),
[{
label: nls.localize('releaseNotes', "Release Notes"),
run: () => {
const uri = URI.parse(releaseNotesUrl);
openerService.open(uri);
}
}],
{ sticky: true }
);
});
}
// was there an update? if so, open release notes
const releaseNotesUrl = productService.releaseNotesUrl;
if (shouldShowReleaseNotes && !environmentService.args['skip-release-notes'] && releaseNotesUrl && lastVersion && productService.version !== lastVersion) {
showReleaseNotes(instantiationService, productService.version)
.then(undefined, () => {
notificationService.prompt(
severity.Info,
nls.localize('read the release notes', "Welcome to {0} v{1}! Would you like to read the Release Notes?", productService.nameLong, productService.version),
[{
label: nls.localize('releaseNotes', "Release Notes"),
run: () => {
const uri = URI.parse(releaseNotesUrl);
openerService.open(uri);
}
}],
{ sticky: true }
);
});
}
// should we show the new license?
if (productService.licenseUrl && lastVersion && semver.satisfies(lastVersion, '<1.0.0') && semver.satisfies(productService.version, '>=1.0.0')) {
notificationService.info(nls.localize('licenseChanged', "Our license terms have changed, please click [here]({0}) to go through them.", productService.licenseUrl));
}
// should we show the new license?
if (productService.licenseUrl && lastVersion && semver.satisfies(lastVersion, '<1.0.0') && semver.satisfies(productService.version, '>=1.0.0')) {
notificationService.info(nls.localize('licenseChanged', "Our license terms have changed, please click [here]({0}) to go through them.", productService.licenseUrl));
}
storageService.store(ProductContribution.KEY, productService.version, StorageScope.GLOBAL);
storageService.store(ProductContribution.KEY, productService.version, StorageScope.GLOBAL);
});
}
}

View file

@ -95,6 +95,10 @@ export class BrowserHostService extends Disposable implements IHostService {
return document.hasFocus();
}
async hadLastFocus(): Promise<boolean> {
return true;
}
async focus(): Promise<void> {
window.focus();
}

View file

@ -25,6 +25,11 @@ export interface IHostService {
*/
readonly hasFocus: boolean;
/**
* Find out if the window had the last focus.
*/
hadLastFocus(): Promise<boolean>;
/**
* Attempt to bring the window to the foreground and focus it.
*/

View file

@ -36,6 +36,16 @@ export class DesktopHostService extends Disposable implements IHostService {
return document.hasFocus();
}
async hadLastFocus(): Promise<boolean> {
const activeWindowId = await this.electronService.getActiveWindowId();
if (typeof activeWindowId === 'undefined') {
return false;
}
return activeWindowId === this.electronEnvironmentService.windowId;
}
openWindow(options?: IOpenEmptyWindowOptions): Promise<void>;
openWindow(toOpen: IWindowOpenable[], options?: IOpenWindowOptions): Promise<void>;
openWindow(arg1?: IOpenEmptyWindowOptions | IWindowOpenable[], arg2?: IOpenWindowOptions): Promise<void> {

View file

@ -865,6 +865,7 @@ export class TestHostService implements IHostService {
_serviceBrand: undefined;
readonly hasFocus: boolean = true;
async hadLastFocus(): Promise<boolean> { return true; }
readonly onDidChangeFocus: Event<boolean> = Event.None;
async restart(): Promise<void> { }