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