Skip to content

Commit

Permalink
connectivity check
Browse files Browse the repository at this point in the history
and bug fixes
  • Loading branch information
Shan Khan authored and Shan Khan committed Sep 17, 2016
1 parent b4bf5c0 commit 2c086b0
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 21 deletions.
5 changes: 3 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": "Visual Studio Code Settings Sync",
"description": "Synchronize Settings, Snippets, launch, keybindings files and extensions Across Multiple Machines using Github GIST.",
"version": "2.2.5",
"version": "2.2.6",
"icon": "images/cloud.png",
"publisher": "Shan",
"author": {
Expand Down Expand Up @@ -88,6 +88,7 @@
"adm-zip": "^0.4.7",
"ncp": "^2.0.0",
"rimraf": "^2.5.4",
"github": "^2.6.0"
"github": "^2.6.0",
"is-online": "^5.1.2"
}
}
14 changes: 13 additions & 1 deletion src/commons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import {File, FileManager} from './fileManager';
import {LocalSetting} from './setting';
import {PluginService, ExtensionInformation} from './pluginService';

var isOnline = require('is-online');

export class Commons {

public ERROR_MESSAGE: string = "Error Logged In Console (Help menu > Toggle Developer Tools). You may open an issue using 'Sync : Open Issue' from advance setting command.";
Expand All @@ -19,6 +21,16 @@ export class Commons {
vscode.window.setStatusBarMessage("");
}

public async InternetConnected(): Promise<boolean> {
return new Promise<boolean>(async (resolve, reject) => {
isOnline(function (err, online) {
resolve(online);
});
});
}



//TODO : change any to LocalSetting after max users migrate to new settings.
public async InitSettings(): Promise<any> {

Expand Down Expand Up @@ -207,7 +219,7 @@ export class Commons {
tempURI = tempURI.replace("/", "\\");
}

//console.log("FILE URI :" +tempURI);
console.log("FILE URI For Summary Page : " + tempURI);

var setting: vscode.Uri = vscode.Uri.parse("untitled:" + tempURI);

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 = 225;
public static CURRENT_VERSION : number = 226;

private context: vscode.ExtensionContext;
public isInsiders = null;
Expand Down
61 changes: 52 additions & 9 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,30 @@ import {OsType, SettingType} from './enums';

export async function activate(context: vscode.ExtensionContext) {


var openurl = require('open');
var fs = require('fs');
var GitHubApi = null;

var github = null;

//migration code starts

var en: Environment = new Environment(context);
var common: commons.Commons = new commons.Commons(en);

var status = await common.InternetConnected();
if (status) {
GitHubApi = require("github");
github = new GitHubApi({
version: "3.0.0"
});
} else {
vscode.window.setStatusBarMessage("Sync : Internet Not Connected.", 3000);
}



var mainSyncSetting: any = null;
var newSetting: LocalSetting = new LocalSetting();
var settingChanged: boolean = false;
Expand Down Expand Up @@ -55,7 +75,9 @@ export async function activate(context: vscode.ExtensionContext) {
var gistAvailable = newSetting.Gist != null && newSetting.Gist != "";

if (tokenAvailable && gistAvailable && newSetting.autoSync) {
vscode.commands.executeCommand('extension.downloadSettings');
if (status) {
vscode.commands.executeCommand('extension.downloadSettings');
}
}
}
}
Expand Down Expand Up @@ -86,17 +108,23 @@ export async function activate(context: vscode.ExtensionContext) {

//migration code ends

var openurl = require('open');
var fs = require('fs');
var GitHubApi = require("github");

var github = new GitHubApi({
version: "3.0.0"
});

var updateSettings = vscode.commands.registerCommand('extension.updateSettings', async () => {
var en: Environment = new Environment(context);
var common: commons.Commons = new commons.Commons(en);

var status = await common.InternetConnected();

if (status) {
GitHubApi = require("github");
github = new GitHubApi({
version: "3.0.0"
});
}
else {
vscode.window.showInformationMessage("Sync :Internet Not Connected.");
return;
}

var myGi: GithubService = null;
var dateNow: Date = new Date();
var syncSetting: LocalSetting = new LocalSetting();
Expand Down Expand Up @@ -275,6 +303,21 @@ export async function activate(context: vscode.ExtensionContext) {

var en: Environment = new Environment(context);
var common: commons.Commons = new commons.Commons(en);

var status = await common.InternetConnected();

if (status) {
GitHubApi = require("github");
github = new GitHubApi({
version: "3.0.0"
});
}
else {
vscode.window.showInformationMessage("Sync : Internet Not Connected.");
return;
}


var myGi: GithubService = null;
var syncSetting: LocalSetting = new LocalSetting();

Expand Down
18 changes: 10 additions & 8 deletions src/githubService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,14 @@
import * as envir from './environmentPath';
import * as fileManager from './fileManager';


var GitHubApi = require("github");

var github = new GitHubApi({
version: "3.0.0"
});


export class GithubService {


private GIST_JSON_EMPTY: any = {
"description": "Visual Studio Code Sync Settings GIST",
"public": false,
Expand Down Expand Up @@ -68,15 +65,22 @@ export class GithubService {
else {
me.GIST_JSON_EMPTY.public = false;
}

return new Promise<string>((resolve, reject) => {
github.getGistsApi().create(me.GIST_JSON_EMPTY
, function (err, res) {
if (err) {
console.error(err);
reject(false);
}
resolve(res.id);
if (res.id) {
resolve(res.id);
} else {
console.error("ID is null");
console.log("Response from GITHUB is: ");
console.log(res);
}

});
});
}
Expand All @@ -100,9 +104,7 @@ export class GithubService {
var allFiles: string[] = Object.keys(gistObject.files);
for (var fileIndex = 0; fileIndex < allFiles.length; fileIndex++) {
var fileName = allFiles[fileIndex];
// if (fileName.indexOf(".") < 0) {
// gistObject.files[fileName] = null;
// }

var exists = false;

files.forEach((settingFile) => {
Expand Down

0 comments on commit 2c086b0

Please sign in to comment.