Repository navigation
luci-app-v2raya: add overview and richer settings #9243
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
+487
−130
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
185 changes: 112 additions & 73 deletions
185
applications/luci-app-v2raya/htdocs/luci-static/resources/view/v2raya/config.js
This file contains hidden or 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
106 changes: 54 additions & 52 deletions
106
applications/luci-app-v2raya/htdocs/luci-static/resources/view/v2raya/log.js
This file contains hidden or 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 |
|---|---|---|
| @@ -1,75 +1,77 @@ | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| 'use strict'; | ||
| 'require dom'; | ||
| 'require fs'; | ||
| 'require poll'; | ||
| 'require uci'; | ||
| 'require ui'; | ||
| 'require view'; | ||
|
|
||
| var LOG_PATH = '/var/log/v2raya/v2raya.log'; | ||
| var MAX_LINES = 500; | ||
| var POLL_INTERVAL = 5; | ||
|
|
||
| return view.extend({ | ||
| render: function() { | ||
| /* Thanks to luci-app-aria2 */ | ||
| var css = ' \ | ||
| #log_textarea { \ | ||
| padding: 10px; \ | ||
| text-align: left; \ | ||
| } \ | ||
| #log_textarea pre { \ | ||
| padding: .5rem; \ | ||
| word-break: break-all; \ | ||
| margin: 0; \ | ||
| } \ | ||
| .description { \ | ||
| background-color: #33ccff; \ | ||
| }'; | ||
| render: function () { | ||
| var logEl = E('pre', { | ||
| id: 'v2raya-log', | ||
| style: 'white-space:pre-wrap;word-break:break-all;max-height:65vh;overflow:auto;padding:8px;margin:0;background:rgba(0,0,0,0.04);border-radius:4px' | ||
| }, _('Loading…')); | ||
|
|
||
| var refresh = function () { | ||
| return L.resolveDefault(fs.read_direct(LOG_PATH, 'text'), null).then(function (text) { | ||
| if (text === null) { | ||
| dom.content(logEl, _('The log file does not exist yet. Start the service and try again.')); | ||
| return; | ||
| } | ||
|
|
||
| var log_textarea = E('div', { 'id': 'log_textarea' }, | ||
| E('img', { | ||
| 'src': L.resource('icons/loading.svg'), | ||
| 'alt': _('Loading…'), | ||
| 'style': 'vertical-align:middle' | ||
| }, _('Collecting data…')) | ||
| ); | ||
| var lines = text.replace(/\s+$/, '').split('\n'); | ||
| if (lines.length > MAX_LINES) | ||
| lines = lines.slice(-MAX_LINES); | ||
|
|
||
| var log_path = '/var/log/v2raya/v2raya.log'; | ||
| var atBottom = (logEl.scrollTop + logEl.clientHeight + 20) >= logEl.scrollHeight; | ||
| dom.content(logEl, lines.join('\n') || _('The log is empty.')); | ||
|
|
||
| if (atBottom) | ||
| logEl.scrollTop = logEl.scrollHeight; | ||
| }).catch(function (err) { | ||
| dom.content(logEl, _('Unable to read the log: %s').format(err)); | ||
| }); | ||
| }; | ||
|
|
||
| poll.add(L.bind(function() { | ||
| return fs.read_direct(log_path, 'text') | ||
| .then(function(res) { | ||
| var log = E('pre', { 'wrap': 'pre' }, [ | ||
| res.trim() || _('Log is clean.') | ||
| ]); | ||
| var refreshBtn = E('button', { class: 'btn cbi-button cbi-button-action' }, _('Refresh')); | ||
| var clearBtn = E('button', { class: 'btn cbi-button cbi-button-reset' }, _('Clear log')); | ||
|
|
||
| dom.content(log_textarea, log); | ||
| }).catch(function(err) { | ||
| var log; | ||
| refreshBtn.addEventListener('click', function () { refresh(); }); | ||
| clearBtn.addEventListener('click', function () { | ||
| if (!confirm(_('Clear the v2rayA log file?'))) | ||
| return; | ||
|
|
||
| if (err.toString().includes('NotFoundError')) | ||
| log = E('pre', { 'wrap': 'pre' }, [ | ||
| _('Log file does not exist.') | ||
| ]); | ||
| L.resolveDefault(fs.write(LOG_PATH, ''), null).then(function (res) { | ||
| if (res === null) | ||
| ui.addNotification(null, E('p', {}, _('Unable to clear the log file.')), 'danger'); | ||
| else | ||
| log = E('pre', { 'wrap': 'pre' }, [ | ||
| _('Unknown error: %s').format(err) | ||
| ]); | ||
| ui.addNotification(null, E('p', {}, _('Log file cleared.')), 'info'); | ||
|
|
||
| dom.content(log_textarea, log); | ||
| refresh(); | ||
| }); | ||
| })); | ||
| }); | ||
|
|
||
| return E([ | ||
| E('style', [ css ]), | ||
| E('div', {'class': 'cbi-map'}, [ | ||
| E('div', {'class': 'cbi-section'}, [ | ||
| log_textarea, | ||
| E('div', {'style': 'text-align:right'}, | ||
| E('small', {}, _('Refresh every %d seconds.').format(L.env.pollinterval)) | ||
| ) | ||
| ]) | ||
| refresh(); | ||
| poll.add(refresh, POLL_INTERVAL); | ||
|
|
||
| return E('div', { class: 'cbi-map' }, [ | ||
| E('h2', {}, _('v2rayA log')), | ||
| E('div', { class: 'cbi-map-descr' }, | ||
| _('Showing the last %d lines of %s. Refreshes every %d seconds.') | ||
| .format(MAX_LINES, LOG_PATH, POLL_INTERVAL)), | ||
| E('div', { class: 'cbi-section' }, [ | ||
| logEl, | ||
| E('div', { style: 'margin-top:8px' }, [ refreshBtn, ' ', clearBtn ]) | ||
| ]) | ||
| ]); | ||
| }, | ||
|
|
||
| handleSaveApply: null, | ||
| handleSave: null, | ||
| handleSaveApply: null, | ||
| handleReset: null | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
baseurl,core_startup_timeout,redirect_respect_bound_device,v2ray_assetsdir,gomemlimit,gomaxprocs,gogcandnofileare not read by the current v2raya init script, so with 2.2.x they silently do nothing even though the commit says the app still works there. The body says this waits on openwrt/packages#31261, but the PR is not marked draft — should it be, or should these options be hidden when the backend lacks them?Generated by Claude Code