Skip to content

Commit dc96e0a

Browse files
authored
Merge pull request #4 from Milly/feat/powershell-startup
windows: install to startup with powershell
2 parents a4c3f4a + 981868c commit dc96e0a

File tree

7 files changed

+80
-67
lines changed

7 files changed

+80
-67
lines changed

README.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,16 @@ And uninstall the server with `denops_shared_server#uninstall()` like
2121

2222
This plugin uses the following methods to install the shared server on the system.
2323

24-
| OS | Method |
25-
| ------- | -------------------------------------------------- |
26-
| Windows | Bundled [WinSW v2](https://github.com/winsw/winsw) |
27-
| macOS | System's `launchctl` (launchd) |
28-
| Linux | System's `systemctl` (systemd) |
24+
| OS | Method |
25+
| ------- | -------------------------------------------- |
26+
| Windows | System's `powershell.exe` and [runtray-ps][] |
27+
| macOS | System's `launchctl` (launchd) |
28+
| Linux | System's `systemctl` (systemd) |
2929

30-
Note that Windows user requires .NET Framework 4.6.1 (preinstalled since Windows 10 November Update version 1511).
30+
Note that Windows user requires PowerShell 3.0 (preinstalled since Windows 8).
31+
[runtray-ps][]'s script file is automatically downloaded.
32+
33+
[runtray-ps]: https://github.com/Milly/runtray-ps
3134

3235
## License
3336

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: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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+
call denops_shared_server#runtray#_download_file(s:script_download_url, s:script_file)
23+
call denops_shared_server#runtray#_remove_zone_identifier(s:script_file)
24+
25+
call denops#util#info('install to the startup')
26+
call denops_shared_server#runtray#_execute_script_command('install')
27+
28+
call denops#util#info('start the service')
29+
call denops_shared_server#runtray#_execute_script_command('start')
30+
endfunction
31+
32+
function! denops_shared_server#runtray#uninstall() abort
33+
call denops#util#info('uninstall from the startup')
34+
call denops_shared_server#runtray#_execute_script_command('uninstall')
35+
36+
call denops#util#info(printf('delete the configuration file `%s`', s:config_file))
37+
call delete(s:config_file)
38+
39+
call denops#util#info(printf('delete the script `%s`', s:script_file))
40+
call delete(s:script_file)
41+
endfunction
42+
43+
function denops_shared_server#runtray#_download_file(url, outfile) abort
44+
echo system(printf('%s Invoke-WebRequest -URI "%s" -OutFile "%s"', s:ps_cmd, a:url, a:outfile))
45+
endfunction
46+
47+
function denops_shared_server#runtray#_remove_zone_identifier(file) abort
48+
echo system(printf('%s Unblock-File "%s"', s:ps_cmd, a:file))
49+
endfunction
50+
51+
function denops_shared_server#runtray#_execute_script_command(command) abort
52+
echo system(printf('%s "%s" %s', s:ps_cmd, s:script_file, a:command))
53+
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)