Skip to content
Permalink
Browse files

Add eaf-grip-token option.

  • Loading branch information...
manateelazycat committed Jul 21, 2018
1 parent ae67e7d commit 333de8866da57fc1658567e9990397f17a536e5b
@@ -109,6 +109,13 @@ Please don't run EAF with root user, root user just can access DBus's system bus
| File Uploader | Type 'eaf-upload-file' | | |
| Air Share | Type 'eaf-air-share' | | |

## Settings
If you use markdown previewer, you need access [Personal access token](https://github.com/settings/tokens/new?scopes=), fill something in "Token description" and click button "Generate token" to get your personal token, then set token with code:

```Elisp
(setq eaf-grip-token "yourtokencode")
```

## Report bug
If you have any problem with EAF, please use command "emacs -Q" start Emacs first.

@@ -32,8 +32,8 @@
from core.buffer import Buffer

class AppBuffer(Buffer):
def __init__(self, buffer_id, url):
Buffer.__init__(self, buffer_id, url, False, QColor(0, 0, 0, 255))
def __init__(self, buffer_id, url, arguments):
Buffer.__init__(self, buffer_id, url, arguments, False, QColor(0, 0, 0, 255))

self.add_widget(AirShareWidget(url, QColor(0, 0, 0, 255)))

@@ -24,8 +24,8 @@
from core.browser_buffer import BrowserBuffer

class AppBuffer(BrowserBuffer):
def __init__(self, buffer_id, url):
BrowserBuffer.__init__(self, buffer_id, url, False, QColor(255, 255, 255, 255))
def __init__(self, buffer_id, url, arguments):
BrowserBuffer.__init__(self, buffer_id, url, arguments, False, QColor(255, 255, 255, 255))

self.buffer_widget.setUrl(QUrl(url))
self.buffer_widget.titleChanged.connect(self.change_title)
@@ -29,8 +29,8 @@
from core.buffer import Buffer

class AppBuffer(Buffer):
def __init__(self, buffer_id, url):
Buffer.__init__(self, buffer_id, url, True, QColor(0, 0, 0, 255))
def __init__(self, buffer_id, url, arguments):
Buffer.__init__(self, buffer_id, url, arguments, True, QColor(0, 0, 0, 255))

self.add_widget(CameraWidget(QColor(0, 0, 0, 255)))

@@ -24,8 +24,8 @@
from core.buffer import Buffer

class AppBuffer(Buffer):
def __init__(self, buffer_id, url):
Buffer.__init__(self, buffer_id, url, True, QColor(0, 0, 0, 255))
def __init__(self, buffer_id, url, arguments):
Buffer.__init__(self, buffer_id, url, arguments, True, QColor(0, 0, 0, 255))

self.add_widget(QPushButton("Hello, EAF hacker, it's working!!!"))
self.buffer_widget.setStyleSheet("font-size: 100px")
@@ -36,8 +36,8 @@
from core.buffer import Buffer

class AppBuffer(Buffer):
def __init__(self, buffer_id, url):
Buffer.__init__(self, buffer_id, url, False, QColor(0, 0, 0, 255))
def __init__(self, buffer_id, url, arguments):
Buffer.__init__(self, buffer_id, url, arguments, False, QColor(0, 0, 0, 255))

self.add_widget(FileTransferWidget(url, QColor(0, 0, 0, 255)))

@@ -44,8 +44,8 @@
from core.buffer import Buffer

class AppBuffer(Buffer):
def __init__(self, buffer_id, url):
Buffer.__init__(self, buffer_id, url, False, QColor(0, 0, 0, 255))
def __init__(self, buffer_id, url, argument):
Buffer.__init__(self, buffer_id, url, argument, False, QColor(0, 0, 0, 255))

self.add_widget(FileUploaderWidget(url, QColor(0, 0, 0, 255)))

@@ -27,8 +27,8 @@
from core.buffer import Buffer

class AppBuffer(Buffer):
def __init__(self, buffer_id, url):
Buffer.__init__(self, buffer_id, url, False, QColor(0, 0, 0, 255))
def __init__(self, buffer_id, url, arguments):
Buffer.__init__(self, buffer_id, url, arguments, False, QColor(0, 0, 0, 255))

self.add_widget(ImageViewerWidget(url, QColor(0, 0, 0, 255)))
self.buffer_widget.render_image.connect(self.change_title)
@@ -29,15 +29,20 @@
import os

class AppBuffer(BrowserBuffer):
def __init__(self, buffer_id, url):
BrowserBuffer.__init__(self, buffer_id, url, False, QColor(255, 255, 255, 255))
def __init__(self, buffer_id, url, arguments):
BrowserBuffer.__init__(self, buffer_id, url, arguments, False, QColor(255, 255, 255, 255))

# Get free port to render markdown.
self.port = self.get_free_port()
self.url = url

# Start markdown render process.
subprocess.Popen("grip {0} {1}".format(url, self.port), shell=True)
if arguments == "":
subprocess.Popen("grip {0} {1}".format(url, self.port), shell=True)
else:
subprocess.Popen("grip --pass {0} {1} {2}".format(arguments, url, self.port), shell=True)

print("**************** ", arguments)

# Add timer make load markdown preview link after grip process start finish.
timer = threading.Timer(2, self.load_markdown_server)
@@ -62,4 +67,3 @@ def load_markdown_server(self):
paths = os.path.split(self.url)
if len(paths) > 0:
self.change_title(paths[-1])

@@ -25,8 +25,8 @@
import os

class AppBuffer(BrowserBuffer):
def __init__(self, buffer_id, url):
BrowserBuffer.__init__(self, buffer_id, url, False, QColor(255, 255, 255, 255))
def __init__(self, buffer_id, url, arguments):
BrowserBuffer.__init__(self, buffer_id, url, arguments, False, QColor(255, 255, 255, 255))

self.url = url

@@ -28,8 +28,8 @@
from core.buffer import Buffer

class AppBuffer(Buffer):
def __init__(self, buffer_id, url):
Buffer.__init__(self, buffer_id, url, False, QColor(0, 0, 0, 255))
def __init__(self, buffer_id, url, arguments):
Buffer.__init__(self, buffer_id, url, arguments, False, QColor(0, 0, 0, 255))

self.add_widget(PdfViewerWidget(url, QColor(0, 0, 0, 255)))
self.buffer_widget.send_jump_page_message.connect(self.send_jump_page_message)
@@ -27,8 +27,8 @@
from core.buffer import Buffer

class AppBuffer(Buffer):
def __init__(self, buffer_id, url):
Buffer.__init__(self, buffer_id, url, True, QColor(0, 0, 0, 255))
def __init__(self, buffer_id, url, arguments):
Buffer.__init__(self, buffer_id, url, arguments, True, QColor(0, 0, 0, 255))

self.add_widget(VideoPlayerWidget())
self.buffer_widget.play(url)
@@ -49,7 +49,7 @@ def save_session_data(self):
def restore_session_data(self, session_data):
position = int(session_data)
self.buffer_widget.media_player.setPosition(position)

class VideoPlayerWidget(QWidget):

def __init__(self, parent=None):
@@ -25,8 +25,8 @@

class BrowserBuffer(Buffer):

def __init__(self, buffer_id, url, fit_to_view, background_color):
Buffer.__init__(self, buffer_id, url, fit_to_view, background_color)
def __init__(self, buffer_id, url, arguments, fit_to_view, background_color):
Buffer.__init__(self, buffer_id, url, arguments, fit_to_view, background_color)

self.add_widget(BrowserView())

@@ -34,11 +34,12 @@ class Buffer(QGraphicsScene):
input_message = QtCore.pyqtSignal(str, str, str)
close_buffer = QtCore.pyqtSignal(str)

def __init__(self, buffer_id, url, fit_to_view, background_color):
def __init__(self, buffer_id, url, arguments, fit_to_view, background_color):
super(QGraphicsScene, self).__init__()

self.buffer_id = buffer_id
self.url = url
self.arguments = arguments
self.fit_to_view = fit_to_view
self.background_color = background_color
self.setBackgroundBrush(QBrush(self.background_color))
@@ -52,8 +52,8 @@ from PyQt5.QtWidgets import QPushButton
from core.buffer import Buffer
class AppBuffer(Buffer):
def __init__(self, buffer_id, url):
Buffer.__init__(self, buffer_id, url, True, QColor(0, 0, 0, 255))
def __init__(self, buffer_id, url, arguments):
Buffer.__init__(self, buffer_id, url, arguments, True, QColor(0, 0, 0, 255))
self.add_widget(QPushButton("Hello, EAF hacker, it's work!!!"))
self.buffer_widget.setStyleSheet("font-size: 100px")
@@ -107,8 +107,8 @@ Below is code example from pdfviewer:
...
class AppBuffer(Buffer):
def __init__(self, buffer_id, url):
Buffer.__init__(self, buffer_id, url, False, QColor(0, 0, 0, 255))
def __init__(self, buffer_id, url, arguments):
Buffer.__init__(self, buffer_id, url, arguments, False, QColor(0, 0, 0, 255))
self.add_widget(PdfViewerWidget(url, QColor(0, 0, 0, 255)))
self.buffer_widget.send_jump_page_message.connect(self.send_jump_page_message)
@@ -209,7 +209,7 @@ If your application will do some long-time operation, you can use below use belo
def start_progress(self):
def stop_progress(self):
def update_progress(self, progress):
```
```


## Todolist
@@ -4,7 +4,6 @@
* Browser: implement js plugin like vimium
* Browser: study more code from https://github.com/LavaPower/Browthon-Old/blob/c25d5721b40e95131a3c521566a18467f13ecbf0/files/Browthon_elements.py
* ImageViewer: add zoom support
* Markdown Previewer: make grip render offline or switch other backend to fix github api times limit.
* Pdfviewer: hover mouse to detect url postion, ctrl + button can open url under mouse.
* Pdfviewer: open link like vimium.
* Pdfviewer: fix page still in scrolling even user release key.
20 eaf.el
@@ -113,6 +113,8 @@

(defvar eaf-first-start-app-name nil)

(defvar eaf-first-start-arguments nil)

(defvar eaf-title-length 30)

(defvar eaf-org-file-list '())
@@ -123,6 +125,8 @@

(defvar eaf-last-frame-height 0)

(defvar eaf-grip-token nil)

(defcustom eaf-name "*eaf*"
"Name of eaf buffer."
:type 'string
@@ -174,6 +178,7 @@
;; Clean cache url and app name, avoid next start process to open buffer.
(setq eaf-first-start-url nil)
(setq eaf-first-start-app-name nil)
(setq eaf-first-start-arguments nil)

;; Clean `eaf-org-file-list' and `eaf-org-killed-file-list'.
(dolist (org-file-name eaf-org-file-list)
@@ -432,7 +437,7 @@ We need calcuate render allocation to make sure no black border around render co

(defun eaf-start-finish ()
;; Call `eaf-open-internal' after receive `start_finish' signal from server process.
(eaf-open-internal eaf-first-start-url eaf-first-start-app-name))
(eaf-open-internal eaf-first-start-url eaf-first-start-app-name eaf-first-start-arguments))

(dbus-register-signal
:session "com.lazycat.eaf" "/com/lazycat/eaf"
@@ -479,11 +484,11 @@ We need calcuate render allocation to make sure no black border around render co
(add-hook 'kill-buffer-hook #'eaf-monitor-buffer-kill)
(add-hook 'after-save-hook #'eaf-monitor-buffer-save)

(defun eaf-open-internal (url app-name)
(defun eaf-open-internal (url app-name arguments)
(let* ((buffer (eaf-create-buffer url))
buffer-result)
(with-current-buffer buffer
(setq buffer-result (eaf-call "new_buffer" buffer-id url app-name)))
(setq buffer-result (eaf-call "new_buffer" buffer-id url app-name arguments)))
(if (equal buffer-result "")
(progn
;; Switch to new buffer if buffer create successful.
@@ -500,7 +505,7 @@ We need calcuate render allocation to make sure no black border around render co
(message buffer-result))
))

(defun eaf-open (url &optional app-name)
(defun eaf-open (url &optional app-name arguments)
(interactive "FOpen with EAF: ")
;; Try set app-name along with url if app-name is set.
(unless app-name
@@ -514,6 +519,10 @@ We need calcuate render allocation to make sure no black border around render co
(cond ((member extension-name '("pdf" "xps" "oxps" "cbz" "epub" "fb2" "fbz"))
(setq app-name "pdfviewer"))
((member extension-name '("md"))
;; Try get user's github token if `eaf-grip-token' is nil.
(if eaf-grip-token
(setq arguments eaf-grip-token)
(setq arguments (read-string "Fill your own github token: ")))
;; Split window to show file and previewer.
(eaf-split-preview-windows)
(setq app-name "markdownpreviewer"))
@@ -561,10 +570,11 @@ We need calcuate render allocation to make sure no black border around render co
;; if no match buffer found, call `eaf-open-internal'.
(if exists-eaf-buffer
(switch-to-buffer exists-eaf-buffer)
(eaf-open-internal url app-name)))
(eaf-open-internal url app-name arguments)))
;; Record user input, and call `eaf-open-internal' after receive `start_finish' signal from server process.
(setq eaf-first-start-url url)
(setq eaf-first-start-app-name app-name)
(setq eaf-first-start-arguments arguments)
(eaf-start-process)
(message (format "Opening %s with eaf.%s" url app-name)))
;; Output something to user if app-name is empty string.
16 eaf.py
@@ -55,11 +55,11 @@ def __init__(self, args):

self.session_file_path = os.path.expanduser("~/.emacs.d/eaf/session.json")

@dbus.service.method(EAF_DBUS_NAME, in_signature="sss", out_signature="s")
def new_buffer(self, buffer_id, url, app_name):
@dbus.service.method(EAF_DBUS_NAME, in_signature="ssss", out_signature="s")
def new_buffer(self, buffer_id, url, app_name, arguments):
# NOTE: We need use function str convert dbus.String to String,
# otherwise some library will throw error, such as fitz library.
return self.create_app(buffer_id, str(url), "app.{0}.buffer".format(str(app_name)))
return self.create_app(buffer_id, str(url), "app.{0}.buffer".format(str(app_name)), arguments)

@dbus.service.method(EAF_DBUS_NAME, in_signature="sss", out_signature="")
def update_buffer_with_url(self, module_path, buffer_url, update_data):
@@ -91,30 +91,30 @@ def create_new_browser_window(self):
buffer_id = self.get_new_browser_window_buffer_id()

# Create buffer for create new browser window.
app_buffer = self.create_buffer(buffer_id, "http://0.0.0.0", "app.browser.buffer")
app_buffer = self.create_buffer(buffer_id, "http://0.0.0.0", "app.browser.buffer", "")

# Create emacs buffer with buffer id.
self.create_new_browser_buffer(buffer_id)

# Return new QWebEngineView for create new browser window.
return app_buffer.buffer_widget

def create_app(self, buffer_id, url, module_path):
def create_app(self, buffer_id, url, module_path, arguments):
try:
self.create_buffer(buffer_id, url, module_path)
self.create_buffer(buffer_id, url, module_path, arguments)

return ""
except ImportError:
import traceback
traceback.print_exc()
return "Something wrong when import {0}".format(module_path)

def create_buffer(self, buffer_id, url, module_path):
def create_buffer(self, buffer_id, url, module_path, arguments):
global emacs_width, emacs_height

# Create application buffer.
module = importlib.import_module(module_path)
app_buffer = module.AppBuffer(buffer_id, url)
app_buffer = module.AppBuffer(buffer_id, url, arguments)
app_buffer.module_path = module_path

# Add buffer to buffer dict.

0 comments on commit 333de88

Please sign in to comment.
You can’t perform that action at this time.