rm in app updater

nomaster
Jeff Moe 2023-11-12 13:12:20 -07:00
parent 28518c07e3
commit c58475d873
12 changed files with 1 additions and 592 deletions

View File

@ -54,7 +54,4 @@ clean:
rm -rf theia-extensions/product/lib
rm -rf theia-extensions/product/node_modules
rm -rf theia-extensions/product/tsconfig.tsbuildinfo
rm -rf theia-extensions/updater/lib
rm -rf theia-extensions/updater/node_modules
rm -rf theia-extensions/updater/tsconfig.tsbuildinfo
rm -rf yarn.lock

View File

@ -87,7 +87,6 @@
"@theia/vsx-registry": "1.43.0",
"@theia/workspace": "1.43.0",
"fs-extra": "^9.0.1",
"parrot-updater-ext": "0.0.6",
"parrot-product-ext": "0.0.6",
"parrot-launcher-ext": "0.0.6"
},

View File

@ -1,10 +0,0 @@
/** @type {import('eslint').Linter.Config} */
module.exports = {
extends: [
'../../configs/build.eslintrc.json'
],
parserOptions: {
tsconfigRootDir: __dirname,
project: 'tsconfig.json'
}
};

View File

@ -1,49 +0,0 @@
{
"private": true,
"name": "parrot-updater-ext",
"version": "0.0.6",
"description": "Parrot Updater",
"dependencies": {
"@theia/core": "1.43.0",
"@theia/output": "1.43.0",
"@theia/preferences": "1.43.0",
"electron-log": "^4.3.0",
"electron-updater": "5.3.0",
"fs-extra": "^10.0.0",
"vscode-uri": "^2.1.1"
},
"devDependencies": {
"rimraf": "^2.7.1",
"tslint": "^5.12.0",
"typescript": "^4.5.5"
},
"theiaExtensions": [
{
"electronMain": "lib/electron-main/update/theia-updater-main-module",
"frontendElectron": "lib/electron-browser/theia-updater-frontend-module"
}
],
"keywords": [
"theia-extension"
],
"license": "GPL-3.0-or-later",
"repository": {
"type": "git",
"url": "https://spacecruft.org/deepcrayon/parrot.git"
},
"bugs": {
"url": "https://spacecruft.org/deepcrayon/parrot/issues"
},
"homepage": "https://parrot.codes",
"files": [
"lib",
"src"
],
"scripts": {
"clean": "rimraf lib *.tsbuildinfo",
"build": "tsc -b",
"lint": "eslint --ext js,jsx,ts,tsx src",
"lint:fix": "eslint --ext js,jsx,ts,tsx src --fix",
"update:next": "ts-node ../../scripts/update-theia-to-next.ts"
}
}

View File

