2017-06-06 23:19:12 +02:00
|
|
|
import * as types from "constants/action_types";
|
|
|
|
import lbry from "lbry";
|
2017-08-07 02:55:31 +02:00
|
|
|
import { readdirSync } from "fs";
|
|
|
|
import { extname } from "path";
|
|
|
|
import { remote } from "electron";
|
2017-05-17 23:52:45 +02:00
|
|
|
|
|
|
|
export function doFetchDaemonSettings() {
|
|
|
|
return function(dispatch, getState) {
|
2017-06-06 23:19:12 +02:00
|
|
|
lbry.settings_get().then(settings => {
|
2017-05-17 23:52:45 +02:00
|
|
|
dispatch({
|
|
|
|
type: types.DAEMON_SETTINGS_RECEIVED,
|
|
|
|
data: {
|
2017-06-06 23:19:12 +02:00
|
|
|
settings,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
2017-05-17 23:52:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export function doSetDaemonSetting(key, value) {
|
|
|
|
return function(dispatch, getState) {
|
|
|
|
let settings = {};
|
|
|
|
settings[key] = value;
|
2017-06-06 23:19:12 +02:00
|
|
|
lbry.settings_set(settings).then(settings);
|
|
|
|
lbry.settings_get().then(settings => {
|
2017-05-17 23:52:45 +02:00
|
|
|
dispatch({
|
|
|
|
type: types.DAEMON_SETTINGS_RECEIVED,
|
|
|
|
data: {
|
2017-06-06 23:19:12 +02:00
|
|
|
settings,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
2017-06-06 06:21:55 +02:00
|
|
|
}
|
2017-06-28 09:12:01 +02:00
|
|
|
|
|
|
|
export function doSetClientSetting(key, value) {
|
|
|
|
lbry.setClientSetting(key, value);
|
|
|
|
|
|
|
|
return {
|
|
|
|
type: types.CLIENT_SETTING_CHANGED,
|
|
|
|
data: {
|
|
|
|
key,
|
|
|
|
value,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
2017-08-07 02:55:31 +02:00
|
|
|
|
2017-08-19 23:34:45 +02:00
|
|
|
export function doSetTheme(name) {
|
|
|
|
const link = document.getElementById("theme");
|
|
|
|
|
|
|
|
return function(dispatch, getState) {
|
|
|
|
const { themes } = getState().settings.clientSettings;
|
|
|
|
const theme = themes.find(theme => theme.name === name);
|
|
|
|
|
|
|
|
link.href = theme.path;
|
|
|
|
|
|
|
|
dispatch(doSetClientSetting("theme", theme));
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function doGetThemes() {
|
|
|
|
const path = `${remote.app.getAppPath()}/dist/themes`;
|
2017-08-07 02:55:31 +02:00
|
|
|
|
|
|
|
// Get all .css files
|
2017-08-19 23:34:45 +02:00
|
|
|
const files = readdirSync(path).filter(file => extname(file) === ".css");
|
2017-08-07 02:55:31 +02:00
|
|
|
|
|
|
|
// Get theme name
|
2017-08-19 23:34:45 +02:00
|
|
|
const themes = files.map(file => ({
|
|
|
|
name: file.replace(".css", ""),
|
|
|
|
path: `./themes/${file}`,
|
|
|
|
fullPath: `${path}/${file}`,
|
|
|
|
}));
|
2017-08-07 02:55:31 +02:00
|
|
|
|
2017-08-19 23:34:45 +02:00
|
|
|
return function(dispatch, getState) {
|
|
|
|
dispatch(doSetClientSetting("themes", themes));
|
2017-08-07 02:55:31 +02:00
|
|
|
};
|
|
|
|
}
|