-
Notifications
You must be signed in to change notification settings - Fork 655
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Pompurin404
committed
Aug 2, 2024
1 parent
ebbd3a2
commit 7c00ddc
Showing
15 changed files
with
182 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { appConfigPath } from '../utils/dirs' | ||
import yaml from 'yaml' | ||
import fs from 'fs' | ||
|
||
export let appConfig: IAppConfig // config.yaml | ||
|
||
export function getAppConfig(force = false): IAppConfig { | ||
if (force || !appConfig) { | ||
appConfig = yaml.parse(fs.readFileSync(appConfigPath(), 'utf-8')) | ||
} | ||
return appConfig | ||
} | ||
|
||
export function setAppConfig(patch: Partial<IAppConfig>): void { | ||
appConfig = Object.assign(appConfig, patch) | ||
fs.writeFileSync(appConfigPath(), yaml.stringify(appConfig)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { controledMihomoConfigPath } from '../utils/dirs' | ||
import yaml from 'yaml' | ||
import fs from 'fs' | ||
|
||
export let controledMihomoConfig: Partial<IMihomoConfig> // mihomo.yaml | ||
|
||
export function getControledMihomoConfig(force = false): Partial<IMihomoConfig> { | ||
if (force || !controledMihomoConfig) { | ||
controledMihomoConfig = yaml.parse(fs.readFileSync(controledMihomoConfigPath(), 'utf-8')) | ||
} | ||
return controledMihomoConfig | ||
} | ||
|
||
export function setControledMihomoConfig(patch: Partial<IMihomoConfig>): void { | ||
controledMihomoConfig = Object.assign(controledMihomoConfig, patch) | ||
fs.writeFileSync(controledMihomoConfigPath(), yaml.stringify(controledMihomoConfig)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
export { appConfig, getAppConfig, setAppConfig } from './app' | ||
export { | ||
controledMihomoConfig, | ||
getControledMihomoConfig, | ||
setControledMihomoConfig | ||
} from './controledMihomo' | ||
export { | ||
profileConfig, | ||
currentProfile, | ||
getCurrentProfile, | ||
getCurrentProfileItem, | ||
getProfileItem, | ||
getProfileConfig, | ||
addProfileItem, | ||
removeProfileItem, | ||
createProfile | ||
} from './profile' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { | ||
appConfigPath, | ||
controledMihomoConfigPath, | ||
dataDir, | ||
logDir, | ||
mihomoWorkDir, | ||
profileConfigPath, | ||
profilePath, | ||
profilesDir, | ||
resourcesFilesDir | ||
} from '../utils/dirs' | ||
import { | ||
getAppConfig, | ||
getControledMihomoConfig, | ||
getCurrentProfile, | ||
getProfileConfig | ||
} from '../config' | ||
import { | ||
defaultConfig, | ||
defaultControledMihomoConfig, | ||
defaultProfile, | ||
defaultProfileConfig | ||
} from '../utils/template' | ||
import yaml from 'yaml' | ||
import fs from 'fs' | ||
import path from 'path' | ||
|
||
function initDirs(): void { | ||
if (!fs.existsSync(dataDir)) { | ||
fs.mkdirSync(dataDir) | ||
} | ||
if (!fs.existsSync(profilesDir())) { | ||
fs.mkdirSync(profilesDir()) | ||
} | ||
if (!fs.existsSync(mihomoWorkDir())) { | ||
fs.mkdirSync(mihomoWorkDir()) | ||
} | ||
if (!fs.existsSync(logDir())) { | ||
fs.mkdirSync(logDir()) | ||
} | ||
} | ||
|
||
function initConfig(): void { | ||
if (!fs.existsSync(appConfigPath())) { | ||
fs.writeFileSync(appConfigPath(), yaml.stringify(defaultConfig)) | ||
} | ||
if (!fs.existsSync(profileConfigPath())) { | ||
fs.writeFileSync(profileConfigPath(), yaml.stringify(defaultProfileConfig)) | ||
} | ||
if (!fs.existsSync(profilePath('default'))) { | ||
fs.writeFileSync(profilePath('default'), yaml.stringify(defaultProfile)) | ||
} | ||
if (!fs.existsSync(controledMihomoConfigPath())) { | ||
fs.writeFileSync(controledMihomoConfigPath(), yaml.stringify(defaultControledMihomoConfig)) | ||
} | ||
getAppConfig(true) | ||
getControledMihomoConfig(true) | ||
getProfileConfig(true) | ||
getCurrentProfile(true) | ||
} | ||
|
||
function initFiles(): void { | ||
const fileList = ['Country.mmdb', 'geoip.dat', 'geosite.dat'] | ||
for (const file of fileList) { | ||
const targetPath = path.join(profilesDir(), file) | ||
const sourcePath = path.join(resourcesFilesDir(), file) | ||
if (!fs.existsSync(targetPath) && fs.existsSync(sourcePath)) { | ||
fs.copyFileSync(sourcePath, targetPath) | ||
} | ||
} | ||
} | ||
|
||
export function init(): void { | ||
initDirs() | ||
initConfig() | ||
initFiles() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.