3
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
4
*--------------------------------------------------------------------------------------------*/
5
5
6
- import { Disposable } from 'vs/base/common/lifecycle' ;
6
+ import { Disposable , MutableDisposable } from 'vs/base/common/lifecycle' ;
7
7
import { IWorkbenchContributionsRegistry , Extensions as WorkbenchExtensions , IWorkbenchContribution } from 'vs/workbench/common/contributions' ;
8
8
import { Registry } from 'vs/platform/registry/common/platform' ;
9
9
import { ILifecycleService , LifecyclePhase } from 'vs/workbench/services/lifecycle/common/lifecycle' ;
@@ -54,6 +54,8 @@ import { ThemeIcon } from 'vs/platform/theme/common/themeService';
54
54
import { IOutputService } from 'vs/workbench/services/output/common/output' ;
55
55
import * as Constants from 'vs/workbench/contrib/logs/common/logConstants' ;
56
56
import { sha1Hex } from 'vs/base/browser/hash' ;
57
+ import { IStorageService , StorageScope , StorageTarget } from 'vs/platform/storage/common/storage' ;
58
+ import { IActivityService , NumberBadge } from 'vs/workbench/services/activity/common/activity' ;
57
59
58
60
registerSingleton ( IEditSessionsLogService , EditSessionsLogService , false ) ;
59
61
registerSingleton ( IEditSessionsStorageService , EditSessionsWorkbenchService , false ) ;
@@ -89,6 +91,9 @@ export class EditSessionsContribution extends Disposable implements IWorkbenchCo
89
91
90
92
private readonly shouldShowViewsContext : IContextKey < boolean > ;
91
93
94
+ private static APPLICATION_LAUNCHED_VIA_CONTINUE_ON_STORAGE_KEY = 'applicationLaunchedViaContinueOn' ;
95
+ private accountsMenuBadgeDisposable = this . _register ( new MutableDisposable ( ) ) ;
96
+
92
97
constructor (
93
98
@IEditSessionsStorageService private readonly editSessionsStorageService : IEditSessionsStorageService ,
94
99
@IFileService private readonly fileService : IFileService ,
@@ -109,7 +114,9 @@ export class EditSessionsContribution extends Disposable implements IWorkbenchCo
109
114
@ICommandService private commandService : ICommandService ,
110
115
@IContextKeyService private readonly contextKeyService : IContextKeyService ,
111
116
@IFileDialogService private readonly fileDialogService : IFileDialogService ,
112
- @ILifecycleService private readonly lifecycleService : ILifecycleService
117
+ @ILifecycleService private readonly lifecycleService : ILifecycleService ,
118
+ @IStorageService private readonly storageService : IStorageService ,
119
+ @IActivityService private readonly activityService : IActivityService ,
113
120
) {
114
121
super ( ) ;
115
122
@@ -123,6 +130,7 @@ export class EditSessionsContribution extends Disposable implements IWorkbenchCo
123
130
124
131
this . _register ( this . fileService . registerProvider ( EditSessionsFileSystemProvider . SCHEMA , new EditSessionsFileSystemProvider ( this . editSessionsStorageService ) ) ) ;
125
132
this . lifecycleService . onWillShutdown ( ( e ) => e . join ( this . autoStoreEditSession ( ) , { id : 'autoStoreEditSession' , label : localize ( 'autoStoreEditSession' , 'Storing current edit session...' ) } ) ) ;
133
+ this . _register ( this . editSessionsStorageService . onDidSignIn ( ( ) => this . updateAccountsMenuBadge ( ) ) ) ;
126
134
}
127
135
128
136
private autoResumeEditSession ( ) {
@@ -136,21 +144,58 @@ export class EditSessionsContribution extends Disposable implements IWorkbenchCo
136
144
this . telemetryService . publicLog2 < ResumeEvent , ResumeClassification > ( 'editSessions.continue.resume' ) ;
137
145
138
146
if ( this . environmentService . editSessionId !== undefined ) {
147
+ this . logService . info ( `Resuming edit session, reason: found editSessionId ${ this . environmentService . editSessionId } in environment service...` ) ;
139
148
await this . resumeEditSession ( this . environmentService . editSessionId ) . finally ( ( ) => this . environmentService . editSessionId = undefined ) ;
140
149
} else if (
141
150
this . configurationService . getValue ( 'workbench.editSessions.autoResume' ) === 'onReload' &&
142
151
this . editSessionsStorageService . isSignedIn
143
152
) {
153
+ this . logService . info ( 'Resuming edit session, reason: edit sessions enabled...' ) ;
144
154
// Attempt to resume edit session based on edit workspace identifier
145
155
// Note: at this point if the user is not signed into edit sessions,
146
156
// we don't want them to be prompted to sign in and should just return early
147
157
await this . resumeEditSession ( undefined , true ) ;
158
+ } else {
159
+ // The application has previously launched via a protocol URL Continue On flow
160
+ const hasApplicationLaunchedFromContinueOnFlow = this . storageService . getBoolean ( EditSessionsContribution . APPLICATION_LAUNCHED_VIA_CONTINUE_ON_STORAGE_KEY , StorageScope . APPLICATION , false ) ;
161
+
162
+ if ( ( this . environmentService . continueOn !== undefined ) &&
163
+ ! this . editSessionsStorageService . isSignedIn &&
164
+ // and user has not yet been prompted to sign in on this machine
165
+ hasApplicationLaunchedFromContinueOnFlow === false
166
+ ) {
167
+ this . storageService . store ( EditSessionsContribution . APPLICATION_LAUNCHED_VIA_CONTINUE_ON_STORAGE_KEY , true , StorageScope . APPLICATION , StorageTarget . MACHINE ) ;
168
+ await this . editSessionsStorageService . initialize ( true ) ;
169
+ if ( this . editSessionsStorageService . isSignedIn ) {
170
+ await this . resumeEditSession ( undefined , true ) ;
171
+ } else {
172
+ this . updateAccountsMenuBadge ( ) ;
173
+ }
174
+ // store the fact that we prompted the user
175
+ } else if ( ! this . editSessionsStorageService . isSignedIn &&
176
+ // and user has been prompted to sign in on this machine
177
+ hasApplicationLaunchedFromContinueOnFlow === true
178
+ ) {
179
+ // display a badge in the accounts menu but do not prompt the user to sign in again
180
+ this . updateAccountsMenuBadge ( ) ;
181
+ // attempt a resume if we are in a pending state and the user just signed in
182
+ this . _register ( this . editSessionsStorageService . onDidSignIn ( async ( ) => this . resumeEditSession ( undefined , true ) ) ) ;
183
+ }
148
184
}
149
185
150
186
performance . mark ( 'code/didResumeEditSessionFromIdentifier' ) ;
151
187
} ) ;
152
188
}
153
189
190
+ private updateAccountsMenuBadge ( ) {
191
+ if ( this . editSessionsStorageService . isSignedIn ) {
192
+ return this . accountsMenuBadgeDisposable . clear ( ) ;
193
+ }
194
+
195
+ const badge = new NumberBadge ( 1 , ( ) => localize ( 'check for pending edit sessions' , 'Check for pending edit sessions' ) ) ;
196
+ this . accountsMenuBadgeDisposable . value = this . activityService . showAccountsActivity ( { badge, priority : 1 } ) ;
197
+ }
198
+
154
199
private async autoStoreEditSession ( ) {
155
200
if ( this . configurationService . getValue ( 'workbench.experimental.editSessions.autoStore' ) === 'onShutdown' ) {
156
201
await this . progressService . withProgress ( {
@@ -252,7 +297,7 @@ export class EditSessionsContribution extends Disposable implements IWorkbenchCo
252
297
if ( ref !== undefined && uri !== 'noDestinationUri' ) {
253
298
const encodedRef = encodeURIComponent ( ref ) ;
254
299
uri = uri . with ( {
255
- query : uri . query . length > 0 ? ( uri . query + `&${ queryParamName } =${ encodedRef } ` ) : `${ queryParamName } =${ encodedRef } `
300
+ query : uri . query . length > 0 ? ( uri . query + `&${ queryParamName } =${ encodedRef } &continueOn=1 ` ) : `${ queryParamName } =${ encodedRef } &continueOn=1 `
256
301
} ) ;
257
302
258
303
// Open the URI
0 commit comments