Skip to content

Commit

Permalink
[update] Version compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
lkeme committed Nov 29, 2021
1 parent b5e75eb commit 534b20d
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 10 deletions.
2 changes: 1 addition & 1 deletion NOTIFY.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ filter_words =
**钉钉**

> 文档: https://developers.dingtalk.com/文档ument/robots/custom-robot-access
> 文档: https://developers.dingtalk.com/document/robots/custom-robot-access
> 说明: 钉钉推送的密钥
```ini
Expand Down
7 changes: 5 additions & 2 deletions data/latest_version.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
"source": "https://github.com/lkeme/BiliHelper-personal",
"raw_url": "https://cdn.jsdelivr.net/gh/lkeme/BiliHelper-personal@master/data/latest_version.json",
"purge_url": "https://purge.jsdelivr.net/gh/lkeme/BiliHelper-personal@master/data/latest_version.json",
"version": "1.0.2.211115",
"version": "1.0.2.211114",
"des": "程序有更新,请及时线上查看更新哦~",
"time": "2021年11月15日15:40:35"
"time": "2021年11月15日15:40:35",
"ini_version": "0.0.1",
"ini_des": "配置有更新,请及时线上查看更新哦~",
"ini_time": "2021年11月15日15:40:35"
}
5 changes: 3 additions & 2 deletions src/core/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,12 @@ function setConf($name, $value, int|string $section = 0, $key = null)
/**
* @use 开关
* @param string $plugin
* @param bool $default
* @return bool
*/
function getEnable(string $plugin): bool
function getEnable(string $plugin, bool $default = false): bool
{
return getConf('enable', $plugin);
return getConf('enable', $plugin) ?: $default;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/plugin/AloneTcpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ private static function packMsg($value, string $fmt = "N"): string
* @return mixed
* @throws \Exception
*/
private static function unPackMsg($value, string $fmt = "N"):mixed
private static function unPackMsg($value, string $fmt = "N"): mixed
{
return unpack($fmt, $value)[1];
}
Expand Down
31 changes: 28 additions & 3 deletions src/plugin/CheckUpdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,28 @@ private static function check()
self::loadJsonData();
Log::info('拉取线上最新配置');
self::fetchLatest();
// 检测项目版本
if (!self::compareVersion()) {
Log::info('项目已是最新版本');
Log::info('程序已是最新版本');
} else {
Log::notice('项目有更新');
// Todo 完善提示信息
$time = self::$latest_conf->get('time');
$version = self::$latest_conf->get('version');
$des = self::$latest_conf->get('des');
$info = "最新版本-$version, $des";
$info = "请注意程序有版本更新变动哦~\n\n版本号: $version\n\n更新日志: $des\n\n更新时间: $time\n\n";
Log::notice($info);
Notice::push('update', $info);
}

// 检测配置版本
if (!self::compareINIVersion()) {
Log::info('配置已是最新版本');
} else {
$time = self::$latest_conf->get('ini_time');
$version = self::$latest_conf->get('ini_version');
$des = self::$latest_conf->get('ini_des');
$info = "请注意配置有版本变动更新哦~\n\n版本号: $version\n\n更新日志: $des\n\n更新时间: $time\n\n";
Log::notice($info);
Notice::push('update', $info);
}
}
Expand Down Expand Up @@ -87,4 +100,16 @@ private static function compareVersion(): bool
return !($current_version == $latest_version);
}

/**
* @use 比较INI版本号
* @return bool
*/
private static function compareINIVersion(): bool
{
$current_version = self::$current_conf->get('ini_version');
$latest_version = self::$latest_conf->get('ini_version');
// true 有更新 false 无更新
return !($current_version == $latest_version);
}

}
5 changes: 4 additions & 1 deletion src/plugin/Notice.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ private static function sendInfoHandle(string $type, string $uname, string $resu
$now_time = date('Y-m-d H:i:s');
$info = match ($type) {
'update' => [
'title' => '程序更新通知',
'title' => '版本更新通知',
'content' => "[$now_time] 用户: $uname 程序更新通知: $result"
],
'anchor' => [
Expand Down Expand Up @@ -127,6 +127,9 @@ private static function sendInfoHandle(string $type, string $uname, string $resu
],
};

// 添加前缀
$info['title'] = "【BHP】" . $info['title'];

self::sendLog($info);
return true;
}
Expand Down

0 comments on commit 534b20d

Please sign in to comment.