Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactoring: OS Support List moved to Widget
- Loading branch information
Delfer
committed
May 16, 2018
1 parent
3b013f2
commit a8bd5af
Showing
5 changed files
with
172 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,17 @@ | ||
files: | ||
- node_modules/**/* | ||
- plugins/* | ||
- scripts/* | ||
- ui/**/* | ||
- "*.js" | ||
- "package.json" | ||
# Standart for electron-builder: https://www.electron.build/file-patterns | ||
- "!**/node_modules/*/{CHANGELOG.md,README.md,README,readme.md,readme,test,__tests__,tests,powered-test,example,examples,*.d.ts}" | ||
- "!**/node_modules/.bin" | ||
- "!**/*.{iml,o,hprof,orig,pyc,pyo,rbc,swp,csproj,sln,xproj}" | ||
- "!**/._*" | ||
- "!.editorconfig" | ||
- "!**/{.DS_Store,.git,.hg,.svn,CVS,RCS,SCCS,__pycache__,thumbs.db,.gitignore,.gitattributes,.flowconfig,.yarn-metadata.json,.idea,.vs,appveyor.yml,.travis.yml,circle.yml,npm-debug.log,.nyc_output,yarn.lock,.yarn-integrity}" | ||
|
||
asar: true | ||
files: | ||
- node_modules/**/* | ||
- plugins/* | ||
- widgets/* | ||
- scripts/* | ||
- ui/**/* | ||
- "*.js" | ||
- "package.json" | ||
# Standart for electron-builder: https://www.electron.build/file-patterns | ||
- "!**/node_modules/*/{CHANGELOG.md,README.md,README,readme.md,readme,test,__tests__,tests,powered-test,example,examples,*.d.ts}" | ||
- "!**/node_modules/.bin" | ||
- "!**/*.{iml,o,hprof,orig,pyc,pyo,rbc,swp,csproj,sln,xproj}" | ||
- "!**/._*" | ||
- "!.editorconfig" | ||
- "!**/{.DS_Store,.git,.hg,.svn,CVS,RCS,SCCS,__pycache__,thumbs.db,.gitignore,.gitattributes,.flowconfig,.yarn-metadata.json,.idea,.vs,appveyor.yml,.travis.yml,circle.yml,npm-debug.log,.nyc_output,yarn.lock,.yarn-integrity}" | ||
|
||
asar: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[ | ||
require("./os") | ||
] | ||
.forEach(i => i.load(exports)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
var sshell = require('../sshell'); | ||
|
||
var osName; | ||
|
||
var widget = { | ||
init: con => { | ||
return new Promise((resolve, reject) => { | ||
sshell.runCmd(con, 'cat /etc/*-release').then(res => { | ||
var pretty = res.toString().match(/PRETTY_NAME="(.+)"/); | ||
if (pretty) { | ||
osName = pretty[1]; | ||
} else { | ||
var description = res.toString().match(/DISTRIB_DESCRIPTION="(.+)"/); | ||
if (description) { | ||
osName = description[1]; | ||
} else { | ||
osName = res.toString(); | ||
} | ||
} | ||
resolve(osName); | ||
}, reject); | ||
}); | ||
}, | ||
|
||
isSupported: false, | ||
|
||
getView: list_ => { | ||
var list = JSON.parse(JSON.stringify(list_)); //Deep copy | ||
|
||
// OS check | ||
list.forEach(os => { | ||
var re = new RegExp(os.name, 'i'); | ||
if (re.test(osName)) { | ||
os.supported = true; | ||
if (os.version && os.version.length > 0) { | ||
os.version.forEach(v => { | ||
re = new RegExp(v, 'i'); | ||
if (re.test(osName)) { | ||
os.supportedVersion = v; | ||
} | ||
}); | ||
} | ||
} | ||
}); | ||
|
||
//UI build | ||
widget.isSupported = false; | ||
var ui = `<p class="container text-muted p-0"> | ||
<label>Supported OS:</label><br>`; | ||
list.forEach((os, num) => { | ||
var c = ''; | ||
if ( | ||
(os.supported && os.version && os.version.length > 0 && os.supportedVersion) || | ||
(os.supported && os.version && os.version.length === 0) || | ||
(os.supported && !os.version) | ||
) { | ||
widget.isSupported = true; | ||
c = ' badge-success'; | ||
} else if (os.supported) { | ||
c = ' badge-danger'; | ||
} | ||
ui += '<label class="badge' + c + '">' + os.name + '</label>'; | ||
|
||
if (os.version && os.version.length > 0) { | ||
os.version.forEach(v => { | ||
if (os.supported && v === os.supportedVersion) { | ||
c = ' badge-success'; | ||
} else { | ||
c = ''; | ||
} | ||
ui += '<label class="badge' + c + '">' + v + '</label>'; | ||
}); | ||
} | ||
|
||
if (num != (list.length - 1)) { | ||
if (num % 2 === 1) { | ||
ui += '<br>'; | ||
} else { | ||
ui += '| '; | ||
} | ||
} | ||
}); | ||
|
||
if (!widget.isSupported) { | ||
if (list.length % 2 === 0) { | ||
ui += '<br>'; | ||
} else { | ||
ui += '| '; | ||
} | ||
|
||
if (!osName || osName.length < 1) { | ||
osName = 'Unknown'; | ||
} | ||
ui += '<label class="badge badge-danger">' + osName.split(/\s+/).slice(0, 3).join(' ').substr(0, 32) + '</label>'; | ||
} | ||
|
||
ui += `</p>`; | ||
return ui; | ||
} | ||
}; | ||
|
||
exports.load = widgets => { | ||
widgets.os = widget; | ||
}; |