Skip to content

Commit 7094de0

Browse files
authored
V3.2.8 (#821)
* #806 * prettify custom setting json (#812) * Fix auto upload (#801) * Fix auto upload! * Properly stop watching * Add synchronous functions * Move watcher to a new service * Make a new service for watcher * Add general ignored items setting for chokidar * Use globalCommons's autoUploadService instance * Reset * Add local settings to ignored files * Asynchronously get ignored items * Remove unused import * Use autoUploadService * Use the globalCommonService everywhere Since the autoUploadService is an instance in Commons, using a global Commons instance will allow everything to use the same instance. * Stop spamming with extension paths * Fix to work with async functions * Add global state to ignored files * Add .DS_Store and sync.lock * Start watcher only after downloading has finished * Inform user that auto upload has started * #805 * #820 * #820 * #821 * #805 * #823 * Go back to webpack and fix source maps * Ignore node_modules and some other files (#826)
1 parent 34b5bf6 commit 7094de0

13 files changed

+222
-500
lines changed

.vscodeignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,10 @@ src/**
77
.gitignore
88
tsconfig.json
99
vsc-extension-quickstart.md
10+
node_modules
11+
.github
12+
debug.log
13+
scripts
14+
tslint.json
15+
webpack.config.js
16+
*.log

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,16 @@
22

33
[![Version](https://vsmarketplacebadge.apphb.com/version/Shan.code-settings-sync.svg)](https://marketplace.visualstudio.com/items?itemName=Shan.code-settings-sync) [![Travis](https://img.shields.io/travis/rust-lang/rust.svg)](https://marketplace.visualstudio.com/items?itemName=Shan.code-settings-sync) [![Master course](https://img.shields.io/badge/Supported%20by-VSCode%20Power%20User%20Course%20%E2%86%92-gray.svg?colorA=444444&colorB=4F44D6)](https://t.co/8BEMyhpKU5?amp=1)
44

5+
#### v3.2.8 - April 04,2019
6+
7+
* Bug : auto upload doesn't work when make change on settings [#801](https://github.com/shanalikhan/code-settings-sync/issues/801) - Thanks for PR [#807](https://github.com/shanalikhan/code-settings-sync/pull/807) by [@arnohovhannisyan](https://github.com/arnohovhannisyan)
8+
* Bug : Auto Upload / Download : Disable change detection for workspace storage folder [#708](https://github.com/shanalikhan/code-settings-sync/issues/708) - Thanks for PR [#811](https://github.com/shanalikhan/code-settings-sync/pull/811) by [@knyhle](https://github.com/knyhle)
9+
* Pretiffy Custom Settings JSON - Thanks for PR [#812](https://github.com/shanalikhan/code-settings-sync/pull/812) by [@knyhle](https://github.com/knyhle)
10+
* Improvement - Remove manual visx package installation in favour of extension download by CLI [#820](https://github.com/shanalikhan/code-settings-sync/issues/820)
11+
* Improvement - Remove replaceCodeSettings from Settings Sync configurations [#805](https://github.com/shanalikhan/code-settings-sync/issues/805)
12+
513
#### v3.2.7 - March 06,2019
14+
615
* Bug : Fixing Extensions Sync on Windows [#789](https://github.com/shanalikhan/code-settings-sync/issues/789) - Thanks for PR [#791](https://github.com/shanalikhan/code-settings-sync/pull/791) by [@LuisUrrutia](https://github.com/LuisUrrutia)
716

817
#### v3.2.6 - March 05,2019

README.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,9 +257,6 @@ You can customize the sync:
257257
"ignoreExtensions": [
258258
"ignored_extension_name"
259259
],
260-
"replaceCodeSettings": {
261-
"http.proxy": "http://my.proxy.address:8080"
262-
},
263260
"gistDescription": "Visual Studio Code Settings Sync Gist",
264261
"version": 310,
265262
"token": "YOUR_GITHUB_TOKEN_HERE",

package.json

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "code-settings-sync",
33
"displayName": "Settings Sync",
44
"description": "Synchronize Settings, Snippets, Themes, File Icons, Launch, Keybindings, Workspaces and Extensions Across Multiple Machines Using GitHub Gist.",
5-
"version": "3.2.7",
5+
"version": "3.2.8",
66
"icon": "images/cloud.png",
77
"publisher": "Shan",
88
"author": {
@@ -46,7 +46,7 @@
4646
"email": "[email protected]"
4747
},
4848
"engines": {
49-
"vscode": "^1.31.1"
49+
"vscode": "^1.32.3"
5050
},
5151
"categories": [
5252
"Other"
@@ -153,24 +153,25 @@
153153
},
154154
"devDependencies": {
155155
"@types/chai": "4.1.7",
156+
"@types/chokidar": "^2.1.3",
156157
"@types/fs-extra": "^5.0.5",
157158
"@types/mocha": "^5.2.6",
158-
"@types/node": "^11.10.4",
159+
"@types/node": "^11.13.0",
159160
"chai": "^4.2.0",
160-
"clean-webpack-plugin": "^2.0.0",
161-
"mocha": "^6.0.0",
161+
"clean-webpack-plugin": "^2.0.1",
162+
"mocha": "^6.0.2",
162163
"prettier": "^1.16.4",
163164
"ts-loader": "^5.3.3",
164-
"tslint": "^5.13.1",
165+
"tslint": "^5.15.0",
165166
"tslint-plugin-prettier": "^2.0.1",
166-
"typescript": "^3.3.3333",
167-
"vscode": "^1.1.30",
167+
"typescript": "^3.4.1",
168+
"vscode": "^1.1.33",
168169
"webpack": "^4.29.6",
169-
"webpack-cli": "^3.2.3"
170+
"webpack-cli": "^3.3.0"
170171
},
171172
"dependencies": {
172173
"@octokit/rest": "^16.16.4",
173-
"adm-zip": "^0.4.13",
174+
"chokidar": "^2.1.5",
174175
"fs-extra": "^7.0.1",
175176
"https-proxy-agent": "^2.2.1",
176177
"lockfile": "^1.0.4",

src/commons.ts

Lines changed: 24 additions & 173 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
"use strict";
2-
import * as fs from "fs-extra";
32
import * as vscode from "vscode";
43
import { Environment } from "./environmentPath";
54
import localize from "./localize";
6-
import * as lockfile from "./lockfile";
5+
import { AutoUploadService } from "./service/autoUploadService";
76
import { File, FileService } from "./service/fileService";
87
import { ExtensionInformation } from "./service/pluginService";
98
import { CustomSettings, ExtensionConfig, LocalConfig } from "./setting";
10-
import { Util } from "./util";
119

1210
export default class Commons {
1311
public static outputChannel: vscode.OutputChannel = null;
@@ -35,7 +33,7 @@ export default class Commons {
3533
message = localize("common.error.invalidGistId");
3634
}
3735
} catch (error) {
38-
// message = error.message;
36+
// message = error.message;
3937
}
4038
}
4139
}
@@ -72,172 +70,26 @@ export default class Commons {
7270
}
7371
}
7472

75-
private static configWatcher = null;
76-
private static extensionWatcher = null;
73+
public autoUploadService: AutoUploadService;
7774

7875
public ERROR_MESSAGE: string = localize("common.error.message");
7976

8077
constructor(
8178
private en: Environment,
8279
private context: vscode.ExtensionContext
83-
) {}
84-
85-
public async StartWatch(): Promise<void> {
86-
const lockExist: boolean = await FileService.FileExists(
87-
this.en.FILE_SYNC_LOCK
88-
);
89-
if (!lockExist) {
90-
fs.closeSync(fs.openSync(this.en.FILE_SYNC_LOCK, "w"));
91-
}
92-
93-
// check is sync locking
94-
if (await lockfile.Check(this.en.FILE_SYNC_LOCK)) {
95-
await lockfile.Unlock(this.en.FILE_SYNC_LOCK);
96-
}
97-
98-
let uploadStopped: boolean = true;
99-
Commons.extensionWatcher = vscode.workspace.createFileSystemWatcher(
100-
this.en.ExtensionFolder + "*"
101-
);
102-
Commons.configWatcher = vscode.workspace.createFileSystemWatcher(
103-
this.en.PATH + "/User/" + "{*,*/*,*/*/*}" // depth: 2
104-
);
105-
106-
// TODO : Uncomment the following lines when code allows feature to update Issue in github code repo - #14444
107-
108-
// Commons.extensionWatcher.on('addDir', (path, stat)=> {
109-
// if (uploadStopped) {
110-
// uploadStopped = false;
111-
// this.InitiateAutoUpload().then((resolve) => {
112-
// uploadStopped = resolve;
113-
// }, (reject) => {
114-
// uploadStopped = reject;
115-
// });
116-
// }
117-
// else {
118-
// vscode.window.setStatusBarMessage("");
119-
// vscode.window.setStatusBarMessage("Sync : Updating In Progres... Please Wait.", 3000);
120-
// }
121-
// });
122-
// Commons.extensionWatcher.on('unlinkDir', (path)=> {
123-
// if (uploadStopped) {
124-
// uploadStopped = false;
125-
// this.InitiateAutoUpload().then((resolve) => {
126-
// uploadStopped = resolve;
127-
// }, (reject) => {
128-
// uploadStopped = reject;
129-
// });
130-
// }
131-
// else {
132-
// vscode.window.setStatusBarMessage("");
133-
// vscode.window.setStatusBarMessage("Sync : Updating In Progres... Please Wait.", 3000);
134-
// }
135-
// });
136-
137-
Commons.configWatcher.onDidChange(async (uri: vscode.Uri) => {
138-
const path: string = uri.path;
139-
140-
// check sync is locking
141-
if (await lockfile.Check(this.en.FILE_SYNC_LOCK)) {
142-
uploadStopped = false;
143-
}
144-
145-
if (!uploadStopped) {
146-
vscode.window.setStatusBarMessage("").dispose();
147-
vscode.window.setStatusBarMessage(
148-
localize("common.info.updating"),
149-
3000
150-
);
151-
return false;
152-
}
153-
154-
uploadStopped = false;
155-
await lockfile.Lock(this.en.FILE_SYNC_LOCK);
156-
const settings: ExtensionConfig = this.GetSettings();
157-
const customSettings: CustomSettings = await this.GetCustomSettings();
158-
if (customSettings == null) {
159-
return;
160-
}
161-
162-
let requiredFileChanged: boolean = false;
163-
if (
164-
customSettings.ignoreUploadFolders.indexOf("workspaceStorage") === -1
165-
) {
166-
requiredFileChanged =
167-
path.indexOf(this.en.FILE_SYNC_LOCK_NAME) === -1 &&
168-
path.indexOf(".DS_Store") === -1 &&
169-
path.indexOf(this.en.FILE_CUSTOMIZEDSETTINGS_NAME) === -1;
170-
} else {
171-
requiredFileChanged =
172-
path.indexOf(this.en.FILE_SYNC_LOCK_NAME) === -1 &&
173-
path.indexOf("workspaceStorage") === -1 &&
174-
path.indexOf(".DS_Store") === -1 &&
175-
path.indexOf(this.en.FILE_CUSTOMIZEDSETTINGS_NAME) === -1;
176-
}
177-
178-
console.log("Sync : File Change Detected On : " + path);
179-
180-
if (requiredFileChanged) {
181-
if (settings.autoUpload) {
182-
if (
183-
customSettings.ignoreUploadFolders.indexOf("workspaceStorage") > -1
184-
) {
185-
const fileType: string = path.substring(
186-
path.lastIndexOf("."),
187-
path.length
188-
);
189-
if (fileType.indexOf("json") === -1) {
190-
console.log(
191-
"Sync : Cannot Initiate Auto-upload on This File (Not JSON)."
192-
);
193-
uploadStopped = true;
194-
return;
195-
}
196-
}
197-
198-
console.log("Sync : Initiating Auto-upload For File : " + path);
199-
this.InitiateAutoUpload(path)
200-
.then(isDone => {
201-
uploadStopped = isDone;
202-
return lockfile.Unlock(this.en.FILE_SYNC_LOCK);
203-
})
204-
.catch(() => {
205-
uploadStopped = true;
206-
return lockfile.Unlock(this.en.FILE_SYNC_LOCK);
207-
});
208-
}
209-
} else {
210-
uploadStopped = true;
211-
await lockfile.Unlock(this.en.FILE_SYNC_LOCK);
212-
}
213-
});
80+
) {
81+
this.InitializeAutoUpload();
21482
}
21583

216-
public async InitiateAutoUpload(path: string): Promise<boolean> {
217-
vscode.window.setStatusBarMessage("").dispose();
218-
vscode.window.setStatusBarMessage(
219-
localize("common.info.initAutoUpload"),
220-
5000
221-
);
222-
223-
await Util.Sleep(3000);
224-
225-
vscode.commands.executeCommand(
226-
"extension.updateSettings",
227-
"forceUpdate",
228-
path
84+
public async InitializeAutoUpload() {
85+
const ignored = await AutoUploadService.GetIgnoredItems(
86+
await this.GetCustomSettings()
22987
);
230-
231-
return true;
232-
}
233-
234-
public CloseWatch(): void {
235-
if (Commons.configWatcher != null) {
236-
Commons.configWatcher.dispose();
237-
}
238-
if (Commons.extensionWatcher != null) {
239-
Commons.extensionWatcher.dispose();
240-
}
88+
this.autoUploadService = new AutoUploadService({
89+
en: this.en,
90+
commons: this,
91+
ignored
92+
});
24193
}
24294

24395
public async InitalizeSettings(
@@ -296,13 +148,8 @@ export default class Commons {
296148
const customSettingStr: string = await FileService.ReadFile(
297149
this.en.FILE_CUSTOMIZEDSETTINGS
298150
);
299-
const tempObj: {
300-
[key: string]: any;
301-
ignoreUploadSettings: string[];
302-
} = JSON.parse(customSettingStr);
303-
if (!Array.isArray(tempObj.ignoreUploadSettings)) {
304-
tempObj.ignoreUploadSettings = [];
305-
}
151+
const tempObj = JSON.parse(customSettingStr);
152+
306153
Object.assign(customSettings, tempObj);
307154
customSettings.token = customSettings.token.trim();
308155
return customSettings;
@@ -328,13 +175,9 @@ export default class Commons {
328175

329176
public async SetCustomSettings(setting: CustomSettings): Promise<boolean> {
330177
try {
331-
const json: { [key: string]: any; ignoreUploadSettings: string[] } = {
332-
...setting
333-
};
334-
delete json.ignoreUploadSettings;
335178
await FileService.WriteFile(
336179
this.en.FILE_CUSTOMIZEDSETTINGS,
337-
JSON.stringify(json)
180+
JSON.stringify(setting, null, 4)
338181
);
339182
return true;
340183
} catch (e) {
@@ -382,6 +225,14 @@ export default class Commons {
382225
});
383226
} else if (customSettings.version < Environment.CURRENT_VERSION) {
384227
fileChanged = true;
228+
// #TODO : Remove this in new update
229+
const newIgnoredList = new CustomSettings().ignoreUploadFiles;
230+
newIgnoredList.forEach(m => {
231+
if (customSettings.ignoreUploadFiles.indexOf(m) === -1) {
232+
customSettings.ignoreUploadFiles.push(m);
233+
}
234+
});
235+
385236
if (this.context.globalState.get("synctoken")) {
386237
const token = this.context.globalState.get("synctoken");
387238
if (token !== "") {

src/environmentPath.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export function osTypeFromString(osName: string): OsType {
1717
}
1818

1919
export class Environment {
20-
public static CURRENT_VERSION: number = 327;
20+
public static CURRENT_VERSION: number = 328;
2121
public static getVersion(): string {
2222
return (
2323
Environment.CURRENT_VERSION.toString().slice(0, 1) +

0 commit comments

Comments
 (0)