Skip to content

Commit

Permalink
v1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
soroushchehresa committed Nov 27, 2020
1 parent aa0d26a commit 7c4b8d7
Show file tree
Hide file tree
Showing 24 changed files with 4,071 additions and 25,421 deletions.
8 changes: 3 additions & 5 deletions .env
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
UNSPLASH_ACCESS_KEY=your_access_key
ELECTRON_DISABLE_SECURITY_WARNINGS=true;
CSC_LINK=""
CSC_KEY_PASSWORD=""
GH_TOKEN=""
UNSPLASH_ACCESS_KEY=
GH_TOKEN=
CSC_IDENTITY_AUTO_DISCOVERY=false
62 changes: 33 additions & 29 deletions app/containers/App/index.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
// @flow

import { debug } from 'electron-log';
import React, { Fragment, useEffect } from 'react';
import { ThemeProvider } from 'styled-components';
import { Route } from 'react-router';
import { TransitionGroup, CSSTransition } from 'react-transition-group';
import moment from 'moment';
import { connect } from 'react-redux';
import storage from 'electron-json-storage';
import { withRouter } from 'react-router';
import Navbar from 'app/components/Navbar';
import { getPhoto } from 'app/containers/Home/redux';
import GlobalStyle from 'app/styles/globalStyles';

