Skip to content

Commit 2e2b27e

Browse files
committed
check for update
1 parent d3abb5d commit 2e2b27e

File tree

13 files changed

+212
-34
lines changed

13 files changed

+212
-34
lines changed

app/Console/Commands/TestGrpc.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace App\Console\Commands;
44

55
use Bridge\BridgeClient;
6-
use Bridge\GetVersionRequest;
76
use Bridge\HelloRequest;
87
use Illuminate\Console\Command;
98
use Illuminate\Contracts\Filesystem\FileNotFoundException;
@@ -70,14 +69,6 @@ public function handle(): int
7069
exit(1);
7170
}
7271
echo $response->getMessage() . PHP_EOL;
73-
74-
$request2 = new GetVersionRequest();
75-
list($response2, $status2) = $client->GetVersion($request2)->wait();
76-
if ($status2->code !== \Grpc\STATUS_OK) {
77-
echo "ERROR: " . $status2->code . ", " . $status2->details . PHP_EOL;
78-
exit(1);
79-
}
80-
echo $response2->getVersion() . PHP_EOL;
8172
return 0;
8273
}
8374
}

app/Http/Controllers/SettingsController.php

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use App\Services\Bridge\BridgeClientService;
88
use App\Settings\VoiceSettings;
99
use Exception;
10+
use Illuminate\Http\JsonResponse;
1011
use Illuminate\Http\RedirectResponse;
1112
use Illuminate\Http\Request;
1213
use Inertia\Response;
@@ -19,6 +20,8 @@ public function __construct()
1920
$this->middleware('can:settings-edit')->only(['edit']);
2021

2122
$this->middleware('can:settings-edit_voice')->only(['updateVoice']);
23+
24+
$this->middleware('can:settings-cp_update_check')->only(['checkForCpUpdate']);
2225
}
2326

2427
/**
@@ -34,7 +37,7 @@ public function edit(VoiceSettings $voiceSettings)
3437

3538
$version = $bridgeClient->getControlPanelVersion();
3639
} catch (Exception $e) {
37-
flash('BRIDGE ERROR: ', $e->getMessage(), 'error');
40+
flash('BRIDGE ERROR', $e->getMessage(), 'error');
3841
}
3942

4043

@@ -51,12 +54,37 @@ public function edit(VoiceSettings $voiceSettings)
5154
* @param EditSettings $editor
5255
* @return RedirectResponse
5356
*/
54-
public function updateVoice(EditVoiceSettingsRequest $request, EditSettings $editor): RedirectResponse
55-
{
57+
public function updateVoice(EditVoiceSettingsRequest $request, EditSettings $editor): RedirectResponse
58+
{
5659
$editor->editVoiceSettings($request->all());
5760

5861
flash('Voice Settings', "Your voice settings has been successfully saved.")->success();
5962

6063
return redirect()->back();
61-
}
64+
}
65+
66+
/**
67+
* Check for control panel updates
68+
*
69+
* @return JsonResponse
70+
*/
71+
public function checkForCpUpdate(): JsonResponse
72+
{
73+
$target = 'none';
74+
try {
75+
$bridgeClient = new BridgeClientService();
76+
77+
$target = $bridgeClient->checkForControlPanelUpdate();
78+
} catch (Exception $e) {
79+
flash('BRIDGE ERROR', $e->getMessage(), 'error');
80+
}
81+
82+
if ($target === 'none') {
83+
flash('A new version of the Control Panel is available.', $target, 'info');
84+
}
85+
86+
return response()->json([
87+
$target
88+
]);
89+
}
6290
}

app/Services/Bridge/BridgeClientService.php

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
namespace App\Services\Bridge;
44

