-
Notifications
You must be signed in to change notification settings - Fork 23
/
extension.js
118 lines (95 loc) · 3.89 KB
/
extension.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
const { workspace, window, commands } = require('vscode');
const shell = require('node-powershell');
function activate(context) {
if (process.platform == 'win32') {
const path = context.asAbsolutePath('./SetTransparency.cs');
const ps = new shell({
executionPolicy: 'RemoteSigned',
noProfile: true,
});
context.subscriptions.push(ps);
ps.addCommand('[Console]::OutputEncoding = [Text.Encoding]::UTF8');
ps.addCommand(`Add-Type -Path '${path}'`);
function setAlpha(alpha) {
if (alpha < 1) {
alpha = 1;
} else if (alpha > 255) {
alpha = 255;
}
ps.addCommand(`[GlassIt.SetTransParency]::SetTransParency(${process.pid}, ${alpha})`);
ps.invoke().then(res => {
console.log(res);
console.log(`GlassIt: set alpha ${alpha}`);
config().update('alpha', alpha, true);
}).catch(err => {
console.error(err);
window.showErrorMessage(`GlassIt Error: ${err}`);
});
}
} else if (process.platform == 'linux'){
const cp = require('child_process');
// Checking the weather xprop has installed
try {
cp.spawnSync('which xprop').toString();
} catch (error){
console.error(`GlassIt Error: Please install xprop package to use GlassIt.`);
return;
}
// Retrieving the process ids of VS code
const processIds = cp.execSync('pgrep \'code\'').toString().split('\n');
processIds.pop();
// Retrieving all window ids
const allWindowIdsOutput = cp.execSync(
`xprop -root | grep '_NET_CLIENT_LIST(WINDOW)'`
).toString();
const allWindowIds = allWindowIdsOutput.match(/0x[\da-f]+/ig);
const codeWindowIds = [];
for(const windowId of allWindowIds){
// Checking the weather the window has a associated process
const hasProcessId = cp.execSync(`xprop -id ${windowId} _NET_WM_PID`).toString();
if(!(hasProcessId.search('not found')+1)){
// Extract process id from the result
const winProcessId = hasProcessId.replace(/([a-zA-Z_\(\)\s\=])/g,'');
if(processIds.includes(winProcessId)){
codeWindowIds.push(windowId);
}
}
}
function setAlpha(alpha){
if (alpha < 1) {
alpha = 1;
} else if (alpha > 255) {
alpha = 255;
}
for(const codeWindowId of codeWindowIds){
cp.exec(`xprop -id ${codeWindowId} -f _NET_WM_WINDOW_OPACITY 32c -set _NET_WM_WINDOW_OPACITY $(printf 0x%x $((0xffffffff * ${alpha} / 255)))`, function(error,stdout, stderr){
if (error) {
console.error(`GlassIt error: ${error}`);
return;
}
console.log(stdout.toString());
console.log(`GlassIt: set alpha ${alpha}`);
config().update('alpha', alpha, true);
});
}
}
} else {
return;
}
console.log('Congratulations, your extension "GlassIt VSC" is now active!');
const config = () => workspace.getConfiguration('glassit');
context.subscriptions.push(commands.registerCommand('glassit.increase', () => {
const alpha = config().get('alpha') - config().get('step');
setAlpha(alpha);
}));
context.subscriptions.push(commands.registerCommand('glassit.decrease', () => {
const alpha = config().get('alpha') + config().get('step');
setAlpha(alpha);
}));
const alpha = config().get('alpha');
setAlpha(alpha);
}
exports.activate = activate;
function deactivate() {
}
exports.deactivate = deactivate;