@@ -58,73 +58,72 @@ export default plugin;
5858/**
5959 * Activate the running plugin.
6060 */
61- function activate (
61+ async function activate (
6262 app : JupyterFrontEnd ,
6363 mainMenu : IMainMenu ,
6464 restorer : ILayoutRestorer ,
6565 factory : IFileBrowserFactory ,
6666 renderMime : IRenderMimeRegistry ,
6767 settingRegistry : ISettingRegistry
68- ) : IGitExtension {
69- const key = plugin . id ;
68+ ) : Promise < IGitExtension > {
69+ let settings : ISettingRegistry . ISettings ;
7070
71+ // Register Git icons with the icon registry
7172 registerGitIcons ( defaultIconRegistry ) ;
7273
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+ }
7386 // Create the Git model
74- let gitExtension = new GitExtension ( app ) ;
87+ const gitExtension = new GitExtension ( app , settings ) ;
7588
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 ;
7891
7992 // Whenever the file browser path changes, sync the Git extension path
8093 filebrowser . model . pathChanged . connect (
8194 ( model : FileBrowserModel , change : IChangedArgs < string > ) => {
8295 gitExtension . pathRepository = change . newValue ;
8396 }
8497 ) ;
85-
8698 // Whenever a user adds/renames/saves/deletes/modifies a file within the lab environment, refresh the Git status
8799 filebrowser . model . fileChanged . connect ( ( ) => gitExtension . refreshStatus ( ) ) ;
88100
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
127125 addCloneButton ( gitExtension , factory . defaultBrowser ) ;
126+
128127 return gitExtension ;
129128}
130129
0 commit comments