@ -1,39 +0,0 @@
/********************************************************************************
* Copyright (C) 2020 TypeFox, EclipseSource and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the Eclipse
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
* with the GNU Classpath Exception which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/
import { JsonRpcServer } from '@theia/core/lib/common/messaging/proxy-factory';
export const TheiaUpdaterPath = '/services/theia-updater';
export const TheiaUpdater = Symbol('TheiaUpdater');
export interface TheiaUpdater extends JsonRpcServer<TheiaUpdaterClient> {
checkForUpdates(): void;
downloadUpdate(): void;
onRestartToUpdateRequested(): void;
disconnectClient(client: TheiaUpdaterClient): void;
}
export const TheiaUpdaterClient = Symbol('TheiaUpdaterClient');
export interface UpdaterError {
message: string;
errorLogPath?: string;
}
export interface TheiaUpdaterClient {
updateAvailable(available: boolean, startupCheck: boolean): void;
notifyReadyToInstall(): void;
reportError(error: UpdaterError): void;
}

View File

@ -1,38 +0,0 @@
/********************************************************************************
* Copyright (C) 2020 TypeFox, EclipseSource and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the Eclipse
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
* with the GNU Classpath Exception which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/
import { CommandContribution, MenuContribution } from '@theia/core/lib/common';
import { ElectronMenuUpdater, TheiaUpdaterClientImpl, TheiaUpdaterFrontendContribution } from './updater/theia-updater-frontend-contribution';
import { TheiaUpdater, TheiaUpdaterClient, TheiaUpdaterPath } from '../common/updater/theia-updater';
import { ContainerModule } from '@theia/core/shared/inversify';
import { ElectronIpcConnectionProvider } from '@theia/core/lib/electron-browser/messaging/electron-ipc-connection-provider';
import { PreferenceContribution } from '@theia/core/lib/browser';
import { theiaUpdaterPreferenceSchema } from './updater/theia-updater-preferences';
export default new ContainerModule((bind, _unbind, isBound, rebind) => {
bind(ElectronMenuUpdater).toSelf().inSingletonScope();
bind(TheiaUpdaterClientImpl).toSelf().inSingletonScope();
bind(TheiaUpdaterClient).toService(TheiaUpdaterClientImpl);
bind(TheiaUpdater).toDynamicValue(context => {
const client = context.container.get(TheiaUpdaterClientImpl);
return ElectronIpcConnectionProvider.createProxy(context.container, TheiaUpdaterPath, client);
}).inSingletonScope();
bind(TheiaUpdaterFrontendContribution).toSelf().inSingletonScope();
bind(MenuContribution).toService(TheiaUpdaterFrontendContribution);
bind(CommandContribution).toService(TheiaUpdaterFrontendContribution);
bind(PreferenceContribution).toConstantValue({ schema: theiaUpdaterPreferenceSchema });
});

View File

@ -1,249 +0,0 @@
/********************************************************************************
* Copyright (C) 2020 TypeFox, EclipseSource and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the Eclipse
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
* with the GNU Classpath Exception which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/
import {
Command,
CommandContribution,
CommandRegistry,
Emitter,
MenuContribution,
MenuModelRegistry,
MenuPath,
MessageService,
Progress
} from '@theia/core/lib/common';
import { PreferenceScope, PreferenceService } from '@theia/core/lib/browser/preferences';
import { TheiaUpdater, TheiaUpdaterClient, UpdaterError } from '../../common/updater/theia-updater';
import { inject, injectable, postConstruct } from '@theia/core/shared/inversify';
import { CommonMenus, OpenerService } from '@theia/core/lib/browser';
import { ElectronMainMenuFactory } from '@theia/core/lib/electron-browser/menu/electron-main-menu-factory';
import URI from '@theia/core/lib/common/uri';
import { URI as VSCodeURI } from 'vscode-uri';
export namespace TheiaUpdaterCommands {
const category = 'Theia Electron Updater';
export const CHECK_FOR_UPDATES: Command = {
id: 'electron-theia:check-for-updates',
label: 'Check for Updates...',
category
};
export const RESTART_TO_UPDATE: Command = {
id: 'electron-theia:restart-to-update',
label: 'Restart to Update',
category
};
}
export namespace TheiaUpdaterMenu {
export const MENU_PATH: MenuPath = [...CommonMenus.FILE_SETTINGS_SUBMENU, '3_settings_submenu_update'];
}
@injectable()
export class TheiaUpdaterClientImpl implements TheiaUpdaterClient {
@inject(PreferenceService) private readonly preferenceService: PreferenceService;
protected readonly onReadyToInstallEmitter = new Emitter<void>();
readonly onReadyToInstall = this.onReadyToInstallEmitter.event;
protected readonly onUpdateAvailableEmitter = new Emitter<boolean>();
readonly onUpdateAvailable = this.onUpdateAvailableEmitter.event;
protected readonly onErrorEmitter = new Emitter<UpdaterError>();
readonly onError = this.onErrorEmitter.event;
notifyReadyToInstall(): void {
this.onReadyToInstallEmitter.fire();
}
updateAvailable(available: boolean, startupCheck: boolean): void {
if (startupCheck) {
// When we are checking for updates after program launch we need to check whether to prompt the user
// we need to wait for the preference service. Also add a few seconds delay before showing the dialog
this.preferenceService.ready
.then(() => {
setTimeout(() => {
const reportOnStart: boolean = this.preferenceService.get('updates.reportOnStart', true);
if (reportOnStart) {
this.onUpdateAvailableEmitter.fire(available);
}
}, 10000);
});
} else {
this.onUpdateAvailableEmitter.fire(available);
}
}
reportError(error: UpdaterError): void {
this.onErrorEmitter.fire(error);
}
}
// Dynamic menus aren't yet supported by electron: https://github.com/eclipse-theia/theia/issues/446
@injectable()
export class ElectronMenuUpdater {
@inject(ElectronMainMenuFactory)
protected readonly factory: ElectronMainMenuFactory;
public update(): void {
this.setMenu();
}
private setMenu(): void {
window.electronTheiaCore.setMenu(this.factory.createElectronMenuBar());
}
}
@injectable()
export class TheiaUpdaterFrontendContribution implements CommandContribution, MenuContribution {
@inject(MessageService)
protected readonly messageService: MessageService;
@inject(ElectronMenuUpdater)
protected readonly menuUpdater: ElectronMenuUpdater;
@inject(TheiaUpdater)
protected readonly updater: TheiaUpdater;
@inject(TheiaUpdaterClientImpl)
protected readonly updaterClient: TheiaUpdaterClientImpl;
@inject(PreferenceService)
private readonly preferenceService: PreferenceService;
@inject(OpenerService)
protected readonly openerService: OpenerService;
protected readyToUpdate = false;
private progress: Progress | undefined;
private intervalId: NodeJS.Timeout | undefined;
@postConstruct()
protected init(): void {
this.updaterClient.onUpdateAvailable(available => {
if (available) {
this.handleDownloadUpdate();
} else {
this.handleNoUpdate();
}
});
this.updaterClient.onReadyToInstall(async () => {
this.readyToUpdate = true;
this.menuUpdater.update();
this.handleUpdatesAvailable();
});
this.updaterClient.onError(error => this.handleError(error));
}
registerCommands(registry: CommandRegistry): void {
registry.registerCommand(TheiaUpdaterCommands.CHECK_FOR_UPDATES, {
execute: async () => {
this.updater.checkForUpdates();
},
isEnabled: () => !this.readyToUpdate,
isVisible: () => !this.readyToUpdate
});
registry.registerCommand(TheiaUpdaterCommands.RESTART_TO_UPDATE, {
execute: () => this.updater.onRestartToUpdateRequested(),
isEnabled: () => this.readyToUpdate,
isVisible: () => this.readyToUpdate
});
}
registerMenus(registry: MenuModelRegistry): void {
registry.registerMenuAction(TheiaUpdaterMenu.MENU_PATH, {
commandId: TheiaUpdaterCommands.CHECK_FOR_UPDATES.id
});
registry.registerMenuAction(TheiaUpdaterMenu.MENU_PATH, {
commandId: TheiaUpdaterCommands.RESTART_TO_UPDATE.id
});
}
protected async handleDownloadUpdate(): Promise<void> {
const answer = await this.messageService.info('Updates found, do you want to update?', 'No', 'Yes', 'Never');
if (answer === 'Never') {
this.preferenceService.set('updates.reportOnStart', false, PreferenceScope.User);
return;
}
if (answer === 'Yes') {
this.stopProgress();
this.progress = await this.messageService.showProgress({
text: 'Blueprint Update'
});
let dots = 0;
this.intervalId = setInterval(() => {
if (this.progress !== undefined) {
dots = (dots + 1) % 4;
this.progress.report({ message: 'Downloading' + '.'.repeat(dots) });
}
}, 1000);
this.updater.downloadUpdate();
}
}
protected async handleNoUpdate(): Promise<void> {
this.messageService.info('Already using the latest version');
}
protected async handleUpdatesAvailable(): Promise<void> {
if (this.progress !== undefined) {
this.progress.report({ work: { done: 1, total: 1 } });
this.stopProgress();
}
const answer = await this.messageService.info('An update has been downloaded and will be automatically installed on exit. Do you want to restart now?', 'No', 'Yes');
if (answer === 'Yes') {
this.updater.onRestartToUpdateRequested();
}
}
protected async handleError(error: UpdaterError): Promise<void> {
this.stopProgress();
if (error.errorLogPath) {
const viewLogAction = 'View Error Log';
const answer = await this.messageService.error(error.message, viewLogAction);
if (answer === viewLogAction) {
const uri = new URI(VSCodeURI.file(error.errorLogPath));
const opener = await this.openerService.getOpener(uri);
opener.open(uri);
}
} else {
this.messageService.error(error.message);
}
}
private stopProgress(): void {
if (this.intervalId !== undefined) {
clearInterval(this.intervalId);
this.intervalId = undefined;
}
if (this.progress !== undefined) {
this.progress.cancel();
this.progress = undefined;
}
}
}

View File

@ -1,28 +0,0 @@
/********************************************************************************
* Copyright (C) 2020 EclipseSource and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the Eclipse
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
* with the GNU Classpath Exception which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/
import { PreferenceSchema } from '@theia/core/lib/common/preferences/preference-schema';
export const theiaUpdaterPreferenceSchema: PreferenceSchema = {
'type': 'object',
'properties': {
'updates.reportOnStart': {
type: 'boolean',
description: 'Report available updates after application start.',
default: true
}
}
};

View File

@ -1,123 +0,0 @@
/********************************************************************************
* Copyright (C) 2020 TypeFox, EclipseSource and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the Eclipse
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
* with the GNU Classpath Exception which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/
import * as fs from 'fs-extra';
import * as http from 'http';
import * as os from 'os';
import * as path from 'path';
import { ElectronMainApplication, ElectronMainApplicationContribution } from '@theia/core/lib/electron-main/electron-main-application';
import { TheiaUpdater, TheiaUpdaterClient } from '../../common/updater/theia-updater';
import { injectable } from '@theia/core/shared/inversify';
const { autoUpdater } = require('electron-updater');
autoUpdater.logger = require('electron-log');
autoUpdater.logger.transports.file.level = 'info';
@injectable()
export class TheiaUpdaterImpl implements TheiaUpdater, ElectronMainApplicationContribution {
protected clients: Array<TheiaUpdaterClient> = [];
private initialCheck: boolean = true;
private reportOnFirstRegistration: boolean = false;
constructor() {
autoUpdater.autoDownload = false;
autoUpdater.on('update-available', () => {
const startupCheck = this.initialCheck;
if (this.initialCheck) {
this.initialCheck = false;
if (this.clients.length === 0) {
this.reportOnFirstRegistration = true;
}
}
this.clients.forEach(c => c.updateAvailable(true, startupCheck));
});
autoUpdater.on('update-not-available', () => {
if (this.initialCheck) {
this.initialCheck = false;
/* do not report that no update is available on start up */
return;
}
this.clients.forEach(c => c.updateAvailable(false, false));
});
autoUpdater.on('update-downloaded', () => {
this.clients.forEach(c => c.notifyReadyToInstall());
});
autoUpdater.on('error', (err: unknown) => {
const errorLogPath = autoUpdater.logger.transports.file.getFile().path;
this.clients.forEach(c => c.reportError({ message: 'An error has occurred while attempting to update.', errorLogPath }));
});
}
checkForUpdates(): void {
autoUpdater.checkForUpdates();
}
onRestartToUpdateRequested(): void {
autoUpdater.quitAndInstall();
}
downloadUpdate(): void {
autoUpdater.downloadUpdate();
// record download stat, ignore errors
fs.mkdtemp(path.join(os.tmpdir(), 'updater-'))
.then(tmpDir => {
const file = fs.createWriteStream(path.join(tmpDir, 'update'));
http.get('https://www.eclipse.org/downloads/download.php?file=/theia/update&r=1', response => {
response.pipe(file);
file.on('finish', () => {
file.close();
});
});
});
}
onStart(application: ElectronMainApplication): void {
// Called when the contribution is starting. You can use both async and sync code from here.
this.checkForUpdates();
}
onStop(application: ElectronMainApplication): void {
// Invoked when the contribution is stopping. You can clean up things here. You are not allowed call async code from here.
}
setClient(client: TheiaUpdaterClient | undefined): void {
if (client) {
this.clients.push(client);
if (this.reportOnFirstRegistration) {
this.reportOnFirstRegistration = false;
this.clients.forEach(c => c.updateAvailable(true, true));
}
}
}
disconnectClient(client: TheiaUpdaterClient): void {
const index = this.clients.indexOf(client);
if (index !== -1) {
this.clients.splice(index, 1);
}
}
dispose(): void {
this.clients.forEach(this.disconnectClient.bind(this));
}
}