55
use Bridge\BridgeClient;
6-
use Bridge\GetVersionRequest;
6+
use Bridge\CheckForCpUpdateRequest;
7+
use Bridge\GetCpVersionRequest;
78
use Exception;
89
use Illuminate\Contracts\Filesystem\FileNotFoundException;
910
use Illuminate\Support\Facades\Storage;
@@ -35,11 +36,24 @@ public function __construct()
3536
* @return string
3637
*/
3738
public function getControlPanelVersion(): string {
38-
$request = new GetVersionRequest();
39-
list($response, $status) = $this->client->getVersion($request)->wait();
39+
$request = new GetCpVersionRequest();
40+
list($response, $status) = $this->client->getCpVersion($request)->wait();
4041
if ($status->code !== \Grpc\STATUS_OK) {
41-
throw new Exception('Error while getting version:' . $status->code . ", " . $status->details . PHP_EOL);
42+
throw new Exception('Error while getting version: ' . $status->code . ", " . $status->details . PHP_EOL);
4243
}
4344
return $response->getVersion();
4445
}
46+
47+
/**
48+
* @throws Exception
49+
* @return string
50+
*/
51+
public function checkForControlPanelUpdate(): string {
52+
$request = new CheckForCpUpdateRequest();
53+
list($response, $status) = $this->client->CheckForCpUpdate($request)->wait();
54+
if ($status->code !== \Grpc\STATUS_OK) {
55+
throw new Exception('Error while checking for Control Panel update: ' . $status->code . ", " . $status->details . PHP_EOL);
56+
}
57+
return $response->getTarget();
58+
}
4559
}

