@@ -58,73 +58,72 @@ export default plugin;
58
58
/**
59
59
* Activate the running plugin.
60
60
*/
61
- function activate (
61
+ async function activate (
62
62
app : JupyterFrontEnd ,
63
63
mainMenu : IMainMenu ,
64
64
restorer : ILayoutRestorer ,
65
65
factory : IFileBrowserFactory ,
66
66
renderMime : IRenderMimeRegistry ,
67
67
settingRegistry : ISettingRegistry
68
- ) : IGitExtension {
69
- const key = plugin . id ;
68
+ ) : Promise < IGitExtension > {
69
+ let settings : ISettingRegistry . ISettings ;
70
70
71
+ // Register Git icons with the icon registry
71
72
registerGitIcons ( defaultIconRegistry ) ;
72
73
74
+ // Get a reference to the default file browser extension
75
+ const filebrowser = factory . defaultBrowser ;
76
+
77
+ // Wait for the application and file browser extension to be restored:
78
+ await Promise . all ( [ app . restored , filebrowser . model . restored ] ) ;
79
+
80
+ // Attempt to load application settings
81
+ try {
82
+ settings = await settingRegistry . load ( plugin . id ) ;
83
+ } catch ( error ) {
84
+ console . error ( `Failed to load settings for the Git Exetnsion.\n${ error } ` ) ;
85
+ }
73
86
// Create the Git model
74
- let gitExtension = new GitExtension ( app ) ;
87
+ const gitExtension = new GitExtension ( app , settings ) ;
75
88
76
- // Connect file browser with git model
77
- const filebrowser = factory . defaultBrowser ;
89
+ // Sync the Git extension path with the file browser extension's current path
90
+ gitExtension . pathRepository = filebrowser . model . path ;
78
91
79
92
// Whenever the file browser path changes, sync the Git extension path
80
93
filebrowser . model . pathChanged . connect (
81
94
( model : FileBrowserModel , change : IChangedArgs < string > ) => {
82
95
gitExtension . pathRepository = change . newValue ;
83
96
}
84
97
) ;
85
-
86
98
// Whenever a user adds/renames/saves/deletes/modifies a file within the lab environment, refresh the Git status
87
99
filebrowser . model . fileChanged . connect ( ( ) => gitExtension . refreshStatus ( ) ) ;
88
100
89
- // Whenever we restore the application, sync the Git extension path
90
- Promise . all ( [ app . restored , filebrowser . model . restored ] ) . then ( ( ) => {
91
- gitExtension . pathRepository = filebrowser . model . path ;
92
- } ) ;
93
-
94
- /* Create the widgets */
95
- settingRegistry
96
- . load ( key )
97
- . then ( settings => {
98
- // Create the Git widget sidebar
99
- const gitPlugin = new GitWidget ( gitExtension , settings , renderMime ) ;
100
- gitPlugin . id = 'jp-git-sessions' ;
101
- gitPlugin . title . iconClass = `jp-SideBar-tabIcon jp-GitIcon` ;
102
- gitPlugin . title . caption = 'Git' ;
103
-
104
- // Let the application restorer track the running panel for restoration of
105
- // application state (e.g. setting the running panel as the current side bar
106
- // widget).
107
- restorer . add ( gitPlugin , 'git-sessions' ) ;
108
- // Rank has been chosen somewhat arbitrarily to give priority to the running
109
- // sessions widget in the sidebar.
110
- app . shell . add ( gitPlugin , 'left' , { rank : 200 } ) ;
111
-
112
- // add a menu for the plugin
113
- mainMenu . addMenu (
114
- createGitMenu ( app , gitExtension , factory . defaultBrowser , settings ) ,
115
- { rank : 60 }
116
- ) ;
117
-
118
- // Pass along the plugin settings to the Git model:
119
- gitExtension . settings = settings ;
120
- } )
121
- . catch ( reason => {
122
- console . error (
123
- `Failed to load settings for the Git Exetnsion.\n${ reason } `
124
- ) ;
125
- } ) ;
126
-
101
+ // Provided we were able to load application settings, create the extension widgets
102
+ if ( typeof settings !== void 0 ) {
103
+ // Create the Git widget sidebar
104
+ const gitPlugin = new GitWidget ( gitExtension , settings , renderMime ) ;
105
+ gitPlugin . id = 'jp-git-sessions' ;
106
+ gitPlugin . title . iconClass = 'jp-SideBar-tabIcon jp-GitIcon' ;
107
+ gitPlugin . title . caption = 'Git' ;
108
+
109
+ // Let the application restorer track the running panel for restoration of
110
+ // application state (e.g. setting the running panel as the current side bar
111
+ // widget).
112
+ restorer . add ( gitPlugin , 'git-sessions' ) ;
113
+
114
+ // Rank has been chosen somewhat arbitrarily to give priority to the running
115
+ // sessions widget in the sidebar.
116
+ app . shell . add ( gitPlugin , 'left' , { rank : 200 } ) ;
117
+
118
+ // Add a menu for the plugin
119
+ mainMenu . addMenu (
120
+ createGitMenu ( app , gitExtension , factory . defaultBrowser , settings ) ,
121
+ { rank : 60 }
122
+ ) ;
123
+ }
124
+ // Add a clone button to the file browser extension toolbar
127
125
addCloneButton ( gitExtension , factory . defaultBrowser ) ;
126
+
128
127
return gitExtension ;
129
128
}
130
129
0 commit comments