Skip to content

Commit 12a321e

Browse files
committed
windows: install to startup with powershell
1 parent a4c3f4a commit 12a321e

File tree

6 files changed

+64
-61
lines changed

6 files changed

+64
-61
lines changed

autoload/denops_shared_server.vim

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,31 @@ function! denops_shared_server#install() abort
1010
\ 'hostname': hostname,
1111
\ 'port': port,
1212
\}
13-
if executable('launchctl')
13+
if has('win32') && executable('powershell.exe')
14+
call denops_shared_server#runtray#install(options)
15+
elseif executable('launchctl')
1416
call denops_shared_server#launchctl#install(options)
1517
elseif executable('systemctl')
1618
call denops_shared_server#systemctl#install(options)
17-
elseif has('win32')
18-
call denops_shared_server#winsw#install(options)
1919
else
2020
call denops#util#error('This platform is not supported. Please configure denops-shared-server manually.')
2121
return
2222
endif
23-
call denops#util#info('wait 1 second for the shared server startup...')
24-
sleep 1
23+
call denops#util#info('wait 5 second for the shared server startup...')
24+
sleep 5
2525
call denops#util#info('connect to the shared server')
2626
call denops#server#connect(g:denops_server_addr)
2727
call denops#util#info('stop the local server')
2828
call denops#server#stop()
2929
endfunction
3030

3131
function! denops_shared_server#uninstall() abort
32-
if executable('launchctl')
32+
if has('win32') && executable('powershell.exe')
33+
call denops_shared_server#runtray#uninstall()
34+
elseif executable('launchctl')
3335
call denops_shared_server#launchctl#uninstall()
3436
elseif executable('systemctl')
3537
call denops_shared_server#systemctl#uninstall()
36-
elseif has('win32')
37-
call denops_shared_server#winsw#uninstall()
3838
else
3939
call denops#util#error('This platform is not supported. Please configure denops-shared-server manually.')
4040
return
-641 KB
Binary file not shown.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"name": "denops-shared-server",
3+
"description": "denops.vim shared server",
4+
"executable": "{{deno}}",
5+
"arguments": [
6+
"run", "-A", "--no-check", "{{script}}",
7+
"--hostname", "{{hostname}}",
8+
"--port", "{{port}}"
9+
]
10+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
let s:file = expand('<sfile>:p')
2+
let s:name = 'denops-shared-server'
3+
let s:local_app_data = isdirectory($LOCALAPPDATA) ? '$LOCALAPPDATA' : '~\AppData\Local'
4+
let s:config_file = expand(printf('%s\denops\%s.json', s:local_app_data, s:name))
5+
let s:script_file = expand(printf('%s\denops\%s.ps1', s:local_app_data, s:name))
6+
let s:config_template_file = printf('%s\runtray.template.json', fnamemodify(s:file, ':h'))
7+
let s:ps_cmd = 'powershell -NoLogo -NoProfile -ExecutionPolicy RemoteSigned -Command'
8+
let s:script_download_url = 'https://raw.githubusercontent.com/Milly/runtray-ps/v1.0.0/runtray.ps1'
9+
10+
function! denops_shared_server#runtray#install(options) abort
11+
let content = denops_shared_server#_render(readfile(s:config_template_file, 'b'), {
12+
\ 'deno': escape(a:options.deno, '\'),
13+
\ 'script': escape(a:options.script, '\'),
14+
\ 'hostname': a:options.hostname,
15+
\ 'port': a:options.port,
16+
\})
17+
call denops#util#info(printf('create the configuration file `%s`', s:config_file))
18+
call mkdir(fnamemodify(s:config_file, ':h'), 'p')
19+
call writefile(content, s:config_file, 'b')
20+
21+
call denops#util#info(printf('download the script `%s`', s:script_file))
22+
echo system(printf(
23+
\ '%s Invoke-WebRequest -URI "%s" -OutFile "%s";Unblock-File "%s"',
24+
\ s:ps_cmd,
25+
\ s:script_download_url,
26+
\ s:script_file,
27+
\ s:script_file,
28+
\))
29+
30+
call denops#util#info('install to the startup')
31+
echo system(printf('%s "%s" install', s:ps_cmd, s:script_file))
32+
33+
call denops#util#info('start the service')
34+
echo system(printf('%s "%s" start', s:ps_cmd, s:script_file))
35+
endfunction
36+
37+
function! denops_shared_server#runtray#uninstall() abort
38+
call denops#util#info('uninstall from the startup')
39+
call system(printf('%s "%s" uninstall', s:ps_cmd, s:script_file))
40+
41+
call denops#util#info(printf('delete the configuration file `%s`', s:config_file))
42+
call delete(s:config_file)
43+
44+
call denops#util#info(printf('delete the script `%s`', s:script_file))
45+
call delete(s:script_file)
46+
endfunction

autoload/denops_shared_server/winsw.template

Lines changed: 0 additions & 10 deletions
This file was deleted.

autoload/denops_shared_server/winsw.vim

Lines changed: 0 additions & 43 deletions
This file was deleted.

0 commit comments

Comments
 (0)