This repository has been archived by the owner on Apr 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 111
Rsync events #771
Merged
+192
−0
Merged
Rsync events #771
Changes from 10 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
85daf2c
Add event tracking and show progress in status bar
vparfonov 4203bbd
Merge conflict with master
vparfonov b717c35
Merge conflict with master
vparfonov c52c577
Update README.md
vparfonov 931c85d
Fix: Strings must use singlequote
vparfonov 867ffd5
Merge branch 'rsync_events' of github.com:eclipse/che-theia into rsyn…
vparfonov 84b33cc
Fix: Missing semicolon, missing whitespace
vparfonov f8ff668
Fix: missing whitespace
vparfonov 4cb35cc
Code cleanup
vparfonov 060fa89
Fix error: More than 1 blank line not allowed no-multiple-empty-lines
vparfonov 6bae574
Fix review comments
vparfonov fcb00af
Fix extension path after rename
vparfonov 2d9e244
Fix module name
vparfonov d4186e2
Fix typos in README.md
vparfonov e72c18b
Merge with master
vparfonov a8e723b
Update extensions/eclipse-che-theia-file-sync-tracker/package.json
vparfonov 3b5f255
Update extensions/eclipse-che-theia-file-sync-tracker/README.md
vparfonov 5a3cfa7
Rename class to more specific. Code cleanup
vparfonov a4b84d0
Rename class to more specific. Code cleanup
vparfonov 5a0820a
Merge branch 'master' into rsync_events
vparfonov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
lib/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# theia-file-sync-tracker extension | ||
|
||
This extension tracks events of file synchronization progress during workspace startup. | ||
|
||
### How does the extension work? | ||
|
||
If workspace configured to use asynchronous storage extension will open websocket connection to special service and show progress in status bar. In case some error, error message will show in status bar after clicking will appear popup with error details. After successfully file synchronization status bar also will update with corresponding message, in this case message will disappear in 5 seconds. | ||
|
||
## Technical info | ||
|
||
TBD | ||
|
||
|
30 changes: 30 additions & 0 deletions
30
extensions/eclipse-che-theia-sync-file-tracker/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"name": "@eclipse-che/theia-file-sync-tracker", | ||
vparfonov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"keywords": [ | ||
"theia-extension" | ||
], | ||
"version": "1.0.0", | ||
"files": [ | ||
"lib", | ||
"src" | ||
], | ||
"dependencies": { | ||
"@theia/core": "next", | ||
"@eclipse-che/theia-plugin-ext": "^0.0.1" | ||
}, | ||
"scripts": { | ||
"prepare": "yarn clean && yarn build", | ||
"clean": "rimraf lib", | ||
"format": "tsfmt -r --useTsfmt ../../configs/tsfmt.json", | ||
"lint": "eslint --cache=true --no-error-on-unmatched-pattern=true \"{src,test}/**/*.{ts,tsx}\"", | ||
"compile": "tsc", | ||
"build": "concurrently -n \"format,lint,compile\" -c \"red,green,blue\" \"yarn format\" \"yarn lint\" \"yarn compile\"", | ||
"watch": "tsc -w" | ||
}, | ||
"license": "EPL-2.0", | ||
"theiaExtensions": [ | ||
{ | ||
"frontend": "lib/browser/che-theia-sync-file-frontend-module" | ||
} | ||
] | ||
} |
24 changes: 24 additions & 0 deletions
24
...ns/eclipse-che-theia-sync-file-tracker/src/browser/che-theia-sync-file-frontend-module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/******************************************************************************** | ||
* Copyright (C) 2020 Red Hat, Inc. 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 { ContainerModule } from 'inversify'; | ||
import { FrontendApplicationContribution } from '@theia/core/lib/browser'; | ||
import { StatusBarFrontendContribution } from './status-bar-contribution'; | ||
|
||
export default new ContainerModule(bind => { | ||
|
||
bind(FrontendApplicationContribution).to(StatusBarFrontendContribution).inSingletonScope(); | ||
}); |
116 changes: 116 additions & 0 deletions
116
extensions/eclipse-che-theia-sync-file-tracker/src/browser/status-bar-contribution.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
/******************************************************************************** | ||
* Copyright (C) 2020 Red Hat, Inc. 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 { injectable, inject, postConstruct } from 'inversify'; | ||
import { FrontendApplicationContribution } from '@theia/core/lib/browser'; | ||
import { MessageService } from '@theia/core/lib/common'; | ||
import { StatusBar, StatusBarAlignment, StatusBarEntry } from '@theia/core/lib/browser/status-bar/status-bar'; | ||
import { CheApiService } from '@eclipse-che/theia-plugin-ext/lib/common/che-protocol'; | ||
import URI from '@theia/core/lib/common/uri'; | ||
import ReconnectingWebSocket from 'reconnecting-websocket'; | ||
import { DisposableCollection, Disposable } from '@theia/core'; | ||
|
||
@injectable() | ||
export class StatusBarFrontendContribution implements FrontendApplicationContribution { | ||
|
||
@inject(StatusBar) | ||
private statusBar: StatusBar; | ||
@inject(MessageService) | ||
protected readonly messageService: MessageService; | ||
@inject(CheApiService) | ||
protected cheApiService: CheApiService; | ||
private readonly ID = 'file-synchronization-indicator-id'; | ||
protected readonly statusBarDisposable = new DisposableCollection(); | ||
|
||
private readonly tooltip = 'File synchronization progress'; | ||
private readonly fail = 'File synchronization fail'; | ||
private readonly done = 'File synchronization done'; | ||
vparfonov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
@postConstruct() | ||
vparfonov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
async initialize(): Promise<void> { | ||
const url = await this.getWorkspaceService(); | ||
this.connect(url); | ||
vparfonov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
async getWorkspaceService(): Promise<string> { | ||
vparfonov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const server = await this.cheApiService.findUniqueServerByAttribute('type', 'rsync'); | ||
if (server) { | ||
return new URI(server.url + '/track').toString(); | ||
vparfonov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} else { | ||
return Promise.reject('Server rsync not found'); | ||
} | ||
} | ||
|
||
private connect(endpointAdress: string): void { | ||
vparfonov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const websocket = new ReconnectingWebSocket(endpointAdress, undefined, { | ||
maxRetries: Infinity, | ||
}); | ||
websocket.onerror = err => { | ||
console.log(err); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the case of any error while establishing WebSocket connection |
||
}; | ||
websocket.onmessage = ev => { | ||
this.updateStatusBar(ev.data, websocket); | ||
}; | ||
websocket.onclose = () => console.log('File synchronization tracking connection closed'); | ||
websocket.onopen = () => console.log('File synchronization tracking connection opened'); | ||
}; | ||
|
||
private updateStatusBar(data: string, websocket: ReconnectingWebSocket): void { | ||
this.statusBarDisposable.dispose(); | ||
const obj = JSON.parse(data); | ||
if (obj.state === 'DONE') { | ||
websocket.close(); | ||
this.setStatusBarEntry(this.ID, { | ||
text: this.done, | ||
tooltip: this.tooltip, | ||
alignment: StatusBarAlignment.LEFT, | ||
onclick: (e: MouseEvent) => this.messageService.info(this.done), | ||
priority: 150 | ||
}); | ||
(async () => { | ||
await this.delay(5000); // hide message in 5 sec | ||
this.statusBarDisposable.dispose(); | ||
})(); | ||
} else if (obj.state === 'ERROR') { | ||
websocket.close(); | ||
this.setStatusBarEntry(this.ID, { | ||
text: this.fail, | ||
tooltip: this.tooltip, | ||
alignment: StatusBarAlignment.LEFT, | ||
onclick: (e: MouseEvent) => this.messageService.error(obj.info), | ||
priority: 150 | ||
}); | ||
} else { | ||
const msg = `File synchronization progress: ${obj.info}`; | ||
vparfonov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
this.setStatusBarEntry(this.ID, { | ||
text: msg, | ||
tooltip: this.tooltip, | ||
alignment: StatusBarAlignment.LEFT, | ||
onclick: (e: MouseEvent) => this.messageService.info(msg), | ||
priority: 150 | ||
}); | ||
} | ||
} | ||
|
||
private setStatusBarEntry(id: string, entry: StatusBarEntry): void { | ||
this.statusBar.setElement(id, entry); | ||
vparfonov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
this.statusBarDisposable.push(Disposable.create(() => this.statusBar.removeElement(id))); | ||
} | ||
|
||
private delay(ms: number): Promise<void> { | ||
return new Promise(resolve => setTimeout(resolve, ms)); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
extensions/eclipse-che-theia-sync-file-tracker/tsconfig.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"extends": "../../configs/base.tsconfig.json", | ||
"compilerOptions": { | ||
"lib": [ | ||
"es6", | ||
"dom" | ||
], | ||
"rootDir": "src", | ||
"outDir": "lib" | ||
}, | ||
"include": [ | ||
"src" | ||
] | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it needed here? )