Skip to content
This repository has been archived by the owner on Apr 4, 2023. It is now read-only.

Refactor Welcome plugin #1155

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions plugins/containers-plugin/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@eclipse-che/theia-containers-plugin",
"publisher": "Eclipse Che",
"name": "containers-plugin",
"publisher": "@eclipse-che",
"keywords": [
"theia-plugin"
],
Expand Down
4 changes: 2 additions & 2 deletions plugins/github-auth-plugin/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@eclipse-che/github-auth-plugin",
"name": "github-auth-plugin",
"version": "0.0.1",
"publisher": "Eclipse Che",
"publisher": "@eclipse-che",
"keywords": [
"theia-plugin"
],
Expand Down
4 changes: 2 additions & 2 deletions plugins/ports-plugin/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@eclipse-che/ports-plugin",
"publisher": "Eclipse Che",
"name": "ports-plugin",
"publisher": "@eclipse-che",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does It is a breaking change for the plugin which provided by other developer

"version": "0.0.1",
"keywords": [
"theia-plugin"
Expand Down
6 changes: 3 additions & 3 deletions plugins/recommendations-plugin/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@eclipse-che/recommendations-plugin",
"publisher": "Eclipse-Che",
"name": "recommendations-plugin",
"publisher": "@eclipse-che",
"keywords": [
"theia-plugin"
],
Expand All @@ -10,7 +10,7 @@
"src"
],
"extensionDependencies": [
"Eclipse Che.@eclipse-che/workspace-plugin"
"@eclipse-che.workspace-plugin"
],
"dependencies": {
"@eclipse-che/plugin": "0.0.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export class RecommendationsPlugin {

async enableRecommendationsPlugin(): Promise<void> {
// Bring featured recommendations after projects are cloned
const workspacePlugin = theia.plugins.getPlugin('Eclipse Che.@eclipse-che/workspace-plugin');
const workspacePlugin = theia.plugins.getPlugin('@eclipse-che.workspace-plugin');
if (workspacePlugin && workspacePlugin.exports && workspacePlugin.exports.onDidCloneSources) {
workspacePlugin.exports.onDidCloneSources(() => this.afterClone());
}
Expand Down
4 changes: 2 additions & 2 deletions plugins/resource-monitor-plugin/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@eclipse-che/resource-monitor-plugin",
"publisher": "Eclipse Che",
"name": "resource-monitor-plugin",
"publisher": "@eclipse-che",
"keywords": [
"theia-plugin"
],
Expand Down
4 changes: 2 additions & 2 deletions plugins/ssh-plugin/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@eclipse-che/theia-ssh-plugin",
"publisher": "Eclipse Che",
"name": "ssh-plugin",
"publisher": "@eclipse-che",
"keywords": [
"theia-plugin"
],
Expand Down
2 changes: 1 addition & 1 deletion plugins/task-plugin/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "task-plugin",
"publisher": "Eclipse Che",
"publisher": "@eclipse-che",
"keywords": [
"theia-plugin"
],
Expand Down
4 changes: 2 additions & 2 deletions plugins/telemetry-plugin/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@eclipse-che/telemetry-plugin",
"name": "telemetry-plugin",
"version": "0.0.1",
"publisher": "Eclipse Che",
"publisher": "@eclipse-che",
"keywords": [
"theia-plugin"
],
Expand Down
10 changes: 7 additions & 3 deletions plugins/welcome-plugin/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@eclipse-che/welcome-plugin",
"name": "welcome-plugin",
"version": "0.0.1",
"publisher": "Eclipse Che",
"publisher": "@eclipse-che",
"keywords": [
"theia-plugin"
],
Expand All @@ -28,13 +28,17 @@
}
},
"dependencies": {
"@fortawesome/fontawesome-free": "5.6.3"
"@fortawesome/fontawesome-free": "5.6.3",
"fs-extra": "7.0.1"
},
"devDependencies": {
"@theia/plugin": "next",
"@theia/plugin-packager": "latest",
"@eclipse-che/plugin": "0.0.1"
},
"extensionDependencies": [
"@eclipse-che.workspace-plugin"
],
"scripts": {
"prepare": "yarn clean && yarn build && yarn test",
"clean": "rimraf lib",
Expand Down
26 changes: 26 additions & 0 deletions plugins/welcome-plugin/src/commands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**********************************************************************
* Copyright (c) 2021 Red Hat, Inc.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
***********************************************************************/

import * as theia from '@theia/plugin';

export namespace Commands {
export const SHOW_WELCOME: theia.CommandDescription = {
id: 'welcome:show_welcome',
label: 'Welcome: Show Welcome...',
};

export const ENABLE_WELCOME: theia.CommandDescription = {
id: 'welcome:enable',
};

export const DISABLE_WELCOME: theia.CommandDescription = {
id: 'welcome:disable',
};
}
39 changes: 39 additions & 0 deletions plugins/welcome-plugin/src/devfile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**********************************************************************
* Copyright (c) 2021 Red Hat, Inc.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
***********************************************************************/

import * as che from '@eclipse-che/plugin';

export const WELCOME_ENABLED = 'extensions.welcome';

export async function isWelcomeEnabled(): Promise<boolean> {
const workspace = await che.workspace.getCurrentWorkspace();
// always has a devfile now
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const devfile = workspace.devfile!;
const attributes = devfile.attributes || {};
const welcome = attributes[WELCOME_ENABLED] || 'true';
return welcome !== 'false';
}

export async function enableWelcome(enable: boolean): Promise<void> {
const workspace = await che.workspace.getCurrentWorkspace();
// always has a devfile now
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const devfile = workspace.devfile!;
devfile.attributes = devfile.attributes || {};
devfile.attributes[WELCOME_ENABLED] = '' + enable;
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
await che.workspace.update(workspace.id!, workspace);
}

export async function isMultiroot(): Promise<boolean> {
const devfile = await che.devfile.get();
return devfile.metadata?.attributes?.multiRoot !== 'off';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see Multi-root is the only mode in Che-Theia in #1191 ...

}
82 changes: 82 additions & 0 deletions plugins/welcome-plugin/src/readme.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/**********************************************************************
* Copyright (c) 2021 Red Hat, Inc.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
***********************************************************************/

import * as fs from 'fs-extra';
import * as path from 'path';
import * as theia from '@theia/plugin';

import { isMultiroot } from './devfile';

export class Readme {
processed: string[] = [];

constructor(protected context: theia.PluginContext) {}

async seekAndOpen(): Promise<void> {
if (await isMultiroot()) {
this.context.subscriptions.push(
theia.workspace.onDidChangeWorkspaceFolders(
event => this.handleReadmeFiles(event.added),
undefined,
this.context.subscriptions
)
);
} else {
const workspacePlugin = theia.plugins.getPlugin('@eclipse-che.workspace-plugin');
if (workspacePlugin && workspacePlugin.exports) {
this.context.subscriptions.push(
workspacePlugin.exports.onDidCloneSources(
() => this.handleReadmeFiles(),
undefined,
this.context.subscriptions
)
);
} else {
this.handleReadmeFiles();
}
}
}

async handleReadmeFiles(roots?: theia.WorkspaceFolder[]): Promise<void> {
roots = roots ? roots : theia.workspace.workspaceFolders;
if (!roots || roots.length < 1) {
return;
}

for (const root of roots) {
this.openReadme(root.uri.fsPath);
}
}

async openReadme(projectPath: string): Promise<void> {
if (this.processed.some(value => value === projectPath)) {
return;
}

this.processed.push(projectPath);

const readmePath = path.join(projectPath, 'README.md');
if (await fs.pathExists(projectPath)) {
const openPath = theia.Uri.parse(`file://${readmePath}?open-handler=code-editor-preview`);
try {
const doc = await theia.workspace.openTextDocument(openPath);
if (doc) {
await theia.window.showTextDocument(doc);
}
} catch (err) {
// Ignore the error.
// `theia.window.showTextDocument` throws an error with message `Failed to show text document`
// But works as expected.
// It's because `?open-handler=code-editor-preview` was added at the end of the URI
// to open preview instead of the editor
}
}
}
}
Loading