-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathextension.js
145 lines (119 loc) · 5.19 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
const { workspace, window, commands } = require('vscode');
const shell = require('node-powershell');
function activate(context) {
const config = () => workspace.getConfiguration('glassit');
console.log('ctx', process.platform);
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');
const codeWindowIds = [];
if (config().get('force_sway') === false) {
// 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;
}
// Retrieve the process name for the current VS Code instance (Solution for using forks of VS Code)
const process_name = process.execPath.substring(process.execPath.lastIndexOf('/') + 1);
// Retrieving the process ids of VS code
const processIds = cp.execSync(`pgrep ${process_name}`).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);
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;
}
if (config().get('force_sway') === true){
console.log(`In force_sway mode...`);
cp.exec(`swaymsg opacity ${(alpha / 255).toFixed(2)}`, 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 {
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!');
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);
}));
context.subscriptions.push(commands.registerCommand('glassit.maximize', () => {
setAlpha(1);
}));
context.subscriptions.push(commands.registerCommand('glassit.minimize', () => {
setAlpha(255);
}));
const alpha = config().get('alpha');
setAlpha(alpha);
}
exports.activate = activate;
function deactivate() {
}
exports.deactivate = deactivate;