-
Notifications
You must be signed in to change notification settings - Fork 0
/
extension.js
128 lines (115 loc) · 4.57 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
const vscode = require('vscode');
const path = require('path');
const sound = require('sound-play');
const statusBarsItems = [];
let extensionContext;
function getSoundName(){
const soundName = vscode.workspace.getConfiguration('inspiredev').get('soundName');
const soundNames = {
'Never Back Down Never What?': 'never_back_down',
'Giga Chad Music': 'giga_chad_music',
'Sigma Music': 'sigma_music',
'Oh oh oh Gotaga': 'gotaga',
'Dark Souls 3 - Boss Theme': 'boss_theme',
'Never Give Up Your Waaaaaay': 'never_give_up_japanese',
'Just Do It (Shia LaBeouf)': 'just_do_it',
};
if (soundName == 'Random') return soundNames[Object.keys(soundNames)[Math.floor(Math.random() * Object.keys(soundNames).length)]] + '.mp3';
return soundNames[soundName] + '.mp3';
}
function playSound(){
const playSound = vscode.workspace.getConfiguration('inspiredev').get('playSound');
const soundVolume = (vscode.workspace.getConfiguration('inspiredev').get('soundVolume') || 100) / 100;
if(playSound){
const soundPath = vscode.Uri.file(path.join(extensionContext.extensionPath, 'media', getSoundName())).fsPath;
sound.play(soundPath, soundVolume).catch(err => console.error('Error playing sound:', err));
}
}
function updateQuote() {
const userLang = vscode.workspace.getConfiguration('inspiredev').get('language');
let quotes = require(`./quotes/${userLang}.json`);
const configQuotes = vscode.workspace.getConfiguration('inspiredev').get('customQuotes') || [];
if(configQuotes.length > 0) {
quotes = quotes.concat(configQuotes);
}
const quote = quotes[Math.floor(Math.random() * quotes.length)];
displayQuote(quote);
playSound();
}
function format(quote){
const quoteFormat = vscode.workspace.getConfiguration('inspiredev').get('quoteFormat');
return quoteFormat.replace(/%quote%/g, quote);
}
function actionStatusBarItem(type) {
if(type === 'hide') {
statusBarsItems['left'].hide();
statusBarsItems['right'].hide();
}else if(type === 'dispose') {
statusBarsItems['left'].dispose();
statusBarsItems['right'].dispose();
}else if(type === 'set'){
statusBarsItems['left'].tooltip='Click to hide';
statusBarsItems['left'].command='inspiredev.toggleStatusBarItem';
statusBarsItems['right'].tooltip='Click to hide';
statusBarsItems['right'].command='inspiredev.toggleStatusBarItem';
}
}
function displayQuote(quote) {
const quotePosition = vscode.workspace.getConfiguration('inspiredev').get('displayPosition');
actionStatusBarItem('hide');
if(quotePosition === 'statusBar (left)') {
statusBarsItems['left'].text = format(quote);
statusBarsItems['left'].show();
}else if(quotePosition === 'statusBar (right)') {
statusBarsItems['right'].text = format(quote);
statusBarsItems['right'].show();
}else if(quotePosition === 'notification') {
vscode.window.showInformationMessage(format(quote), {modal: false }, 'Dismiss').then((value) => {
if(value === 'Dismiss') {
return;
}
});
}
}
/**
* @param {vscode.ExtensionContext} context
*/
function activate(context) {
extensionContext = context;
////////////////////////////
// CONFIGURATION
////////////////////////////
const showOnStartup = vscode.workspace.getConfiguration('inspiredev').get('showOnStartup');
const notificationInterval = vscode.workspace.getConfiguration('inspiredev').get('notificationInterval');
////////////////////////////
// STATUS BAR ITEMS
////////////////////////////
statusBarsItems['left'] = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left);
statusBarsItems['right'] = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right);
actionStatusBarItem('set');
context.subscriptions.push(statusBarsItems['left'], statusBarsItems['right']);
////////////////////////////
// UPDATE QUOTE
////////////////////////////
if(showOnStartup){setTimeout(()=>{updateQuote()},1000)};
setInterval(() =>{updateQuote()}, notificationInterval * 1000 * 60);
const updateQuoteCommand = vscode.commands.registerCommand('inspiredev.randomQuote',function(){updateQuote()});
// TOGGLE STATUS BAR ITEM COMMAND
const toggleStatusBarItemCommand = vscode.commands.registerCommand('inspiredev.toggleStatusBarItem', function () {
const quotePosition = vscode.workspace.getConfiguration('inspiredev').get('displayPosition');
if(quotePosition === 'statusBar (left)') {
statusBarsItems['left'].hide();
}else if(quotePosition === 'statusBar (right)') {
statusBarsItems['right'].hide();
}
});
// PUSH INTO CONTEXT SUBSCRIPTIONS
context.subscriptions.push(toggleStatusBarItemCommand, updateQuoteCommand);
}
function deactivate() {
actionStatusBarItem('dispose');
}
module.exports = {
activate,
deactivate
}