This commit is contained in:
eyhn 2021-01-27 02:39:40 +08:00
parent da3dd1eb9d
commit 274fa0f998
10 changed files with 289 additions and 53 deletions

View File

@ -1,6 +1,10 @@
# Visual Studio Code Extension - Vibrancy
> Mouse dragging lag in versions above 1809 of Windows 10, please do not install. See here: https://github.com/EYHN/vscode-vibrancy/issues/5#issuecomment-546591977
> Windows 10 users may have a slight mouse lag when moving the window, [please read here for details](https://github.com/EYHN/vscode-vibrancy/discussions/80).
> Starting from v1.0.10, this extension no longer supports Windows 7.
> For questions about installation and uninstallation, please read [FAQs](#FAQs).
Enable Acrylic/Glass effect for your VS Code.
@ -18,8 +22,6 @@ Links: [Github](https://github.com/eyhn/vscode-vibrancy) | [Visual Studio Code M
## Supported Operating Systems
Windows 7 ✔
Windows 10 ✔
MacOS ✔
@ -55,7 +57,6 @@ To fix the "[Unsupported]" warning on VS Code's title bar, please refer to this
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.
* appearance-based, light, dark, titlebar, selection, menu, popover, sidebar, medium-light, ultra-dark: (MacOS only)
@ -98,6 +99,10 @@ Check your settings. You should change the renderer type of the terminal to dom.
`"terminal.integrated.rendererType": "dom"`
### Prompt "Run Visual Studio Code with administrator privileges" ?
It usually appears on windows when you are using the VSCode System Installer. You should close VSCode completely, then run VSCode as administrator and retry what you did before (Enable/Reload/Disable Vibrancy).
## Thanks ⭐
[be5invis/vscode-custom-css](https://github.com/be5invis/vscode-custom-css) : The basis of this extension program

View File

@ -1,3 +1,9 @@
# 1.0.10
* New runtime implementation.
* fix: win10 dragging lay
* Remove win7 support
# 1.0.9
* fix: Disable auto restart

View File

@ -41,6 +41,16 @@ async function changeTerminalRendererType() {
}
}
async function promptRestart() {
// This is a hacky way to display the restart prompt
let v = vscode.workspace.getConfiguration().inspect("window.titleBarStyle");
if (v !== undefined) {
let value = vscode.workspace.getConfiguration().get("window.titleBarStyle");
await vscode.workspace.getConfiguration().update("window.titleBarStyle", value === "native" ? "custom" : "native", vscode.ConfigurationTarget.Global);
vscode.workspace.getConfiguration().update("window.titleBarStyle", v.globalValue, vscode.ConfigurationTarget.Global);
}
}
async function checkColorTheme() {
const currentTheme = getCurrentTheme(vscode.workspace.getConfiguration("vscode_vibrancy"));
const themeConfig = require(path.join(__dirname, themeConfigPaths[currentTheme]));
@ -104,12 +114,10 @@ function activate(context) {
var HTMLFile = appDir + '/vs/code/electron-browser/workbench/workbench.html';
var JSFile = appDir + '/main.js';
var runtimeVersion = 'v1';
var runtimeVersion = 'v2';
var runtimeDir = appDir + '/vscode-vibrancy-runtime-' + runtimeVersion;
async function installRuntime() {
if (!isWin) return;
if (fs.existsSync(runtimeDir)) return;
await fs.mkdir(runtimeDir);
@ -163,11 +171,17 @@ function activate(context) {
}
function enabledRestart() {
vscode.window.showInformationMessage(localize('messages.enabled'), { title: localize('messages.restartIde') });
vscode.window.showInformationMessage(localize('messages.enabled'), { title: localize('messages.restartIde') })
.then(function (msg) {
msg && promptRestart();
});
}
function disabledRestart() {
vscode.window.showInformationMessage(localize('messages.disabled'), { title: localize('messages.restartIde') });
vscode.window.showInformationMessage(localize('messages.disabled'), { title: localize('messages.restartIde') })
.then(function (msg) {
msg && promptRestart();
});
}
// #### main commands ######################################################
@ -181,36 +195,41 @@ function activate(context) {
try {
await fs.stat(JSFile);
await changeTerminalRendererType()
} catch (error) {
vscode.window.showInformationMessage(localize('messages.smthingwrong') + error);
throw error;
}
try {
await installRuntime();
await installJS();
await changeTerminalRendererType();
} catch (error) {
vscode.window.showInformationMessage(localize('messages.smthingwrong') + error);
if (error && (error.code === 'EPERM' || error.code === 'EACCES')) {
vscode.window.showInformationMessage(localize('messages.admin') + error);
}
else {
vscode.window.showInformationMessage(localize('messages.smthingwrong') + error);
}
throw error;
}
}
async function Uninstall() {
try {
await fs.stat(JSFile);
// uninstall old version
await fs.stat(HTMLFile);
} catch (error) {
vscode.window.showInformationMessage(localize('messages.smthingwrong') + error);
throw error;
await uninstallHTML();
} finally {
}
try {
// uninstall old version
await uninstallHTML();
await fs.stat(JSFile);
await uninstallJS();
} catch (error) {
vscode.window.showInformationMessage(localize('messages.smthingwrong') + error);
if (error && (error.code === 'EPERM' || error.code === 'EACCES')) {
vscode.window.showInformationMessage(localize('messages.admin') + error);
}
else {
vscode.window.showInformationMessage(localize('messages.smthingwrong') + error);
}
throw error;
}
}

140
nls-schema.json Normal file
View File

@ -0,0 +1,140 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"configuration.type.description": {
"type": "string"
},
"configuration.type.auto.description": {
"type": "string"
},
"configuration.type.acrylic.description": {
"type": "string"
},
"configuration.type.appearance-based.description": {
"type": "string"
},
"configuration.type.light.description": {
"type": "string"
},
"configuration.type.dark.description": {
"type": "string"
},
"configuration.type.titlebar.description": {
"type": "string"
},
"configuration.type.selection.description": {
"type": "string"
},
"configuration.type.menu.description": {
"type": "string"
},
"configuration.type.popover.description": {
"type": "string"
},
"configuration.type.sidebar.description": {
"type": "string"
},
"configuration.type.medium-light.description": {
"type": "string"
},
"configuration.type.ultra-dark.description": {
"type": "string"
},
"configuration.opacity.description": {
"type": "string"
},
"configuration.theme.description": {
"type": "string"
},
"configuration.imports.description": {
"type": "string"
},
"extension.installVibrancy.title": {
"type": "string"
},
"extension.uninstallVibrancy.title": {
"type": "string"
},
"extension.updateVibrancy.title": {
"type": "string"
},
"messages.firstload": {
"type": "string"
},
"messages.configupdate": {
"type": "string"
},
"messages.enabled": {
"type": "string"
},
"messages.disabled": {
"type": "string"
},
"messages.already_disabled": {
"type": "string"
},
"messages.smthingwrong": {
"type": "string"
},
"messages.unsupported": {
"type": "string"
},
"messages.admin": {
"type": "string"
},
"messages.recommendedColorTheme": {
"type": "string"
},
"messages.restartIde": {
"type": "string"
},
"messages.installIde": {
"type": "string"
},
"messages.reloadIde": {
"type": "string"
},
"messages.changeColorThemeIde": {
"type": "string"
},
"messages.noIde": {
"type": "string"
}
},
"required": [
"configuration.type.description",
"configuration.type.auto.description",
"configuration.type.acrylic.description",
"configuration.type.appearance-based.description",
"configuration.type.light.description",
"configuration.type.dark.description",
"configuration.type.titlebar.description",
"configuration.type.selection.description",
"configuration.type.menu.description",
"configuration.type.popover.description",
"configuration.type.sidebar.description",
"configuration.type.medium-light.description",
"configuration.type.ultra-dark.description",
"configuration.opacity.description",
"configuration.theme.description",
"configuration.imports.description",
"extension.installVibrancy.title",
"extension.uninstallVibrancy.title",
"extension.updateVibrancy.title",
"messages.firstload",
"messages.configupdate",
"messages.enabled",
"messages.disabled",
"messages.already_disabled",
"messages.smthingwrong",
"messages.unsupported",
"messages.admin",
"messages.recommendedColorTheme",
"messages.restartIde",
"messages.installIde",
"messages.reloadIde",
"messages.changeColorThemeIde",
"messages.noIde"
]
}

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{
"name": "vscode-vibrancy",
"version": "1.0.10-alpha",
"version": "1.0.10",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

View File

@ -2,7 +2,7 @@
"name": "vscode-vibrancy",
"displayName": "Vibrancy",
"description": "Vibrancy Effect for Visual Studio Code",
"version": "1.0.10-alpha",
"version": "1.0.10",
"publisher": "eyhn",
"author": {
"email": "cneyhn@gmail.com",

View File

@ -1,4 +1,5 @@
{
"$schema": "./nls-schema.json",
"configuration.type.description": "すりガラス効果の適用方法を制御します。",
"configuration.type.auto.description": "自動",
"configuration.type.acrylic.description": "(Windows 10 のみ) Fluent Design のブラー効果を使用します",
@ -19,13 +20,14 @@
"extension.uninstallVibrancy.title": "Vibrancy を無効化",
"extension.updateVibrancy.title": "Vibrancy を再読み込み",
"messages.admin": "変更を適用するには、Visual Studio Code を管理者として実行してください。",
"messages.firstload": "Vibrancy へようこそ。はじめに README をご覧ください。ボタンをクリックして、インストールを開始します。",
"messages.configupdate": "設定が変更されました。反映させるには、再読み込みします。",
"messages.enabled": "Vibrancy が有効化されました。設定は再起動の後に反映されます。もし Visual Studio Code が破損を検出した場合、\"今後表示しない\" をクリックします。詳細については README をご確認ください。",
"messages.disabled": "Vibrancy が無効化されました。再起動することで、元の状態に戻ります。",
"messages.already_disabled": "Vibrancy は既に無効です。",
"messages.smthingwrong": "問題が発生しました: ",
"messages.already_disabled": "Vibrancy は既に無効です。",
"messages.smthingwrong": "問題が発生しました: ",
"messages.unsupported": "サポートされていないオペレーティングシステム。macosとwin10のみがサポートされています。 ",
"messages.admin": "変更の適用に失敗しました管理者権限でVSCodeを実行してください詳細については README をご確認ください: ",
"messages.recommendedColorTheme": "現在の配色テーマは \"%1\" ですが、選択された Vibrancy テーマには \"%2\" を推奨します。",
"messages.restartIde": "Visual Studio Code を再起動",
"messages.installIde": "Vibrancy をインストール",

View File

@ -1,4 +1,5 @@
{
"$schema": "https://json.schemastore.org/coffeelint",
"configuration.type.description": "Native method of Vibrancy Effect",
"configuration.type.auto.description": "Automatically switch with system version",
"configuration.type.acrylic.description": "(Windows 10 only) Fluent design blur",
@ -25,7 +26,8 @@
"messages.disabled": "Vibrancy disabled and reverted to default. Restart to take effect.",
"messages.already_disabled": "Vibrancy already disabled.",
"messages.smthingwrong": "Something went wrong: ",
"messages.unsupported": "Unsupported operating system, only macos and win10 are supported",
"messages.unsupported": "Unsupported operating system, only macos and win10 are supported",
"messages.admin": "Apply changes failed, please run Visual Studio Code with administrator privileges, see README for more detail: ",
"messages.recommendedColorTheme": "Your current color theme is \"%1\" and the Vibrancy theme is designed for \"%2\"!",
"messages.restartIde": "Restart Visual Studio Code",
"messages.installIde": "Install Vibrancy",

View File

@ -1,4 +1,5 @@
{
"$schema": "./nls-schema.json",
"configuration.type.description":"设置毛玻璃效果的类型。",
"configuration.type.auto.description": "自动",
"configuration.type.acrylic.description": "(仅限 Windows 10) Fluent design blur",
@ -21,11 +22,12 @@
"messages.firstload": "欢迎使用 Vibrancy请先阅读 README单击下面的按钮进行安装。",
"messages.configupdate": "配置已更改,是否要重新加载。",
"messages.enabled": "已安装毛玻璃效果,重启后才能生效。如果 VSCode 提示”安装似乎损坏“,请点击“不再提示”。有关详细信息,请参阅自述文件。",
"messages.enabled": "已安装毛玻璃效果,重启后才能生效。如果 Visual Studio Code 提示”安装似乎损坏“,请点击“不再提示”。有关详细信息,请参阅自述文件。",
"messages.disabled": "毛玻璃已卸载并恢复为默认值。重启才能生效。",
"messages.already_disabled": "毛玻璃已经禁用。",
"messages.smthingwrong": "发生了预料之外的错误: ",
"messages.unsupported": "操作系统不支持,仅支持 macos 和 win10。",
"messages.unsupported": "操作系统不支持,仅支持 macos 和 win10。",
"messages.admin": "无法应用更改,请使用管理员权限运行 Visual Studio Code有关详细信息请参阅自述文件: ",
"messages.recommendedColorTheme": "你当前的颜色主题是 \"%1\" ,而你的毛玻璃主题是为 \"%2\" 设计的!",
"messages.restartIde": "重启 Visual Studio Code",
"messages.installIde": "安装毛玻璃效果",

View File

@ -67,11 +67,27 @@ electron.app.on('browser-window-created', (_, window) => {
window.maximize();
}
});
}
if (app.os === 'macos') {
window.setVibrancy(type);
}
}
window.on('enter-full-screen', () => {
const currentURL = window.webContents.getURL();
if (!currentURL.includes('workbench.html')) {
return;
}
removeStyle(window);
});
window.on('leave-full-screen', () => {
const currentURL = window.webContents.getURL();
if (!currentURL.includes('workbench.html')) {
return;
}
injectStyle(window);
});
window.webContents.on('dom-ready', () => {
const currentURL = window.webContents.getURL();
@ -80,14 +96,71 @@ electron.app.on('browser-window-created', (_, window) => {
return;
}
window.setBackgroundColor('#00000000');
window.setBackgroundColor('#00000000');
if (app.os === 'macos') {
window.setVibrancy(type);
window.webContents.executeJavaScript("document.body.innerHTML += " + JSON.stringify(HTML()))
// hack
const width = window.getBounds().width;
window.setBounds({
width: width + 1,
});
window.setBounds({
width,
});
}
injectStyle(window);
injectScript(window);
});
});
function injectScript(window) {
window.webContents.executeJavaScript(`(function(){
const element = document.createElement("div");
element.id = "vscode-vibrancy-script";
element.innerHTML = ${JSON.stringify(scriptHTML())};
document.body.appendChild(element);
})();`);
}
function HTML() {
function injectStyle(window) {
window.webContents.executeJavaScript(`(function(){
const element = document.createElement("div");
element.id = "vscode-vibrancy-style";
element.innerHTML = ${JSON.stringify(styleHTML())};
document.body.appendChild(element);
})();`);
}
function removeStyle(window) {
window.webContents.executeJavaScript("document.getElementById(\"vscode-vibrancy-style\")?.remove();")
}
const customImports = {
js: [],
css: []
}
app.config.imports.forEach(function (x) {
if (typeof x === 'string') {
x = new URL(x, 'file://').href;
if (!x.startsWith('file://')) {
x = 'file://' + x;
}
if (/^.*\.js$/.test(x)) customImports.js.push('<script src="' + x + '"></script>');
if (/^.*\.css$/.test(x)) customImports.css.push('<link rel="stylesheet" href="' + x + '"/>');
}
})
function scriptHTML() {
return customImports.js.join('')
}
function styleHTML() {
if (app.os === 'unknown') return '';
var type = app.config.type;
@ -116,20 +189,7 @@ function HTML() {
${app.themeCSS}
</style>
`,
...app.config.imports.map(function (x) {
if (!x) return '';
if (typeof x === 'string') {
x = new URL(x, 'file://').href;
if (!x.startsWith('file://')) {
x = 'file://' + x;
}
if (/^.*\.js$/.test(x)) return '<script src="' + x + '"></script>';
if (/^.*\.css$/.test(x)) return '<link rel="stylesheet" href="' + x + '"/>';
}
return '';
})
...customImports.css
]
return HTML.join('')