|
| 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 |
0 commit comments