Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unhighlight on disconnect #67

Merged
merged 6 commits into from
Mar 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,11 @@
"type": "string",
"default": "Twitch Highlighter has left the building!",
"description": "The message the bot will say when leaving a chat room"
},
"twitchHighlighter.unhighlightOnDisconnect": {
"type": "boolean",
"default": false,
"description": "Unhighlight all lines when disconnected from the chat service."
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export enum Settings {
'announceBot' = 'announceBot',
'joinMessage' = 'joinMessage',
'leaveMessage' = 'leaveMessage',
'unhighlightOnDisconnect' = 'unhighlightOnDisconnect',
}

export enum Commands {
Expand Down
27 changes: 24 additions & 3 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
HighlighterNode
} from './twitchHighlighterTreeView';
import { TwitchChatClient } from './twitchChatClient';
import { Commands } from './constants';
import { extSuffix, Settings, Commands } from './constants';

let highlightDecorationType: vscode.TextEditorDecorationType;
const twitchHighlighterStatusBarIcon: string = '$(plug)'; // The octicon to use for the status bar icon (https://octicons.github.com/)
Expand All @@ -34,7 +34,9 @@ export function activate(context: vscode.ExtensionContext) {
twitchChatClient.onUnhighlight = unhighlight;
twitchChatClient.onConnected = () => setConnectionStatus(true);
twitchChatClient.onConnecting = () => setConnectionStatus(false, true);
twitchChatClient.onDisconnected = () => setConnectionStatus(false);
twitchChatClient.onDisconnected = () => {
setConnectionStatus(false);
};

twitchHighlighterTreeView = new TwitchHighlighterDataProvider(() => {
return highlighters;
Expand Down Expand Up @@ -207,7 +209,26 @@ export function activate(context: vscode.ExtensionContext) {
twitchChatClient.start(setTwitchTokenHandler);
}

function stopChatHandler() {
async function stopChatHandler() {
const config = vscode.workspace.getConfiguration(extSuffix);
let unhighlightOnDisconnect = config.get<boolean>(Settings.unhighlightOnDisconnect);

if (highlighters.length > 0 && highlighters.some(h => h.highlights.length > 0) && !unhighlightOnDisconnect) {
const result = await vscode.window.showInformationMessage('Do you want to keep or remove the existing highlights when disconnecting from chat?', 'Always Remove', 'Remove', 'Keep');
if (result && result === 'Remove') {
unhighlightOnDisconnect = true;
}
if (result && result === 'Always Remove')
{
unhighlightOnDisconnect = true;
config.update(Settings.unhighlightOnDisconnect, true, true);
}
}

if (unhighlightOnDisconnect) {
unhighlightAllHandler();
}

twitchChatClient.stop();
}

Expand Down