Skip to content

Commit

Permalink
V3.2.8 (#821)
Browse files Browse the repository at this point in the history
* #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)
  • Loading branch information
shanalikhan committed Apr 4, 2019
1 parent 34b5bf6 commit 7094de0
Show file tree
Hide file tree
Showing 13 changed files with 222 additions and 500 deletions.
7 changes: 7 additions & 0 deletions .vscodeignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,10 @@ src/**
.gitignore
tsconfig.json
vsc-extension-quickstart.md
node_modules
.github
debug.log
scripts
tslint.json
webpack.config.js
*.log
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@

[![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)

#### v3.2.8 - April 04,2019

* 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)
* 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)
* Pretiffy Custom Settings JSON - Thanks for PR [#812](https://github.com/shanalikhan/code-settings-sync/pull/812) by [@knyhle](https://github.com/knyhle)
* Improvement - Remove manual visx package installation in favour of extension download by CLI [#820](https://github.com/shanalikhan/code-settings-sync/issues/820)
* Improvement - Remove replaceCodeSettings from Settings Sync configurations [#805](https://github.com/shanalikhan/code-settings-sync/issues/805)

#### v3.2.7 - March 06,2019

* 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)

#### v3.2.6 - March 05,2019
Expand Down
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,6 @@ You can customize the sync:
"ignoreExtensions": [
"ignored_extension_name"
],
"replaceCodeSettings": {
"http.proxy": "http://my.proxy.address:8080"
},
"gistDescription": "Visual Studio Code Settings Sync Gist",
"version": 310,
"token": "YOUR_GITHUB_TOKEN_HERE",
Expand Down
21 changes: 11 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "code-settings-sync",
"displayName": "Settings Sync",
"description": "Synchronize Settings, Snippets, Themes, File Icons, Launch, Keybindings, Workspaces and Extensions Across Multiple Machines Using GitHub Gist.",
"version": "3.2.7",
"version": "3.2.8",
"icon": "images/cloud.png",
"publisher": "Shan",
"author": {
Expand Down Expand Up @@ -46,7 +46,7 @@
"email": "shanalikhan@hotmail.com"
},
"engines": {
"vscode": "^1.31.1"
"vscode": "^1.32.3"
},
"categories": [
"Other"
Expand Down Expand Up @@ -153,24 +153,25 @@
},
"devDependencies": {
"@types/chai": "4.1.7",
"@types/chokidar": "^2.1.3",
"@types/fs-extra": "^5.0.5",
"@types/mocha": "^5.2.6",
"@types/node": "^11.10.4",
"@types/node": "^11.13.0",
"chai": "^4.2.0",
"clean-webpack-plugin": "^2.0.0",
"mocha": "^6.0.0",
"clean-webpack-plugin": "^2.0.1",
"mocha": "^6.0.2",
"prettier": "^1.16.4",
"ts-loader": "^5.3.3",
"tslint": "^5.13.1",
"tslint": "^5.15.0",
"tslint-plugin-prettier": "^2.0.1",
"typescript": "^3.3.3333",
"vscode": "^1.1.30",
"typescript": "^3.4.1",
"vscode": "^1.1.33",
"webpack": "^4.29.6",
"webpack-cli": "^3.2.3"
"webpack-cli": "^3.3.0"
},
"dependencies": {
"@octokit/rest": "^16.16.4",
"adm-zip": "^0.4.13",
"chokidar": "^2.1.5",
"fs-extra": "^7.0.1",
"https-proxy-agent": "^2.2.1",
"lockfile": "^1.0.4",
Expand Down
197 changes: 24 additions & 173 deletions src/commons.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
"use strict";
import * as fs from "fs-extra";
import * as vscode from "vscode";
import { Environment } from "./environmentPath";
import localize from "./localize";
import * as lockfile from "./lockfile";
import { AutoUploadService } from "./service/autoUploadService";
import { File, FileService } from "./service/fileService";
import { ExtensionInformation } from "./service/pluginService";
import { CustomSettings, ExtensionConfig, LocalConfig } from "./setting";
import { Util } from "./util";

export default class Commons {
public static outputChannel: vscode.OutputChannel = null;
Expand Down Expand Up @@ -35,7 +33,7 @@ export default class Commons {
message = localize("common.error.invalidGistId");
}
} catch (error) {
// message = error.message;
// message = error.message;
}
}
}
Expand Down Expand Up @@ -72,172 +70,26 @@ export default class Commons {
}
}

private static configWatcher = null;
private static extensionWatcher = null;
public autoUploadService: AutoUploadService;

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

constructor(
private en: Environment,
private context: vscode.ExtensionContext
) {}

public async StartWatch(): Promise<void> {
const lockExist: boolean = await FileService.FileExists(
this.en.FILE_SYNC_LOCK
);
if (!lockExist) {
fs.closeSync(fs.openSync(this.en.FILE_SYNC_LOCK, "w"));
}

// check is sync locking
if (await lockfile.Check(this.en.FILE_SYNC_LOCK)) {
await lockfile.Unlock(this.en.FILE_SYNC_LOCK);
}

let uploadStopped: boolean = true;
Commons.extensionWatcher = vscode.workspace.createFileSystemWatcher(
this.en.ExtensionFolder + "*"
);
Commons.configWatcher = vscode.workspace.createFileSystemWatcher(
this.en.PATH + "/User/" + "{*,*/*,*/*/*}" // depth: 2
);

// TODO : Uncomment the following lines when code allows feature to update Issue in github code repo - #14444

// Commons.extensionWatcher.on('addDir', (path, stat)=> {
// if (uploadStopped) {
// uploadStopped = false;
// this.InitiateAutoUpload().then((resolve) => {
// uploadStopped = resolve;
// }, (reject) => {
// uploadStopped = reject;
// });
// }
// else {
// vscode.window.setStatusBarMessage("");
// vscode.window.setStatusBarMessage("Sync : Updating In Progres... Please Wait.", 3000);
// }
// });
// Commons.extensionWatcher.on('unlinkDir', (path)=> {
// if (uploadStopped) {
// uploadStopped = false;
// this.InitiateAutoUpload().then((resolve) => {
// uploadStopped = resolve;
// }, (reject) => {
// uploadStopped = reject;
// });
// }
// else {
// vscode.window.setStatusBarMessage("");
// vscode.window.setStatusBarMessage("Sync : Updating In Progres... Please Wait.", 3000);
// }
// });

Commons.configWatcher.onDidChange(async (uri: vscode.Uri) => {
const path: string = uri.path;

// check sync is locking
if (await lockfile.Check(this.en.FILE_SYNC_LOCK)) {
uploadStopped = false;
}

if (!uploadStopped) {
vscode.window.setStatusBarMessage("").dispose();
vscode.window.setStatusBarMessage(
localize("common.info.updating"),
3000
);
return false;
}

uploadStopped = false;
await lockfile.Lock(this.en.FILE_SYNC_LOCK);
const settings: ExtensionConfig = this.GetSettings();
const customSettings: CustomSettings = await this.GetCustomSettings();
if (customSettings == null) {
return;
}

let requiredFileChanged: boolean = false;
if (
customSettings.ignoreUploadFolders.indexOf("workspaceStorage") === -1
) {
requiredFileChanged =
path.indexOf(this.en.FILE_SYNC_LOCK_NAME) === -1 &&
path.indexOf(".DS_Store") === -1 &&
path.indexOf(this.en.FILE_CUSTOMIZEDSETTINGS_NAME) === -1;
} else {
requiredFileChanged =
path.indexOf(this.en.FILE_SYNC_LOCK_NAME) === -1 &&
path.indexOf("workspaceStorage") === -1 &&
path.indexOf(".DS_Store") === -1 &&
path.indexOf(this.en.FILE_CUSTOMIZEDSETTINGS_NAME) === -1;
}

console.log("Sync : File Change Detected On : " + path);

if (requiredFileChanged) {
if (settings.autoUpload) {
if (
customSettings.ignoreUploadFolders.indexOf("workspaceStorage") > -1
) {
const fileType: string = path.substring(
path.lastIndexOf("."),
path.length
);
if (fileType.indexOf("json") === -1) {
console.log(
"Sync : Cannot Initiate Auto-upload on This File (Not JSON)."
);
uploadStopped = true;
return;
}
}

console.log("Sync : Initiating Auto-upload For File : " + path);
this.InitiateAutoUpload(path)
.then(isDone => {
uploadStopped = isDone;
return lockfile.Unlock(this.en.FILE_SYNC_LOCK);
})
.catch(() => {
uploadStopped = true;
return lockfile.Unlock(this.en.FILE_SYNC_LOCK);
});
}
} else {
uploadStopped = true;
await lockfile.Unlock(this.en.FILE_SYNC_LOCK);
}
});
) {
this.InitializeAutoUpload();
}

public async InitiateAutoUpload(path: string): Promise<boolean> {
vscode.window.setStatusBarMessage("").dispose();
vscode.window.setStatusBarMessage(
localize("common.info.initAutoUpload"),
5000
);

await Util.Sleep(3000);

vscode.commands.executeCommand(
"extension.updateSettings",
"forceUpdate",
path
public async InitializeAutoUpload() {
const ignored = await AutoUploadService.GetIgnoredItems(
await this.GetCustomSettings()
);

return true;
}

public CloseWatch(): void {
if (Commons.configWatcher != null) {
Commons.configWatcher.dispose();
}
if (Commons.extensionWatcher != null) {
Commons.extensionWatcher.dispose();
}
this.autoUploadService = new AutoUploadService({
en: this.en,
commons: this,
ignored
});
}

public async InitalizeSettings(
Expand Down Expand Up @@ -296,13 +148,8 @@ export default class Commons {
const customSettingStr: string = await FileService.ReadFile(
this.en.FILE_CUSTOMIZEDSETTINGS
);
const tempObj: {
[key: string]: any;
ignoreUploadSettings: string[];
} = JSON.parse(customSettingStr);
if (!Array.isArray(tempObj.ignoreUploadSettings)) {
tempObj.ignoreUploadSettings = [];
}
const tempObj = JSON.parse(customSettingStr);

Object.assign(customSettings, tempObj);
customSettings.token = customSettings.token.trim();
return customSettings;
Expand All @@ -328,13 +175,9 @@ export default class Commons {

public async SetCustomSettings(setting: CustomSettings): Promise<boolean> {
try {
const json: { [key: string]: any; ignoreUploadSettings: string[] } = {
...setting
};
delete json.ignoreUploadSettings;
await FileService.WriteFile(
this.en.FILE_CUSTOMIZEDSETTINGS,
JSON.stringify(json)
JSON.stringify(setting, null, 4)
);
return true;
} catch (e) {
Expand Down Expand Up @@ -382,6 +225,14 @@ export default class Commons {
});
} else if (customSettings.version < Environment.CURRENT_VERSION) {
fileChanged = true;
// #TODO : Remove this in new update
const newIgnoredList = new CustomSettings().ignoreUploadFiles;
newIgnoredList.forEach(m => {
if (customSettings.ignoreUploadFiles.indexOf(m) === -1) {
customSettings.ignoreUploadFiles.push(m);
}
});

if (this.context.globalState.get("synctoken")) {
const token = this.context.globalState.get("synctoken");
if (token !== "") {
Expand Down
2 changes: 1 addition & 1 deletion src/environmentPath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export function osTypeFromString(osName: string): OsType {
}

export class Environment {
public static CURRENT_VERSION: number = 327;
public static CURRENT_VERSION: number = 328;
public static getVersion(): string {
return (
Environment.CURRENT_VERSION.toString().slice(0, 1) +
Expand Down
Loading

0 comments on commit 7094de0

Please sign in to comment.