<commit_before>﻿define(function (require) {
    'use strict';

    var ChromeCommand = require('background/enum/chromeCommand');
    var RepeatButtonState = require('common/enum/repeatButtonState');

    var RepeatButton = Backbone.Model.extend({
        localStorage: new Backbone.LocalStorage('RepeatButton'),
        
        defaults: {
            //  Need to set the ID for Backbone.LocalStorage
            id: 'RepeatButton',
            state: RepeatButtonState.Off
        },
        
        initialize: function () {
            //  Load from Backbone.LocalStorage
            this.fetch();
            
            chrome.commands.onCommand.addListener(this._onChromeCommandsCommand.bind(this));
        },
        
        toggleRepeatState: function () {
            var nextState = null;

            switch (this.get('state')) {
                case RepeatButtonState.Off:
                    nextState = RepeatButtonState.RepeatAll;
                    break;
                case RepeatButtonState.RepeatAll:
                    nextState = RepeatButtonState.RepeatSong;
                    break;
                case RepeatButtonState.RepeatSong:
                    nextState = RepeatButtonState.Off;
                    break;
                default:
                    console.error("Unhandled repeatButtonState:", this.state);
                    break;
            }

            this.save({
                state: nextState
            });
        },
        
        getStateMessage: function () {
            var message = '';
            switch (this.get('state')) {
                case RepeatButtonState.Off:
                    message = chrome.i18n.getMessage('repeatOff');
                    break;
                case RepeatButtonState.RepeatSong:
                    message = chrome.i18n.getMessage('repeatSong');
                    break;
                case RepeatButtonState.RepeatAll:
                    message = chrome.i18n.getMessage('repeatAll');
            }
            
            return message;
        },

        _onChromeCommandsCommand: function (command) {
            if (command === ChromeCommand.ToggleRepeat) {
                this.toggleRepeatState();

                Streamus.channels.backgroundNotification.commands.trigger('show:notification', {
                    message: this.getStateMessage()
                });
            }
        }
    });

    return RepeatButton;
});<commit_msg>Patching update issue w/ changing enum type<commit_after>﻿define(function (require) {
    'use strict';

    var ChromeCommand = require('background/enum/chromeCommand');
    var RepeatButtonState = require('common/enum/repeatButtonState');

    var RepeatButton = Backbone.Model.extend({
        localStorage: new Backbone.LocalStorage('RepeatButton'),
        
        defaults: {
            //  Need to set the ID for Backbone.LocalStorage
            id: 'RepeatButton',
            state: RepeatButtonState.Off
        },
        
        initialize: function () {
            //  Load from Backbone.LocalStorage
            this.fetch();
			
			//  Since the RepeatButtonState enum changed from a number to a string -- people's localStorage data could be out-of-date.
			//  Patch this issue for a few versions (written in v0.169):
			switch(this.get('state')){
				case 0:
				case "0":
					this.set('state', RepeatButtonState.Off);
					break;
				case 1:
				case "1":
					this.set('state', RepeatButtonState.RepeatSong);
					break;
				case 2:
				case "2":
					this.set('state', RepeatButtonState.RepeatAll);
					break;
			}
            
            chrome.commands.onCommand.addListener(this._onChromeCommandsCommand.bind(this));
        },
        
        toggleRepeatState: function () {
            var nextState = null;

            switch (this.get('state')) {
                case RepeatButtonState.Off:
                    nextState = RepeatButtonState.RepeatAll;
                    break;
                case RepeatButtonState.RepeatAll:
                    nextState = RepeatButtonState.RepeatSong;
                    break;
                case RepeatButtonState.RepeatSong:
                    nextState = RepeatButtonState.Off;
                    break;
                default:
                    console.error("Unhandled repeatButtonState:", this.state);
                    break;
            }

            this.save({
                state: nextState
            });
        },
        
        getStateMessage: function () {
            var message = '';
            switch (this.get('state')) {
                case RepeatButtonState.Off:
                    message = chrome.i18n.getMessage('repeatOff');
                    break;
                case RepeatButtonState.RepeatSong:
                    message = chrome.i18n.getMessage('repeatSong');
                    break;
                case RepeatButtonState.RepeatAll:
                    message = chrome.i18n.getMessage('repeatAll');
            }
            
            return message;
        },

        _onChromeCommandsCommand: function (command) {
            if (command === ChromeCommand.ToggleRepeat) {
                this.toggleRepeatState();

                Streamus.channels.backgroundNotification.commands.trigger('show:notification', {
                    message: this.getStateMessage()
                });
            }
        }
    });

    return RepeatButton;
});
{'fraction_non_alphanumeric': 0.09254168957302547, 'fraction_numerical': 0.004031519149715961, 'mean_word_length': 1.4741613780598368, 'pattern_counts': {'":': 3, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3010450', 'n_tokens_mistral': 1440, 'n_tokens_neox': 1272, 'n_words': 253}