bridge/Bridge/BridgeClient.php

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,30 @@ public function SayHello(\Bridge\HelloRequest $argument,
3434

3535
/**
3636
* Get the current version of the control panel
37-
* @param \Bridge\GetVersionRequest $argument input argument
37+
* @param \Bridge\GetCpVersionRequest $argument input argument
3838
* @param array $metadata metadata
3939
* @param array $options call options
4040
* @return \Grpc\UnaryCall
4141
*/
42-
public function GetVersion(\Bridge\GetVersionRequest $argument,
42+
public function GetCpVersion(\Bridge\GetCpVersionRequest $argument,
4343
$metadata = [], $options = []) {
44-
return $this->_simpleRequest('/bridge.Bridge/GetVersion',
44+
return $this->_simpleRequest('/bridge.Bridge/GetCpVersion',
4545
$argument,
46-
['\Bridge\GetVersionReply', 'decode'],
46+
['\Bridge\GetCpVersionReply', 'decode'],
47+
$metadata, $options);
48+
}
49+
50+
/**
51+
* @param \Bridge\CheckForCpUpdateRequest $argument input argument
52+
* @param array $metadata metadata
53+
* @param array $options call options
54+
* @return \Grpc\UnaryCall
55+
*/
56+
public function CheckForCpUpdate(\Bridge\CheckForCpUpdateRequest $argument,
57+
$metadata = [], $options = []) {
58+
return $this->_simpleRequest('/bridge.Bridge/CheckForCpUpdate',
59+
$argument,
60+
['\Bridge\CheckForCpUpdateReply', 'decode'],
4761
$metadata, $options);
4862
}
4963

bridge/Bridge/BridgeStub.php

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,29 @@ public function SayHello(
2525

2626
/**
2727
* Get the current version of the control panel
28-
* @param \Bridge\GetVersionRequest $request client request
28+
* @param \Bridge\GetCpVersionRequest $request client request
2929
* @param \Grpc\ServerContext $context server request context
30-
* @return \Bridge\GetVersionReply for response data, null if if error occured
30+
* @return \Bridge\GetCpVersionReply for response data, null if if error occured
3131
* initial metadata (if any) and status (if not ok) should be set to $context
3232
*/
33-
public function GetVersion(
34-
\Bridge\GetVersionRequest $request,
33+
public function GetCpVersion(
34+
\Bridge\GetCpVersionRequest $request,
3535
\Grpc\ServerContext $context
36-
): ?\Bridge\GetVersionReply {
36+
): ?\Bridge\GetCpVersionReply {
37+
$context->setStatus(\Grpc\Status::unimplemented());
38+
return null;
39+
}
40+
41+
/**
42+
* @param \Bridge\CheckForCpUpdateRequest $request client request
43+
* @param \Grpc\ServerContext $context server request context
44+
* @return \Bridge\CheckForCpUpdateReply for response data, null if if error occured
45+
* initial metadata (if any) and status (if not ok) should be set to $context
46+
*/
47+
public function CheckForCpUpdate(
48+
\Bridge\CheckForCpUpdateRequest $request,
49+
\Grpc\ServerContext $context
50+
): ?\Bridge\CheckForCpUpdateReply {
3751
$context->setStatus(\Grpc\Status::unimplemented());
3852
return null;
3953
}
@@ -52,10 +66,16 @@ public final function getMethodDescriptors(): array
5266
'\Bridge\HelloRequest',
5367
\Grpc\MethodDescriptor::UNARY_CALL
5468
),
55-
'/bridge.Bridge/GetVersion' => new \Grpc\MethodDescriptor(
69+
'/bridge.Bridge/GetCpVersion' => new \Grpc\MethodDescriptor(
70+
$this,
71+
'GetCpVersion',
72+
'\Bridge\GetCpVersionRequest',
73+
\Grpc\MethodDescriptor::UNARY_CALL
74+
),
75+
'/bridge.Bridge/CheckForCpUpdate' => new \Grpc\MethodDescriptor(
5676
$this,
57-
'GetVersion',
58-
'\Bridge\GetVersionRequest',
77+
'CheckForCpUpdate',
78+
'\Bridge\CheckForCpUpdateRequest',
5979
\Grpc\MethodDescriptor::UNARY_CALL
6080
),
6181
];

bridge/Bridge/CheckForCpUpdateReply.php

Lines changed: 58 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bridge/Bridge/CheckForCpUpdateRequest.php

Lines changed: 31 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bridge/Bridge/GetVersionReply.php renamed to bridge/Bridge/GetCpVersionReply.php

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bridge/Bridge/GetVersionRequest.php renamed to bridge/Bridge/GetCpVersionRequest.php

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bridge/GPBMetadata/Bridge.php

165 Bytes
Binary file not shown.

config/cerberus.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,5 +141,9 @@
141141
'slug' => 'settings-edit_voice',
142142
'description' => 'a user can edit voice provider settings'
143143
],
144+
[
145+
'slug' => 'settings-cp_update_check',
146+
'description' => 'a user can check if an update of the control panel is available'
147+
],
144148
]
145149
];

resources/js/Pages/Settings/Components/UpdateSettingsForm.vue

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ import Spinner from '@/Shared/Svgs/Spinner.vue'
5252
import CheckMarkSolid from '@/Shared/Svgs/CheckMarkSolid.vue'
5353
import CloudDownload from '@/Shared/Svgs/CloudDownload.vue'
5454
import InfoCircleSolid from '@/Shared/Svgs/InfoCircleSolid.vue'
55+
import axios from 'axios'
5556
5657
@Component({
5758
components: {
@@ -77,11 +78,27 @@ export default class UpdateSettingsForm extends Mixins(Route) {
7778
7879
newVersion: string = ''
7980
80-
checkingVersion: boolean = false
81+
checkingVersion: boolean = true
8182
8283
isUpToDate: boolean = false
8384
8485
isUpdateAvailable: boolean = !(this.checkingVersion && this.isUpToDate)
86+
87+
mounted() {
88+
this.checkForUpdate()
89+
}
90+
91+
async checkForUpdate() {
92+
const res = await axios.get(this.route('settings.update.check'))
93+
94+
if (res.data.target !== this.currentVersion && res.data.target !== 'none') {
95+
this.newVersion = res.data.target
96+
} else {
97+
this.isUpToDate = true
98+
}
99+
100+
this.checkingVersion = false
101+
}
85102
}
86103
87104
</script>

routes/web.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,5 @@
4747
// Settings
4848
Route::get('settings/edit', [SettingsController::class, 'edit'])->name('settings.edit');
4949
Route::put('settings/voices', [SettingsController::class, 'updateVoice'])->name('settings.update.voice');
50+
Route::get('settings/update', [SettingsController::class, 'checkForCpUpdate'])->name('settings.update.check');
5051
});

0 commit comments

Comments
 (0)