type Props = {
children : React.Node,
updateWallpaperSchedule : string,
updateWallpaperDate : string,
getPhotoAction : (data : { data : boolean }) => void,
activeCategory : string,
activeTheme : string,
Expand All @@ -26,32 +24,40 @@ const App = ({
children,
activeTheme,
location,
updateWallpaperSchedule,
updateWallpaperDate,
getPhotoAction,
activeCategory,
} : Props) => {
useEffect(() => {
const checkUpdateTime = () => {
const now = moment();
const last = moment(updateWallpaperDate);
const diffTime = now.diff(last, 'hours');
switch (updateWallpaperSchedule) {
case 'Daily':
if (diffTime >= 24) {
getPhotoAction({ setAutomaticWallpaper: true, activeCategory });
}
break;
case 'Weekly':
if (diffTime >= 168) {
getPhotoAction({ setAutomaticWallpaper: true, activeCategory });
}
break;
default:
break;
const checkUpdateTime = async () => {
storage.getMany(['autoUpdateWallpaperSchedule', 'autoUpdateWallpaperLastUpdate'], (error, data) => {
if (error) {
console.log(error);
} else if (Object.keys(data.autoUpdateWallpaperLastUpdate).length && Object.keys(data.autoUpdateWallpaperSchedule).length) {
const now = moment();
const last = moment(data.autoUpdateWallpaperLastUpdate, 'MM/DD/YYYY HH:mm:ss');
const diffTime = now.diff(last, 'hours');
switch (data.autoUpdateWallpaperSchedule) {
case 'Hourly':
if (diffTime >= 1) {
getPhotoAction({ setAutomaticWallpaper: true, activeCategory });
}
break;
case 'Daily':
if (diffTime >= 24) {
getPhotoAction({ setAutomaticWallpaper: true, activeCategory });
}
break;
case 'Weekly':
if (diffTime >= 168) {
getPhotoAction({ setAutomaticWallpaper: true, activeCategory });
}
break;
default:
break;
}
}
};
checkUpdateTime();
});
};
useEffect(() => {
setInterval(checkUpdateTime, 10000);
}, []);
return (
Expand Down Expand Up @@ -79,14 +85,12 @@ const App = ({
);
};

export default connect(
export default withRouter(connect(
state => ({
updateWallpaperSchedule: state.getIn(['Settings', 'updateWallpaperSchedule']),
updateWallpaperDate: state.getIn(['Settings', 'updateWallpaperDate']),
activeCategory: state.getIn(['Categories', 'activeCategory']),
activeTheme: state.getIn(['Settings', 'activeTheme']),
}),
{
getPhotoAction: getPhoto,
},
)(withRouter(App));
)(App));
10 changes: 3 additions & 7 deletions app/containers/History/style.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,12 @@ export default styled.div`
height: 100%;
text-align: center;
padding: 0 8px;
> .empty-list {
color: #999;
}
}
.empty-history {
color: #999;
position: absolute;
left: 0;
right: 0;
top: -30px;
bottom: 0;
margin: auto;
display: table;
text-align: center;
width: 100%;
}
Expand Down
4 changes: 1 addition & 3 deletions app/containers/Home/saga.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import util from 'util';
import path from 'path';
import moment from 'moment';
import API from 'app/utils/xhrWrapper';
import { setUpdateWallpaperTime } from 'app/containers/Settings/redux';
import {
GET_PHOTO,
GET_PHOTO_SUCCESS,
Expand Down Expand Up @@ -84,8 +83,7 @@ function* setWallpaper() {
}
yield wallpaper.set(picturePath, { scale: 'auto' });
yield put({ type: SET_WALLPAPER_SUCCESS });
yield put(setUpdateWallpaperTime(moment()
.format('MM/DD/YYYY HH:mm:ss')));
storage.set('autoUpdateWallpaperLastUpdate', moment().format('MM/DD/YYYY HH:mm:ss'));
if (!hasPicture) {
storage.set('pictures', {
list: [
Expand Down
64 changes: 28 additions & 36 deletions app/containers/Settings/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,35 @@ import React, { Fragment, memo, useState, useEffect } from 'react';
import type { SyntheticEvent } from 'react';
import { remote } from 'electron';
import { connect } from 'react-redux';
import type { Map as MapType } from 'immutable';
import storage from 'electron-json-storage';
import moment from 'moment';
import AutoLaunch from 'auto-launch';
import appPackage from '../../../package';
import StyledSettings from './style';
import {
setUpdateWallpaperSchedule,
setUpdateWallpaperTime,
setActiveTheme,
setAutomaticChangeActiveTheme,
} from './redux';
import { setActiveTheme, setAutomaticChangeActiveTheme } from './redux';

type Props = {
setUpdateWallpaperScheduleAction : (data : string) => void,
setUpdateWallpaperTimeAction : (data : string) => void,
setActiveThemeAction : (data : string) => void,
setAutomaticChangeActiveThemeAction : (data : boolean) => void,
updateWallpaperSchedule : MapType,
activeTheme : string,
isChangeAutomaticActiveTheme : boolean,
};

const updateMethods = ['Hourly', 'Daily', 'Weekly', 'Manually'];

const Settings = memo(({
updateWallpaperSchedule,
activeTheme,
isChangeAutomaticActiveTheme,
setActiveThemeAction,
setAutomaticChangeActiveThemeAction,
setUpdateWallpaperScheduleAction,
setUpdateWallpaperTimeAction,
} : Props) => {
const [autoUpdateWallpaperSchedule, setAutoUpdateWallpaperSchedule] = useState(null);
const [isRunAtStartup, setIsRunAtStartup] = useState(false);
const updateMethods = ['Daily', 'Weekly', 'Manually'];

useEffect(() => {
storage.get('isRunAtStartup', (error, status) => {
setIsRunAtStartup(status);
storage.getMany(['isRunAtStartup', 'autoUpdateWallpaperSchedule'], (error, data) => {
setIsRunAtStartup(data.isRunAtStartup);
setAutoUpdateWallpaperSchedule(data.autoUpdateWallpaperSchedule || 'Manually');
});
}, []);

Expand All @@ -64,9 +56,8 @@ const Settings = memo(({
};

const handleChangeUpdateWallpaperScadule = (e : SyntheticEvent<HTMLButtonElement>) => {
setUpdateWallpaperScheduleAction(e.target.value);
setUpdateWallpaperTimeAction(moment()
.format('MM/DD/YYYY HH:mm:ss'));
storage.set('autoUpdateWallpaperSchedule', e.target.value);
storage.set('autoUpdateWallpaperLastUpdate', moment().format('MM/DD/YYYY HH:mm:ss'));
};

const handleChangeTheme = (e : SyntheticEvent<HTMLInputElement>) => {
Expand Down Expand Up @@ -98,19 +89,23 @@ const Settings = memo(({
htmlFor="update-method"
>
Update
<select
id="update-method"
onChange={handleChangeUpdateWallpaperScadule}
defaultValue={updateWallpaperSchedule}
>
{
updateMethods.map((updateMethod : string) => (
<option key={updateMethod} value={updateMethod}>
{updateMethod}
</option>
))
}
</select>
{
!!autoUpdateWallpaperSchedule && (
<select
id="update-method"
onChange={handleChangeUpdateWallpaperScadule}
defaultValue={autoUpdateWallpaperSchedule}
>
{
updateMethods.map((updateMethod : string) => (
<option key={updateMethod} value={updateMethod}>
{updateMethod}
</option>
))
}
</select>
)
}
</label>
<div className="choose-theme">
<p>
Expand Down Expand Up @@ -162,21 +157,18 @@ const Settings = memo(({
Quit Unsplash Wallpapers
</button>
<a className="author" href="https://github.com/soroushchehresa/unsplash-wallpapers">
Made with love by Soroush Chehresa on GitHub <br /> v{appPackage.version}
Made with <i className="fa fa-heart" /> on GitHub (v{appPackage.version})
</a>
</StyledSettings>
);
});

export default connect(
state => ({
updateWallpaperSchedule: state.getIn(['Settings', 'updateWallpaperSchedule']),
activeTheme: state.getIn(['Settings', 'activeTheme']),
isChangeAutomaticActiveTheme: state.getIn(['Settings', 'isChangeAutomaticActiveTheme']),
}),
{
setUpdateWallpaperScheduleAction: setUpdateWallpaperSchedule,
setUpdateWallpaperTimeAction: setUpdateWallpaperTime,
setActiveThemeAction: setActiveTheme,
setAutomaticChangeActiveThemeAction: setAutomaticChangeActiveTheme,
},
Expand Down
22 changes: 3 additions & 19 deletions app/containers/Settings/redux.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,23 @@
import { fromJS } from 'immutable';
import type { fromJS as fromJSType } from 'immutable';

export const SET_ACTIVE_THEME = 'unsplash-wallpapers/Settings/SET_ACTIVE_THEME';
export const SET_AUTOMATIC_CHANGE_ACTIVE_THEME = 'unsplash-wallpapers/Settings/SET_AUTOMATIC_CHANGE_ACTIVE_THEME';

type InitialState = {
updateWallpaperDate : string,
updateWallpaperSchedule : string,
activeTheme : string,
isChangeAutomaticActiveTheme : boolean,
};

export const SET_UPDATE_WALLPAPER_SCHEDULE = 'unsplash-wallpapers/Settings/SET_UPDATE_WALLPAPER_SCHEDULE';
export const SET_UPDATE_WALLPAPER_TIME = 'unsplash-wallpapers/Settings/SET_UPDATE_WALLPAPER_TIME';
export const SET_ACTIVE_THEME = 'unsplash-wallpapers/Settings/SET_ACTIVE_THEME';
export const SET_AUTOMATIC_CHANGE_ACTIVE_THEME = 'unsplash-wallpapers/Settings/SET_AUTOMATIC_CHANGE_ACTIVE_THEME';

const initialState : fromJSType<InitialState> = fromJS({
updateWallpaperDate: '',
updateWallpaperSchedule: 'Manually',
activeTheme: 'Light',
isChangeAutomaticActiveTheme: process.platform === 'darwin',
});

export default (state = initialState, action = {}) => {
switch (action.type) {
case SET_UPDATE_WALLPAPER_SCHEDULE:
return state.set('updateWallpaperSchedule', action.data);
case SET_UPDATE_WALLPAPER_TIME:
return state.set('updateWallpaperDate', action.data);
case SET_ACTIVE_THEME:
return state.set('activeTheme', action.data);
case SET_AUTOMATIC_CHANGE_ACTIVE_THEME:
Expand All @@ -37,14 +29,6 @@ export default (state = initialState, action = {}) => {
}
};

export const setUpdateWallpaperSchedule = (data : string) => (
dispatch => dispatch({ type: SET_UPDATE_WALLPAPER_SCHEDULE, data })
);

export const setUpdateWallpaperTime = (data : string) => (
dispatch => dispatch({ type: SET_UPDATE_WALLPAPER_TIME, data })
);

export const setActiveTheme = (data : string) => (
dispatch => dispatch({ type: SET_ACTIVE_THEME, data })
);
Expand Down
9 changes: 6 additions & 3 deletions app/containers/Settings/style.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const authorTextColor = theme('mode', {
});

const authorHoverTextColor = theme('mode', {
Light: '#555',
Light: '#444',
Dark: '#ccc',
});

Expand Down Expand Up @@ -108,15 +108,18 @@ export default styled.div`
width: 100%;
text-align: center;
margin: auto;
font-size: 11px;
font-size: 12px;
color: ${authorTextColor};
cursor: default;
text-decoration: none;
transition: all linear .1s;
> i {
margin: 0 1.5px;
&.fa-heart {
color: #ff2d5d;
}
&.fa-github {
font-size: 12px;
color: #242a2e;
}
}
&:hover {
Expand Down
5 changes: 5 additions & 0 deletions app/main.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ app.on('ready', () => {

window.webContents.once('did-frame-finish-load', function() {
autoUpdater.checkForUpdatesAndNotify();
if (process.env.NODE_ENV === 'development') {
window.webContents.openDevTools();
}
});

window.webContents.on('will-navigate', (event, url) => {
Expand Down Expand Up @@ -134,3 +137,5 @@ storage.has('isRunAtStartup', (error, hasKey) => {
minecraftAutoLauncher.enable();
}
});

app.commandLine.appendSwitch('ignore-certificate-errors');
2 changes: 1 addition & 1 deletion app/utils/setTheme.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { remote } from 'electron';
import { remote, systemPreferences } from 'electron';
import { setActiveTheme } from 'app/containers/Settings/redux';

export default (store) => {
Expand Down
7 changes: 5 additions & 2 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@ module.exports = (api) => {
return {
presets: [
[
require('@babel/preset-env'),
'@babel/preset-env',
{
targets: { electron: require('electron/package.json').version },
useBuiltIns: 'usage',
corejs: 2,
targets: {
esmodules: true,
electron: require('electron/package.json').version
},
},
],
require('@babel/preset-flow'),
Expand Down
4 changes: 0 additions & 4 deletions example.env

This file was deleted.

Loading

0 comments on commit 7c4b8d7

Please sign in to comment.