Skip to content

Commit

Permalink
feat: check version
Browse files Browse the repository at this point in the history
  • Loading branch information
maotoumao committed Aug 28, 2022
1 parent 223e42b commit c767681
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 33 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"@react-navigation/native-stack": "^6.7.0",
"axios": "^0.27.2",
"color": "^4.2.3",
"compare-versions": "^5.0.1",
"crypto-js": "^4.1.1",
"dayjs": "^1.11.4",
"deepmerge": "^4.2.2",
Expand All @@ -35,6 +36,7 @@
"react-native": "0.69.1",
"react-native-bootsplash": "^4.3.2",
"react-native-circular-progress-indicator": "^4.4.0",
"react-native-device-info": "^10.0.2",
"react-native-document-picker": "^8.1.1",
"react-native-fs": "^2.20.0",
"react-native-gesture-handler": "^2.5.0",
Expand Down
2 changes: 1 addition & 1 deletion src/common/localConfigManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ type ExceptionType = IMusic.IMusicItem | IMusic.IMusicItem[];
interface IConfig {
setting: {
theme: {
mode: 'light' | 'dark' | 'custom';
mode: 'light' | 'dark' | 'custom-light' | 'custom-dark';
background: string;
backgroundOpacity: number;
backgroundBlur: number;
Expand Down
4 changes: 2 additions & 2 deletions src/common/musicQueue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,10 @@ const getMusicTrack = async (musicItem: IMusic.IMusicItem): Promise<Track> => {
} else {
// 插件播放
const plugin = pluginManager.getPlugin(musicItem.platform);
if (plugin && plugin.instance.playMusic) {
if (plugin && plugin.instance.getMusicTrack) {
try {
const {url, headers} =
(await plugin.instance.playMusic(musicItem)) ?? {};
(await plugin.instance.getMusicTrack(musicItem)) ?? {};
if (!url) {
throw new Error();
}
Expand Down
14 changes: 12 additions & 2 deletions src/common/pluginManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import axios from 'axios';
import {useEffect, useState} from 'react';
import {ToastAndroid} from 'react-native';
import pathConst from '@/constants/pathConst';
import {satisfies} from 'compare-versions';
import DeviceInfo from 'react-native-device-info';

const pluginPath = pathConst.pluginPath;
const sha256 = CryptoJs.SHA256;
Expand Down Expand Up @@ -33,7 +35,8 @@ class Plugin {
this.state = 'error';
_instance = {
platform: '',
async playMusic() {
appVersion: '',
async getMusicTrack() {
return null;
},
async search() {
Expand All @@ -57,11 +60,18 @@ class Plugin {
const keys: Array<keyof IPlugin.IPluginInstance> = [
'getAlbumInfo',
'search',
'playMusic',
'getMusicTrack',
];
if (keys.every(k => !_instance[k])) {
return false;
}
/** 版本号校验 */
if (
_instance.appVersion &&
!satisfies(DeviceInfo.getVersion(), _instance.appVersion)
) {
return false;
}
return true;
}
}
Expand Down
21 changes: 12 additions & 9 deletions src/entry/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,17 @@ const Stack = createNativeStackNavigator();
export default function Pages() {
const themeName = useConfig('setting.theme.mode') ?? 'dark';
const themeColors = useConfig('setting.theme.colors') ?? {};
const theme = themeName === 'dark' ? CustomTheme : DefaultTheme;
const mergedTheme = {
...theme,
colors: {
...theme.colors,
...themeColors,
},
};
const theme = themeName.includes('dark') ? CustomTheme : DefaultTheme;
const isCustom = themeName.includes('custom') ? true : false;
const mergedTheme = isCustom
? {
...theme,
colors: {
...theme.colors,
...themeColors,
},
}
: theme;
useEffect(() => {
if (__DEV__) {
RNBootSplash.hide({fade: true});
Expand All @@ -52,7 +55,7 @@ export default function Pages() {
<Stack.Navigator
initialRouteName={routes[0].path}
screenOptions={{
statusBarColor:'transparent',
statusBarColor: 'transparent',
statusBarTranslucent: true,
headerShown: false,
animation: 'slide_from_right',
Expand Down
25 changes: 11 additions & 14 deletions src/entry/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,39 +17,36 @@ const DefaultTheme = {
colors: {
..._DefaultTheme.colors,
text: '#333333',

placeholder: '#666666',
background: 'rgba(128,128,128,0.1)',
primary: '#cdd1d3',
surface: '#cdd1d3',
}
}
},
};

const CustomTheme = {
..._CustomTheme,
colors: {
..._CustomTheme.colors,
/** 文字 */
primary: "#2b333e",
primary: '#2b333e',
secondary: '#cdd1d3',
text: '#eeeeee',
textSecondary: '#aaaaaa',
textHighlight: '#eba0b3',
textPlaceholder: '#4f4f4f',
placeholder: '#424242',
textPlaceholder: '#424242',
placeholder: '#4f4f4f',
background: 'transparent',
pageBackground: '#100000',
backdrop: 'rgba(0,0,0,0.2)',

},
};

const LightTheme = {
...DefaultTheme,
colors: {

}
}
colors: {},
};

export {DarkTheme, DefaultTheme, CustomTheme};

Expand All @@ -64,6 +61,6 @@ export {DarkTheme, DefaultTheme, CustomTheme};
* placeholder: placeholder颜色
* background: 页面背景色
* backdrop: 列表背景色
*
*
*/
*
*
*/
3 changes: 2 additions & 1 deletion src/pages/home/components/drawer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {ROUTE_PATH} from '@/entry/router';
import {fontSizeConst, fontWeightConst} from '@/constants/uiConst';
import ThemeText from '@/components/themeText';
import PageBackground from '@/components/pageBackground';
import DeviceInfo from 'react-native-device-info';

interface IDrawerProps {}

Expand Down Expand Up @@ -62,7 +63,7 @@ export default function HomeDrawer(props: IDrawerProps) {
<PageBackground></PageBackground>
<DrawerContentScrollView {...props} style={style.scrollWrapper}>
<View style={style.header}>
<ThemeText fontSize='appbar' fontWeight='bold'>Music Free</ThemeText>
<ThemeText fontSize='appbar' fontWeight='bold'>{DeviceInfo.getApplicationName()}</ThemeText>
<IconButton icon={'qrcode-scan'} size={rpx(36)}></IconButton>
</View>
<Card style={style.card}>
Expand Down
11 changes: 8 additions & 3 deletions src/pages/setting/settingTypes/themeSetting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,17 @@ export default function ThemeSetting(props: IThemeSettingProps) {
const secondaryColor = Color(colors.average)
.darken(0.3)
.toString();
const textHighlight = Color(0xffffff - Color(primaryColor).rgbNumber(), 'rgb').saturate(0.5).toString();

const textHighlight = Color(
0xffffff - Color(primaryColor).rgbNumber(),
'rgb',
)
.saturate(0.5)
.toString();
setConfig('setting.theme.mode', 'custom-dark');
setConfig('setting.theme.colors', {
primary: primaryColor,
secondary: secondaryColor,
textHighlight: textHighlight
textHighlight: textHighlight,
});
} catch (e) {
console.log(e);
Expand Down
4 changes: 3 additions & 1 deletion src/types/plugin.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ declare namespace IPlugin {
export interface IPluginInstance {
/** 来源名 */
platform: string;
playMusic?: (musicItem: MusicItemBase) => Promise<IPlayResult | null>;
/** 匹配的版本号 */
appVersion?: string;
getMusicTrack?: (musicItem: MusicItemBase) => Promise<IPlayResult | null>;
search?: (keyword: string, page?: number) => Promise<ISearchResult>;
getAlbumInfo?: (albumItem: IAlbum.IAlbumItem) => Promise<IMusic.IMusicItem[] | null>;
}
Expand Down
10 changes: 10 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3149,6 +3149,11 @@ compare-func@^2.0.0:
array-ify "^1.0.0"
dot-prop "^5.1.0"

compare-versions@^5.0.1:
version "5.0.1"
resolved "https://registry.npmmirror.com/compare-versions/-/compare-versions-5.0.1.tgz#14c6008436d994c3787aba38d4087fabe858555e"
integrity sha512-v8Au3l0b+Nwkp4G142JcgJFh1/TUhdxut7wzD1Nq1dyp5oa3tXaqb03EXOAB6jS4gMlalkjAUPZBMiAfKUixHQ==

component-emitter@^1.2.1:
version "1.3.0"
resolved "https://registry.npmmirror.com/component-emitter/-/component-emitter-1.3.0.tgz#16e4070fba8ae29b679f2215853ee181ab2eabc0"
Expand Down Expand Up @@ -7117,6 +7122,11 @@ react-native-codegen@^0.69.1:
jscodeshift "^0.13.1"
nullthrows "^1.1.1"

react-native-device-info@^10.0.2:
version "10.0.2"
resolved "https://registry.npmmirror.com/react-native-device-info/-/react-native-device-info-10.0.2.tgz#17cd96df277cca5a22fb80409527c181a08d4ed1"
integrity sha512-6XY8EctYqNEX6EHDoHxz3yONOYxCHKrgEdStP7HZDYzFXb1JB5BFt7UbXDWrmihXUZDv06sBsjN26+Tp0EajXw==

react-native-document-picker@^8.1.1:
version "8.1.1"
resolved "https://registry.npmmirror.com/react-native-document-picker/-/react-native-document-picker-8.1.1.tgz#642bbe25752cc428b96416318f8dc07cef29ee10"
Expand Down

0 comments on commit c767681

Please sign in to comment.