This commit is contained in:
huaji 2019-07-20 21:35:43 +08:00
parent d54d348e86
commit 768c208d47
11 changed files with 155 additions and 43 deletions

2
.gitignore vendored
View File

@ -2,3 +2,5 @@ node_modules
test test
.vscode .vscode
.vsixmanifest .vsixmanifest
firstload.lock
*.vsix

1
.vscodeignore Normal file
View File

@ -0,0 +1 @@
firstload.lock

View File

@ -10,7 +10,7 @@ Enable Acrylic/Glass effect for your VS Code.
[![](https://img.shields.io/github/stars/eyhn/vscode-vibrancy.svg?style=social)](https://github.com/eyhn/vscode-vibrancy)  [![](https://img.shields.io/github/stars/eyhn/vscode-vibrancy.svg?style=social)](https://github.com/eyhn/vscode-vibrancy) 
[![](https://img.shields.io/github/watchers/eyhn/vscode-vibrancy.svg?style=social)](https://github.com/eyhn/vscode-vibrancy) [![](https://img.shields.io/github/watchers/eyhn/vscode-vibrancy.svg?style=social)](https://github.com/eyhn/vscode-vibrancy)
Links: [Github](https://github.com/eyhn/vscode-vibrancy)  [Visual Studio Code Marketplace](https://marketplace.visualstudio.com/items?itemName=eyhn.vscode-vibrancy) Links: [Github](https://github.com/eyhn/vscode-vibrancy) | [Visual Studio Code Marketplace](https://marketplace.visualstudio.com/items?itemName=eyhn.vscode-vibrancy) | [issues](https://github.com/eyhn/vscode-vibrancy/issues)
## Supported Operating Systems ## Supported Operating Systems
@ -40,6 +40,22 @@ So, a information appears while the first time to install or vscode update.U can
![screenshot](./warns.png) ![screenshot](./warns.png)
## Options
#### vscode_vibrancy.type (Windows Only)
Native method of Vibrancy Effect.
* auto : Automatically switch with system version.
* dwm : (Windows 7 only) Windows Aero blur.
* acrylic : (Windows 10 only) Fluent Design blur.
#### vscode_vibrancy.opacity (Windows Only)
Opacity of Vibrancy Effect.
*value: 0.0 ~ 0.1*
## FAQs ## FAQs
### How to uninstall? ### How to uninstall?

7
package-lock.json generated
View File

@ -1,6 +1,6 @@
{ {
"name": "vscode-vibrancy", "name": "vscode-vibrancy",
"version": "1.0.0", "version": "1.0.1",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {
@ -9,6 +9,11 @@
"resolved": "https://registry.npmjs.org/file-url/-/file-url-2.0.2.tgz", "resolved": "https://registry.npmjs.org/file-url/-/file-url-2.0.2.tgz",
"integrity": "sha1-6VF4TXkJUSfTcTApqwY/QIGMoq4=" "integrity": "sha1-6VF4TXkJUSfTcTApqwY/QIGMoq4="
}, },
"windows-blurbehind": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/windows-blurbehind/-/windows-blurbehind-1.0.1.tgz",
"integrity": "sha512-1HzHfCiM1ayrbACJu5qE9zELV24uX/tINT6kxaZwLY3rtQAoeav6x9z7LFHWoLaGDN/sYbnK+9Vk0cz7fsk5HQ=="
},
"xmlhttprequest": { "xmlhttprequest": {
"version": "1.8.0", "version": "1.8.0",
"resolved": "https://registry.npmjs.org/xmlhttprequest/-/xmlhttprequest-1.8.0.tgz", "resolved": "https://registry.npmjs.org/xmlhttprequest/-/xmlhttprequest-1.8.0.tgz",

View File

@ -2,7 +2,7 @@
"name": "vscode-vibrancy", "name": "vscode-vibrancy",
"displayName": "Vibrancy", "displayName": "Vibrancy",
"description": "Vibrancy Effect for Visual Studio Code", "description": "Vibrancy Effect for Visual Studio Code",
"version": "1.0.1", "version": "1.0.2",
"publisher": "eyhn", "publisher": "eyhn",
"author": { "author": {
"email": "cneyhn@gmail.com", "email": "cneyhn@gmail.com",
@ -46,11 +46,33 @@
"command": "extension.updateVibrancy", "command": "extension.updateVibrancy",
"title": "Reload Vibrancy" "title": "Reload Vibrancy"
} }
] ],
"configuration": {
"title": "Vibrancy Effect",
"properties": {
"vscode_vibrancy.type": {
"description": "(Windows Only) Native method of Vibrancy Effect",
"type": "string",
"default": "auto",
"enum": [
"auto",
"dwm",
"acrylic"
],
"enumDescriptions": [
"Automatically switch with system version",
"(Windows 7 only) Windows default window blur",
"(Windows 10 only) Fluent design blur"
]
},
"vscode_vibrancy.opacity": {
"description": "(Windows Only) Acrylic material opacity.",
"type": "number",
"default": "0.8"
}
}
}
}, },
"devDependencies": {}, "devDependencies": {},
"dependencies": { "dependencies": {}
"file-url": "^2.0.2",
"xmlhttprequest": "^1.8.0"
}
} }

BIN
src/blur-cli.exe Normal file

Binary file not shown.

Binary file not shown.

View File

@ -1,33 +1,62 @@
var vscode = require('vscode'); var vscode = require('vscode');
var fs = require('fs'); var fs = require('fs');
var os = require('os');
var path = require('path'); var path = require('path');
var events = require('events'); var events = require('events');
var msg = require('./messages').messages; var msg = require('./messages').messages;
var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest; var lockPath = path.join(__dirname, '../firstload.lock');
var fileUrl = require('file-url'); var isWin = /^win/.test(process.platform);
var isWin10 = isWin && os.release().split(".").map(Number)[0] === 10;
function activate(context) { function deepEqual(obj1, obj2) {
console.log('vscode-vibrancy is active!'); if(obj1 === obj2) // it's just the same object. No need to compare.
return true;
process.on('uncaughtException', function (err) { if(isPrimitive(obj1) && isPrimitive(obj2)) // compare primitives
if (/ENOENT|EACCES|EPERM/.test(err.code)) { return obj1 === obj2;
vscode.window.showInformationMessage(msg.admin);
return;
}
});
var eventEmitter = new events.EventEmitter(); if(Object.keys(obj1).length !== Object.keys(obj2).length)
var isWin = /^win/.test(process.platform); return false;
var appDir = path.dirname(require.main.filename);
var base = appDir + (isWin ? '\\vs\\code' : '/vs/code'); // compare objects with same number of keys
for(let key in obj1)
{
if(!(key in obj2)) return false; //other object doesn't have this prop
if(!deepEqual(obj1[key], obj2[key])) return false;
}
var htmlFile = base + (isWin ? '\\electron-browser\\workbench\\workbench.html' : '/electron-browser/workbench/workbench.html'); return true;
var htmlFileBack = base + (isWin ? '\\electron-browser\\workbench\\workbench.html.bak-vibrancy' : '/electron-browser/workbench/workbench.bak-vibrancy'); }
var injectHTML = ` //check if value is primitive
function isPrimitive(obj)
{
return (obj !== Object(obj));
}
function isFirstload() {
try {
fs.readFileSync(lockPath);
return false
} catch (err) {
return true
}
}
function lockFirstload() {
fs.writeFileSync(lockPath, '', () => {});
}
function injectHTML(config) {
var type = config.type;
if (type === 'auto') {
type = isWin10 ? 'acrylic' : 'dwm';
}
var enableBackground = isWin && type == 'dwm';
return `
<script> <script>
w = nodeRequire('electron') w = nodeRequire('electron')
.remote .remote
@ -36,10 +65,8 @@ function activate(context) {
w.setBackgroundColor('#00000000'); w.setBackgroundColor('#00000000');
${isWin ? ${isWin ?
` `nodeRequire("child_process")
bbnative = nodeRequire(${JSON.stringify(__dirname + '\\blurbehind.node')}); .spawn(${JSON.stringify(__dirname + '\\blur-cli.exe')}, [new Uint32Array(w.getNativeWindowHandle().buffer)[0], '--type', ${JSON.stringify(type)}, '--enable', 'true', '--opacity', ${JSON.stringify(config.opacity)}]);` :
bbnative.blurbehind(w.getNativeWindowHandle(), true);
` :
`w.setVibrancy('ultra-dark');` `w.setVibrancy('ultra-dark');`
} }
@ -56,7 +83,7 @@ function activate(context) {
<style> <style>
html { html {
background: 'transparent' !important; background: ${enableBackground ? `rgba(30,30,30,${config.opacity})` : 'transparent'} !important;
} }
.scroll-decoration { .scroll-decoration {
@ -130,7 +157,6 @@ function activate(context) {
} }
.extension-editor, .extension-editor,
.monaco-inputbox>.wrapper>.input,
.monaco-workbench>.part.editor>.content>.one-editor-silo>.container>.title .tabs-container>.tab.active, .monaco-workbench>.part.editor>.content>.one-editor-silo>.container>.title .tabs-container>.tab.active,
.preferences-editor>.preferences-header, .preferences-editor>.preferences-header,
.preferences-editor>.preferences-editors-container.side-by-side-preferences-editor .preferences-header-container, .preferences-editor>.preferences-editors-container.side-by-side-preferences-editor .preferences-header-container,
@ -149,16 +175,27 @@ function activate(context) {
} }
</style> </style>
` `
}
function httpGet(theUrl) function activate(context) {
{
var xmlHttp = null;
xmlHttp = new XMLHttpRequest(); console.log('vscode-vibrancy is active!');
xmlHttp.open( "GET", theUrl, false );
xmlHttp.send( null ); process.on('uncaughtException', function (err) {
return xmlHttp.responseText; if (/ENOENT|EACCES|EPERM/.test(err.code)) {
} vscode.window.showInformationMessage(msg.admin);
return;
}
});
var eventEmitter = new events.EventEmitter();
var isWin = /^win/.test(process.platform);
var appDir = path.dirname(require.main.filename);
var base = appDir + (isWin ? '\\vs\\code' : '/vs/code');
var htmlFile = base + (isWin ? '\\electron-browser\\workbench\\workbench.html' : '/electron-browser/workbench/workbench.html');
var htmlFileBack = base + (isWin ? '\\electron-browser\\workbench\\workbench.html.bak-vibrancy' : '/electron-browser/workbench/workbench.bak-vibrancy');
function replaceCss() { function replaceCss() {
try { try {
@ -168,9 +205,8 @@ function activate(context) {
html = html.replace(/<meta.*http-equiv="Content-Security-Policy".*>/, ''); html = html.replace(/<meta.*http-equiv="Content-Security-Policy".*>/, '');
html = html.replace(/(<\/html>)/, html = html.replace(/(<\/html>)/,
'<!-- !! VSCODE-VIBRANCY-START !! -->' + injectHTML + '<!-- !! VSCODE-VIBRANCY-END !! --></html>'); '<!-- !! VSCODE-VIBRANCY-START !! -->' + injectHTML(vscode.workspace.getConfiguration("vscode_vibrancy")) + '<!-- !! VSCODE-VIBRANCY-END !! --></html>');
fs.writeFileSync(htmlFile, html, 'utf-8'); fs.writeFileSync(htmlFile, html, 'utf-8');
enabledRestart();
} catch (e) { } catch (e) {
console.log(e); console.log(e);
} }
@ -268,8 +304,12 @@ function activate(context) {
// #### main commands ###################################################### // #### main commands ######################################################
function fInstall() { function fInstall(autoreload) {
installItem(htmlFileBack, htmlFile, cleanCssInstall); installItem(htmlFileBack, htmlFile, cleanCssInstall);
if (autoreload)
reloadWindow();
else
enabledRestart();
} }
function fUninstall(willReinstall) { function fUninstall(willReinstall) {
@ -302,6 +342,28 @@ function activate(context) {
context.subscriptions.push(installVibrancy); context.subscriptions.push(installVibrancy);
context.subscriptions.push(uninstallVibrancy); context.subscriptions.push(uninstallVibrancy);
context.subscriptions.push(updateVibrancy); context.subscriptions.push(updateVibrancy);
if (isFirstload()) {
vscode.window.showInformationMessage(msg.firstload, { title: msg.installIde })
.then(function (msg) {
eventEmitter.once('endUninstall', () => fInstall(true));
fUninstall(true);
});
lockFirstload();
}
var lastConfig = vscode.workspace.getConfiguration("vscode_vibrancy");
vscode.workspace.onDidChangeConfiguration(() => {
if (!deepEqual(lastConfig, vscode.workspace.getConfiguration("vscode_vibrancy"))) {
vscode.window.showInformationMessage(msg.configupdate, { title: msg.reloadIde })
.then(function () {
eventEmitter.once('endUninstall', () => fInstall(true));
fUninstall(true);
});
lockFirstload();
}
});
} }
exports.activate = activate; exports.activate = activate;

View File

@ -1,8 +1,12 @@
exports.messages = { exports.messages = {
admin: 'Run VS Code with admin privileges so the changes can be applied.', admin: 'Run VS Code with admin privileges so the changes can be applied.',
firstload: 'Welcome to use Vibrancy. Please read the README first. Click the button below to install.',
configupdate: 'Config is changed, do you want to reload.',
enabled: 'Vibrancy enabled. Restart to take effect. If Code complains about it is corrupted, CLICK DON\'T SHOW AGAIN. See README for more detail.', enabled: 'Vibrancy enabled. Restart to take effect. If Code complains about it is corrupted, CLICK DON\'T SHOW AGAIN. See README for more detail.',
disabled: 'Vibrancy disabled and reverted to default. Restart to take effect.', disabled: 'Vibrancy disabled and reverted to default. Restart to take effect.',
already_disabled: 'Vibrancy already disabled.', already_disabled: 'Vibrancy already disabled.',
smthingwrong: 'Something went wrong: ', smthingwrong: 'Something went wrong: ',
restartIde: 'Restart Visual Studio Code' restartIde: 'Restart Visual Studio Code',
installIde: 'Install Vibrancy',
reloadIde: 'Reload'
}; };

Binary file not shown.

Binary file not shown.