<commit_before>import getWeatherInfo from './libs/get-weather-info';
import fetchRandomPhoto from './libs/fetch-random-photo';
import loadNewData from './libs/load-new-data';
import { notifyCloudAuthenticationSuccessful } from './libs/notifications';
import { onedriveAuth, refreshOnedriveToken } from './libs/onedrive-auth';

const setDefaultExtensionSettings = () => {
  chrome.storage.local.set({
    cloudService: 'dropbox',
    forecast: null,
    nextImage: null,
    history: null,
    pausedImage: null,
    photoFrequency: 'newtab',
  });

  chrome.storage.sync.set({
    collections: '',
    imageSource: 'official',
    temperatureFormat: 'metric',
    coords: {
      latitude: '',
      longitude: '',
    },
  });
};

chrome.runtime.onInstalled.addListener(details => {
  if (details.reason === 'install') {
    setDefaultExtensionSettings();
  }

  fetchRandomPhoto();
});

chrome.runtime.onMessage.addListener((request, sender) => {
  const listeners = {
    'close-tab': () => chrome.tabs.remove(sender.tab.id),

    'set-dropbox-token': () => {
      chrome.storage.local.set({ dropbox: request.token });
      notifyCloudAuthenticationSuccessful('Dropbox');
      chrome.runtime.sendMessage({ command: 'update-cloud-status' });
    },

    'code-flow': () => {
      chrome.storage.local.get('cloudService', result => {
        const { cloudService } = result;
        if (cloudService === 'onedrive') {
          chrome.tabs.remove(sender.tab.id);
          onedriveAuth(request.code);
        }
      });
    },

    'update-weather': () => getWeatherInfo(),

    'set-onedrive-alarm': () => {
      chrome.alarms.create('refresh-onedrive-token', {
        periodInMinutes: request.expires_in / 60,
      });
    },

    'load-data': () => loadNewData(),
  };

  listeners[request.command]();
});

chrome.alarms.onAlarm.addListener(alarm => {
  const alarms = {
    loadphoto: () => fetchRandomPhoto(),
    loadweather: () => getWeatherInfo(),
    'refresh-onedrive-token': () => refreshOnedriveToken(),
  };

  alarms[alarm.name]();
});
<commit_msg>Fix bug that caused weather to be displayed in kelvin<commit_after>import getWeatherInfo from './libs/get-weather-info';
import fetchRandomPhoto from './libs/fetch-random-photo';
import loadNewData from './libs/load-new-data';
import { notifyCloudAuthenticationSuccessful } from './libs/notifications';
import { onedriveAuth, refreshOnedriveToken } from './libs/onedrive-auth';

const setDefaultExtensionSettings = () => {
  chrome.storage.local.set({
    cloudService: 'dropbox',
    forecast: null,
    nextImage: null,
    history: null,
    pausedImage: null,
    photoFrequency: 'newtab',
  });

  chrome.storage.sync.set({
    collections: '',
    imageSource: 'official',
    temperatureFormat: 'metric',
    coords: {
      latitude: '',
      longitude: '',
    },
  });
};

chrome.runtime.onInstalled.addListener(details => {
  if (details.reason === 'install') {
    setDefaultExtensionSettings();
  }

  if (details.reason === 'update') {
    chrome.storage.sync.get(r => {
      const { photoFrequency, tempUnit } = r;
      const unit = tempUnit === 'fahrenheit' ? 'imperial' : 'metric';
      chrome.storage.local.get(d => {
        const { cloudService } = d;

        chrome.storage.local.set({
          photoFrequency: photoFrequency || 'newtab',
          pausedImage: null,
          cloudService: cloudService || 'dropbox',
        });

        chrome.storage.sync.set({
          imageSource: 'custom',
          temperatureFormat: unit,
        });
      });
    });
  }

  fetchRandomPhoto();
});

chrome.runtime.onMessage.addListener((request, sender) => {
  const listeners = {
    'close-tab': () => chrome.tabs.remove(sender.tab.id),

    'set-dropbox-token': () => {
      chrome.storage.local.set({ dropbox: request.token });
      notifyCloudAuthenticationSuccessful('Dropbox');
      chrome.runtime.sendMessage({ command: 'update-cloud-status' });
    },

    'code-flow': () => {
      chrome.storage.local.get('cloudService', result => {
        const { cloudService } = result;
        if (cloudService === 'onedrive') {
          chrome.tabs.remove(sender.tab.id);
          onedriveAuth(request.code);
        }
      });
    },

    'update-weather': () => getWeatherInfo(),

    'set-onedrive-alarm': () => {
      chrome.alarms.create('refresh-onedrive-token', {
        periodInMinutes: request.expires_in / 60,
      });
    },

    'load-data': () => loadNewData(),
  };

  listeners[request.command]();
});

chrome.alarms.onAlarm.addListener(alarm => {
  const alarms = {
    loadphoto: () => fetchRandomPhoto(),
    loadweather: () => getWeatherInfo(),
    'refresh-onedrive-token': () => refreshOnedriveToken(),
  };

  alarms[alarm.name]();
});

{'fraction_non_alphanumeric': 0.16876574307304787, 'fraction_numerical': 0.0008396305625524769, 'mean_word_length': 3.048428207306712, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 33, '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': '471512', 'n_tokens_mistral': 1504, 'n_tokens_neox': 1440, 'n_words': 233}