11import path from "path" ;
22import fs from "fs" ;
33import getLocalDataFile from "./getLocalDataFile" ;
4- import commonConst from "./commonConst" ;
54import defaultConfigForAnyPlatform from "../constans/defaultConfig" ;
65
76const configPath = path . join ( getLocalDataFile ( ) , "./rubick-config.json" ) ;
@@ -10,34 +9,34 @@ global.OP_CONFIG = {
109 config : null ,
1110 get ( ) {
1211 try {
13- if ( ! global . config ) {
14- global . config = JSON . parse (
12+ if ( ! global . OP_CONFIG . config ) {
13+ global . OP_CONFIG . config = JSON . parse (
1514 fs . readFileSync ( configPath , "utf8" ) ||
1615 JSON . stringify ( defaultConfigForAnyPlatform )
1716 ) ;
1817 }
1918 // 重置
2019 if (
21- ! global . config . version ||
22- global . config . version < defaultConfigForAnyPlatform . version
20+ ! global . OP_CONFIG . config . version ||
21+ global . OP_CONFIG . config . version < defaultConfigForAnyPlatform . version
2322 ) {
24- global . config = defaultConfigForAnyPlatform ;
23+ global . OP_CONFIG . config = defaultConfigForAnyPlatform ;
2524 fs . writeFileSync (
2625 configPath ,
2726 JSON . stringify ( defaultConfigForAnyPlatform )
2827 ) ;
2928 }
30- return global . config ;
29+ return global . OP_CONFIG . config ;
3130 } catch ( e ) {
32- global . config = defaultConfigForAnyPlatform ;
33- return global . config ;
31+ global . OP_CONFIG . config = defaultConfigForAnyPlatform ;
32+ return global . OP_CONFIG . config ;
3433 }
3534 } ,
3635 set ( value ) {
37- global . config = {
38- ...global . config ,
36+ global . OP_CONFIG . config = {
37+ ...global . OP_CONFIG . config ,
3938 ...value ,
4039 } ;
41- fs . writeFileSync ( configPath , JSON . stringify ( global . config ) ) ;
40+ fs . writeFileSync ( configPath , JSON . stringify ( global . OP_CONFIG . config ) ) ;
4241 } ,
4342} ;
0 commit comments