Skip to content

Commit e1678a1

Browse files
committed
Adjust refresh interval and listen for file change events
1 parent 3bafe21 commit e1678a1

File tree

3 files changed

+39
-8
lines changed

3 files changed

+39
-8
lines changed

schema/plugin.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@
1616
"title": "Simple staging flag",
1717
"description": "If true, use a simplified concept of staging. Only files with changes are shown (instead of showing staged/changed/untracked), and all files with changes will be automatically staged",
1818
"default": false
19+
},
20+
"refreshInterval": {
21+
"type": "integer",
22+
"title": "Refresh interval",
23+
"description": "Number of milliseconds between polling the file system for changes.",
24+
"default": 4000
1925
}
2026
}
2127
}

src/index.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,21 @@ function activate(
7272

7373
// Create the Git model
7474
let gitExtension = new GitExtension(app);
75+
7576
// Connect file browser with git model
7677
const filebrowser = factory.defaultBrowser;
78+
79+
// Whenever the file browser path changes, sync the Git extension path
7780
filebrowser.model.pathChanged.connect(
7881
(model: FileBrowserModel, change: IChangedArgs<string>) => {
7982
gitExtension.pathRepository = change.newValue;
8083
}
8184
);
85+
86+
// Whenever a user adds/renames/saves/deletes/modifies a file within the lab environment, refresh the Git status
87+
filebrowser.model.fileChanged.connect(() => gitExtension.refreshStatus());
88+
89+
// Whenever we restore the application, sync the Git extension path
8290
Promise.all([app.restored, filebrowser.model.restored]).then(() => {
8391
gitExtension.pathRepository = filebrowser.model.path;
8492
});
@@ -106,6 +114,12 @@ function activate(
106114
createGitMenu(app, gitExtension, factory.defaultBrowser, settings),
107115
{ rank: 60 }
108116
);
117+
118+
// Listen for changes to extension settings:
119+
settings.changed.connect((settings: ISettingRegistry.ISettings) => {
120+
gitExtension.refreshInterval = settings.composite
121+
.refreshInterval as number;
122+
});
109123
})
110124
.catch(reason => {
111125
console.error(

src/model.ts

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,6 @@ import { ISignal, Signal } from '@phosphor/signaling';
88
import { httpGitRequest } from './git';
99
import { IGitExtension, Git } from './tokens';
1010

11-
/**
12-
* The default duration of the auto-refresh in ms
13-
*/
14-
const DEFAULT_REFRESH_INTERVAL = 2000;
15-
1611
/** Main extension class */
1712
export class GitExtension implements IGitExtension, IDisposable {
1813
constructor(app: JupyterFrontEnd = null) {
@@ -27,20 +22,35 @@ export class GitExtension implements IGitExtension, IDisposable {
2722
console.error(`Fail to get the server root path.\n${reason}`);
2823
});
2924

30-
const refreshInterval = DEFAULT_REFRESH_INTERVAL;
31-
3225
// Start watching the repository
3326
this._poll = new Poll({
3427
factory: () => this._refreshStatus(),
3528
frequency: {
36-
interval: refreshInterval,
29+
interval: this._refreshInterval,
3730
backoff: true,
3831
max: 300 * 1000
3932
},
4033
standby: 'when-hidden'
4134
});
4235
}
4336

37+
/**
38+
* Number of milliseconds between polling the file system for changes.
39+
*/
40+
public get refreshInterval(): number {
41+
return this._refreshInterval;
42+
}
43+
44+
public set refreshInterval(v: number) {
45+
const freq = this._poll.frequency;
46+
this._poll.frequency = {
47+
interval: v,
48+
backoff: freq.backoff,
49+
max: freq.max
50+
};
51+
this._refreshInterval = v;
52+
}
53+
4454
/**
4555
* A signal emitted when the HEAD of the git repository changes.
4656
*/
@@ -914,6 +924,7 @@ export class GitExtension implements IGitExtension, IDisposable {
914924
private _readyPromise: Promise<void> = Promise.resolve();
915925
private _pendingReadyPromise = 0;
916926
private _poll: Poll;
927+
private _refreshInterval = 4000; // ms
917928
private _headChanged = new Signal<IGitExtension, void>(this);
918929
private _markChanged = new Signal<IGitExtension, void>(this);
919930
private _repositoryChanged = new Signal<

0 commit comments

Comments
 (0)