View File

@ -1,36 +0,0 @@
/********************************************************************************
* Copyright (C) 2020 TypeFox, EclipseSource and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the Eclipse
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
* with the GNU Classpath Exception which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/
import { TheiaUpdater, TheiaUpdaterClient, TheiaUpdaterPath } from '../../common/updater/theia-updater';
import { ContainerModule } from '@theia/core/shared/inversify';
import { ElectronConnectionHandler } from '@theia/core/lib/electron-common/messaging/electron-connection-handler';
import { ElectronMainApplicationContribution } from '@theia/core/lib/electron-main/electron-main-application';
import { JsonRpcConnectionHandler } from '@theia/core/lib/common/messaging/proxy-factory';
import { TheiaUpdaterImpl } from './theia-updater-impl';
export default new ContainerModule(bind => {
bind(TheiaUpdaterImpl).toSelf().inSingletonScope();
bind(TheiaUpdater).toService(TheiaUpdaterImpl);
bind(ElectronMainApplicationContribution).toService(TheiaUpdater);
bind(ElectronConnectionHandler).toDynamicValue(context =>
new JsonRpcConnectionHandler<TheiaUpdaterClient>(TheiaUpdaterPath, client => {
const server = context.container.get<TheiaUpdater>(TheiaUpdater);
server.setClient(client);
client.onDidCloseConnection(() => server.disconnectClient(client));
return server;
})
).inSingletonScope();
});

View File

@ -1,12 +0,0 @@
{
"extends": "../../configs/base.tsconfig",
"compilerOptions": {
"rootDir": "src",
"outDir": "lib",
"baseUrl": ".",
"esModuleInterop": true
},
"include": [
"src",
]
}

View File

@ -12,14 +12,11 @@
{
"path": "theia-extensions/product"
},
{
"path": "theia-extensions/updater"
},
{
"path": "applications/electron"
},
{
"path": "applications/browser"
},
}
]
}