1
1
import * as os from "os" ;
2
2
import { IProgress , INotificationHandle } from "@coder/ide" ;
3
+ import { logger } from "@coder/logger" ;
3
4
import { client } from "./client" ;
4
5
5
6
import "./fill/platform" ;
@@ -28,26 +29,40 @@ import { LogLevel } from "vs/platform/log/common/log";
28
29
import { RawContextKey , IContextKeyService } from "vs/platform/contextkey/common/contextkey" ;
29
30
import { ServiceCollection } from "vs/platform/instantiation/common/serviceCollection" ;
30
31
import { URI } from "vs/base/common/uri" ;
31
-
32
+ import { SyncDescriptor } from "vs/platform/instantiation/common/descriptors" ;
33
+ import { BackupMainService } from "vs/platform/backup/electron-main/backupMainService" ;
34
+ import { IBackupMainService } from "vs/platform/backup/common/backup" ;
35
+ import { IInstantiationService } from "vs/platform/instantiation/common/instantiation" ;
36
+
37
+ /**
38
+ * Initializes VS Code and provides a way to call into general client
39
+ * functionality.
40
+ */
32
41
export class Workbench {
33
42
public readonly retry = client . retry ;
34
43
35
44
private readonly windowId = parseInt ( new Date ( ) . toISOString ( ) . replace ( / [ - : . T Z ] / g, "" ) , 10 ) ;
36
45
private _serviceCollection : ServiceCollection | undefined ;
37
46
private _clipboardContextKey : RawContextKey < boolean > | undefined ;
38
47
48
+ /**
49
+ * Handles a drop event on the file explorer.
50
+ */
39
51
public async handleExternalDrop ( target : ExplorerItem | ExplorerModel , originalEvent : DragEvent ) : Promise < void > {
40
52
await client . upload . uploadDropped (
41
53
originalEvent ,
42
54
( target instanceof ExplorerItem ? target : target . roots [ 0 ] ) . resource ,
43
55
) ;
44
56
}
45
57
58
+ /**
59
+ * Handles a drop event on the editor.
60
+ */
46
61
public handleDrop ( event : DragEvent , resolveTargetGroup : ( ) => IEditorGroup , afterDrop : ( targetGroup : IEditorGroup ) => void , targetIndex ?: number ) : void {
47
- client . upload . uploadDropped ( event , URI . file ( paths . getWorkingDirectory ( ) ) ) . then ( ( paths ) => {
62
+ client . upload . uploadDropped ( event , URI . file ( paths . getWorkingDirectory ( ) ) ) . then ( async ( paths ) => {
48
63
const uris = paths . map ( ( p ) => URI . file ( p ) ) ;
49
64
if ( uris . length ) {
50
- ( this . serviceCollection . get ( IWindowsService ) as IWindowsService ) . addRecentlyOpened ( uris ) ;
65
+ await ( this . serviceCollection . get ( IWindowsService ) as IWindowsService ) . addRecentlyOpened ( uris ) ;
51
66
}
52
67
53
68
const editors : IResourceEditor [ ] = uris . map ( uri => ( {
@@ -59,10 +74,10 @@ export class Workbench {
59
74
} ) ) ;
60
75
61
76
const targetGroup = resolveTargetGroup ( ) ;
62
-
63
- ( this . serviceCollection . get ( IEditorService ) as IEditorService ) . openEditors ( editors , targetGroup ) . then ( ( ) => {
64
- afterDrop ( targetGroup ) ;
65
- } ) ;
77
+ await ( this . serviceCollection . get ( IEditorService ) as IEditorService ) . openEditors ( editors , targetGroup ) ;
78
+ afterDrop ( targetGroup ) ;
79
+ } ) . catch ( ( error ) => {
80
+ logger . error ( error . message ) ;
66
81
} ) ;
67
82
}
68
83
@@ -117,6 +132,15 @@ export class Workbench {
117
132
118
133
public set serviceCollection ( collection : ServiceCollection ) {
119
134
this . _serviceCollection = collection ;
135
+
136
+ // TODO: If possible it might be better to start the app from vs/code/electron-main/app.
137
+ // For now, manually initialize services from there as needed.
138
+ const init = this . _serviceCollection . get ( IInstantiationService ) as IInstantiationService ;
139
+ const backupMainService = init . createInstance ( BackupMainService ) as BackupMainService ;
140
+ backupMainService . initialize ( ) . catch ( ( error ) => {
141
+ logger . error ( error . message ) ;
142
+ } ) ;
143
+
120
144
client . progressService = {
121
145
start : < T > ( title : string , task : ( progress : IProgress ) => Promise < T > , onCancel : ( ) => void ) : Promise < T > => {
122
146
let lastProgress = 0 ;
@@ -166,6 +190,9 @@ export class Workbench {
166
190
} ;
167
191
}
168
192
193
+ /**
194
+ * Start VS Code.
195
+ */
169
196
public async initialize ( ) : Promise < void > {
170
197
this . _clipboardContextKey = new RawContextKey ( "nativeClipboard" , client . clipboard . isEnabled ) ;
171
198
0 commit comments