Skip to content

Commit

Permalink
problema fix in websocket live server
Browse files Browse the repository at this point in the history
  • Loading branch information
andremalveira committed Nov 29, 2021
1 parent 2167d57 commit 0a53055
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 28 deletions.
29 changes: 16 additions & 13 deletions src/js/astronaut.build.js
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ const ASTRONAUT_LOCALHOST = {
btnliveserver.get('.icon-liveServer').addEventListener('click', e => {
var parentLayout = btnliveserver.closest('#layout'), iconLiveServer = btnliveserver.get('.icon-liveServer')
iframehref = parentLayout.get('[window] iframe').contentWindow.location.href,
liveServerIndex = `${popupLiveServerHTML({ url: iframehref, langText: langText, storageLocal: storageLocal.get() })}`,
liveServerIndex = `${popupLiveServerHTML({ url: iframehref, langText: langText, storageLocal: storageLocal.noShared.get() })}`,
popupHTML = contextMenu(liveServerIndex)

btnliveserver.insertAdjacentHTML('beforeend', popupHTML)
Expand All @@ -516,7 +516,7 @@ const ASTRONAUT_LOCALHOST = {
let liveServerAddress = btnliveserver.get('#liveServer');
let submitBtn = btnliveserver.get('#submitBtn');

var sl = storageLocal.get()
var sl = storageLocal.noShared.get()
var slls = (sl && sl.liveServer) ? sl.liveServer : false;

liveReloadCheck.checked = (slls) ? slls.isEnable : false;
Expand All @@ -531,7 +531,7 @@ const ASTRONAUT_LOCALHOST = {
actualUrl: actualServerAddress.value || '',
liveServerUrl: liveServerAddress.value || ''
}
storageLocal.set('liveServer', formData)
storageLocal.noShared.set('liveServer', formData)
chrome.runtime.sendMessage({
req: 'set-live-server-config',
data: formData
Expand Down Expand Up @@ -736,7 +736,8 @@ const ASTRONAUT_LOCALHOST = {
}
}
const windowUrl = {
open(url, elem, focus) {
open(url, elem, focus, isLiveServer) {
var isLiveServer = (isLiveServer === false) ? false : true
var host = (url == location.host) ? location.protocol + '//' + location.host + '/' : false
url = (url == undefined) ? '' : (url == location.host) ? host : url

Expand Down Expand Up @@ -796,16 +797,18 @@ const ASTRONAUT_LOCALHOST = {
if(SERVER_APACHE){
storageLocal.noShared.set('lastWindowUrl', url)
}

if (storageLocal.get('liveServer')) {
var SLliveServer = storageLocal.get('liveServer')
if(SLliveServer && SLliveServer.isEnable && SLliveServer.liveServerUrl != ''){
SLliveServer.actualUrl = url
storageLocal.set('liveServer', SLliveServer)
liveReload.apache(SLliveServer, 'windowUrl')
if(isLiveServer) {
if (storageLocal.get('liveServer')) {
var SLliveServer = storageLocal.get('liveServer')
if(SLliveServer && SLliveServer.isEnable && SLliveServer.liveServerUrl != ''){
SLliveServer.actualUrl = url
storageLocal.set('liveServer', SLliveServer)
liveReload.apache(SLliveServer, 'windowUrl')
}

}

}

//active item-list
if(listItems){
if (listItems.get('.item.active')) { listItems.get('.item.active').classList.remove('active') }
Expand Down Expand Up @@ -850,7 +853,7 @@ const ASTRONAUT_LOCALHOST = {
if (e.keyCode == 13) {
e.preventDefault()
var focus = true
windowUrl.open(barSearchURL.value, layout, focus)
windowUrl.open(barSearchURL.value, layout, focus, false)
}
})
barSearchURL.addEventListener('focus', e => {
Expand Down
30 changes: 15 additions & 15 deletions src/liveserver/reload.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const liveReload = {
}

socket = new WebSocket(address);

socket.onerror = function (event) {
astronaut.notify({
message: `${langText.liveServerFailed} -> ${langText.accessConsole}`,
Expand All @@ -84,8 +84,8 @@ const liveReload = {
socket.onmessage = (msg) => {
reloadWindow(msg, data)
};


}

function reloadWindow(msg, data) {
Expand All @@ -102,20 +102,20 @@ const liveReload = {
function logMsgForASingleTime() {
const key = 'oneTimeLog-live-server-web-extesion';
if (!sessionStorage.getItem(key)) {
/* konsole.success(`${langText.liveServerEnabled}`); */
if(viewMessage){
viewMessage = false
astronaut.notify({
message: `${langText.liveServerEnabled}`,
icon: icons.broadcast,
style: ASTRONAUT_NOTIFY_SETTINGS_DEFAULT,
autoClose: 3000
})
liveServer.isEnabled.check()

}
sessionStorage.setItem(key, 1);
}
if(viewMessage){
viewMessage = false
astronaut.notify({
message: `${langText.liveServerEnabled}`,
icon: icons.broadcast,
style: ASTRONAUT_NOTIFY_SETTINGS_DEFAULT,
autoClose: 3000
})
liveServer.isEnabled.check()

}


}

Expand Down

0 comments on commit 0a53055

Please sign in to comment.