Skip to content

Commit

Permalink
🐛 fix(core): ws的一些杂七杂八的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
Teeoo committed Dec 19, 2021
1 parent d74172f commit 32ed344
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion src/layouts/MainLayout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const browser_download_url = ref('');
const minishell = ref(false);
const $store = useInitStore();
const router = useRouter();
const ws = inject('ws') as WebSocket;
let ws = inject('ws') as WebSocket;
if (ws.readyState === 3) {
const url =
Expand All @@ -61,6 +61,7 @@ if (ws.readyState === 3) {
position: 'bottom',
message: '成功建立ws连接',
});
ws = socket;
socket.send(JSON.stringify({ type: 'ready', data: 'init' }));
socket.send(JSON.stringify({ type: 'ready', data: 'hold' }));
socket.send(JSON.stringify({ type: 'ready', data: 'message' }));
Expand Down Expand Up @@ -176,6 +177,13 @@ if (ws.readyState === 3) {
onMounted(async () => {
$q.dark.set($q.localStorage.getItem<boolean>('dark') ?? 'auto');
if (ws.readyState !== 3) {
ws.send(JSON.stringify({ type: 'ready', data: 'minishell' }));
ws.send(
JSON.stringify({ type: 'ready', data: 'minishell', id: $store.id })
);
ws.send(JSON.stringify({ type: 'shell', data: 'cwd', id: $store.id }));
}
if (
!date.isSameDate(
$q.localStorage.getItem<Date>('verCheck') ?? 0,
Expand Down Expand Up @@ -250,4 +258,29 @@ const upgrade = async () => {
const toggleLeftDrawer = (b: boolean) => {
leftDrawerOpen.value = b;
};
ws.addEventListener('message', (e) => {
const result = JSON.parse(e.data) as {
type: string;
data:
| {
type: string;
data: string;
}
| string;
};
if (result.type === 'minishell') {
let text = result.data;
if (
String(text).search('dist.zip && unzip -o dist.zip -cwd=web') !== -1 &&
String(text).search('finished') !== -1
) {
$q.notify({
position: 'top',
message: '升级成功按 Shift+F5 刷新缓存',
});
$q.localStorage.set('version', $store.tag_name ?? '未知版本');
}
}
});
</script>

0 comments on commit 32ed344

Please sign in to comment.