Skip to content

Commit

Permalink
Merge pull request #183 from shanalikhan/anonymousGist
Browse files Browse the repository at this point in the history
Anonymous gist #168 #180
  • Loading branch information
shanalikhan authored Jan 6, 2017
2 parents 7178065 + 404478b commit 8274946
Show file tree
Hide file tree
Showing 7 changed files with 254 additions and 188 deletions.
18 changes: 15 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

**Type Sync in command Palette in order to view all commands.**

**Note :** Latest Update is available for Code Version 1.9+ as currently its in insiders and I want to make sure that it works well to publish in normal release.

## Key Features
```
1. Use your github account token and Gist.
Expand Down Expand Up @@ -138,6 +136,18 @@ Select Command **"Sync : Advance Options > Share Settings with Public GIST"**
Other users can give your Gist Id to download the Gist, but they cant upload their settings on your Gist.


## Workspaces Sync

By default, extension will not sync your WorkspaceStorage folder. You need to set `sync.workspaceSync` to true in order to enable this. It will only sync the `.json` files inside your WorkspaceStorage folder.

## Creating and Downloading Settings From Anonymous Gist

**Turned Off** by default. Github provides a way to create Anonymous Gist so you can create Anonymous Gist without adding your account information (token). But you cant make change on Anonymous Gist once created, its the limitation from the Github so extension will always create new Anonymous Gist upon uploading the settings, you can download the settings from any Anonymous Gist without adding your account information.

To turn on the Anonymous Gist , set `sync.anonymousGist` to true



## Settings

```
Expand All @@ -149,7 +159,9 @@ Other users can give your Gist Id to download the Gist, but they cant upload the
"sync.autoUpload": true,
"sync.lastDownload": "2016-12-27T15:58:35.760Z",
"sync.showSummary": true,
"sync.forceDownload": true
"sync.forceDownload": true,
"sync.workspaceSync": false,
"sync.anonymousGist": false
```


Expand Down
9 changes: 7 additions & 2 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, launch, keybindings, workspaces and extensions Across Multiple Machines using Github Gist.",
"version": "2.4.1",
"version": "2.4.2",
"icon": "images/cloud.png",
"publisher": "Shan",
"author": {
Expand All @@ -24,7 +24,7 @@
"email": "[email protected]"
},
"engines": {
"vscode": "^1.9.0"
"vscode": "^1.8.0"
},
"categories": [
"Other"
Expand Down Expand Up @@ -124,6 +124,11 @@
"type": "boolean",
"default": false,
"description": "Set it to true if you want to sync the workspaceStorage folder. It will only upload .json files."
},
"sync.anonymousGist": {
"type": "boolean",
"default": false,
"description": "Set it to true if you want to create or download from Anonymous Gist. Extension won't ask for Github token"
}
},
"title": "Code Settings Sync Configuration Settings"
Expand Down
57 changes: 34 additions & 23 deletions src/commons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,13 @@ export class Commons {

}

public async InitializeSettings(askInformation: boolean, askGIST: boolean): Promise<ExtensionConfig> {
public async InitializeSettings(settings: ExtensionConfig, askToken: boolean, askGIST: boolean): Promise<ExtensionConfig> {
let config = vscode.workspace.getConfiguration('sync');
let me: Commons = this;

return new Promise<ExtensionConfig>(async (resolve, reject) => {

let settings: ExtensionConfig = await me.GetSettings();

if (askInformation) {
if (askToken) {
if (settings.token == null || settings.token == "") {
openurl("https://github.com/settings/tokens");

Expand All @@ -184,24 +182,25 @@ export class Commons {
reject(err);
});
}
}

if (askGIST) {
if (settings.gist == null || settings.gist === "") {
await me.GetGistAndSave(settings).then(function (Gist: string) {
if (Gist) {
settings.gist = Gist;
}
else {
vscode.window.showErrorMessage("Sync : Gist Not Saved.");
reject(false);
}
}, function (err: any) {
me.LogException(err, me.ERROR_MESSAGE, true);
reject(err);
});
}
if (askGIST) {
if (settings.gist == null || settings.gist === "") {
await me.GetGistAndSave(settings).then(function (Gist: string) {
if (Gist) {
settings.gist = Gist;
}
else {
vscode.window.showErrorMessage("Sync : Gist Not Saved.");
reject(false);
}
}, function (err: any) {
me.LogException(err, me.ERROR_MESSAGE, true);
reject(err);
});
}
}

resolve(settings);
});
}
Expand Down Expand Up @@ -231,7 +230,8 @@ export class Commons {
await me.SaveSettings(newSetting).then(async function (done) {
if (done) {
vscode.window.showInformationMessage("Sync : Now this extension follows standard code configuration to setup this extension. Settings are migrated.");
vscode.window.showInformationMessage("Sync : To Make it fully work you need to upload the settings once again. Uploading the Settings.");
vscode.window.showInformationMessage("Sync : To Make it fully work you need to upload the settings once again. Extension is uploading the settings.");
vscode.window.showInformationMessage("Sync : To Make it fully work you need to download the settings on others computer using this extension verion.");
await FileManager.DeleteFile(me.en.APP_SETTINGS);
vscode.commands.executeCommand('extension.updateSettings');
}
Expand All @@ -250,7 +250,7 @@ export class Commons {
}
settings.version = Environment.CURRENT_VERSION;
await me.SaveSettings(settings);
vscode.window.setStatusBarMessage("Sync : Settings Version Updated",2000);
vscode.window.setStatusBarMessage("Sync : Settings Version Updated", 2000);
}
}
resolve(true);
Expand Down Expand Up @@ -294,7 +294,7 @@ export class Commons {
if (me.context.globalState.get('syncCounter')) {
let counter = me.context.globalState.get('syncCounter');
let count: number = parseInt(String(counter));
if (count % 100 == 0) {
if (count % 30 == 0) {
vscode.window.showInformationMessage("Sync : Did you like this extension ? How about writing a review or send me some donation ;) ");
}
count = count + 1;
Expand Down Expand Up @@ -327,6 +327,9 @@ export class Commons {
let token = this.context.globalState.get('synctoken');
settings[key] = String(token);
}
else {
settings[key] = null;
}
}
});
return settings;
Expand Down Expand Up @@ -436,12 +439,20 @@ export class Commons {
e.edit(edit => {
edit.insert(new vscode.Position(0, 0), "VISUAL STUDIO CODE SETTINGS SYNC\r\n\r\n" + status + " SUMMARY\r\n\r\n");
edit.insert(new vscode.Position(1, 0), "--------------------\r\n");
let tokenPlaceHolder: string = "Anonymous";
if (syncSettings.config.token != "") {
tokenPlaceHolder = syncSettings.config.token;
}

edit.insert(new vscode.Position(2, 0), "GITHUB TOKEN: " + syncSettings.config.token + "\r\n");
edit.insert(new vscode.Position(2, 0), "GITHUB TOKEN: " + tokenPlaceHolder + "\r\n");
edit.insert(new vscode.Position(3, 0), "GITHUB GIST: " + syncSettings.config.gist + "\r\n");
var type: string = (syncSettings.publicGist == true) ? "Public" : "Secret"
edit.insert(new vscode.Position(4, 0), "GITHUB GIST TYPE: " + type + "\r\n\r\n");
edit.insert(new vscode.Position(5, 0), "--------------------\r\n\r\n");
if (syncSettings.config.token == "") {
edit.insert(new vscode.Position(5, 0), "Anonymous Gist Cant be edited, extension will always create new one during upload.\r\n\r\n");
}


edit.insert(new vscode.Position(6, 0), header + "\r\n");
var row: number = 6;
Expand Down
2 changes: 1 addition & 1 deletion src/environmentPath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {OsType} from './enums';

export class Environment {

public static CURRENT_VERSION : number = 241;
public static CURRENT_VERSION : number = 242;

private context: vscode.ExtensionContext;
public isInsiders = null;
Expand Down
Loading

0 comments on commit 8274946

Please sign in to comment.