UNPKG

s-bit-agent

Version:

s.BitAgent is a simple Bitwarden CLI wrapper which provides a SSH2 Key Agent solution for Bitwarden.

77 lines 3.27 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.LaunchAgentAutostartService = void 0; const common_1 = require("@nestjs/common"); const fs = require("fs"); const child_process = require("child_process"); const plist = require("plist"); let LaunchAgentAutostartService = class LaunchAgentAutostartService { constructor() { this.name = 'Launch Agent Autostart (macOS)'; } async canActivate() { return process.platform === 'darwin'; } async install(command, name, marker) { try { const homeDir = process.env.HOME; if (!homeDir) { throw new Error('Could not determine user home directory'); } const agentFilePath = `${homeDir}/Library/LaunchAgents/${name}-${marker}.plist`; const plistContent = plist.build({ Label: `${name}-${marker}`, ProgramArguments: ['sh', '-c', command], RunAtLoad: true, }); fs.writeFileSync(agentFilePath, plistContent); child_process.execSync(`launchctl load -w ${agentFilePath}`); return true; } catch (error) { console.error('Error installing Launch Agent autostart:', error); return false; } } async uninstall(marker) { try { const homeDir = process.env.HOME; if (!homeDir) { throw new Error('Could not determine user home directory'); } const agentFilePath = `${homeDir}/Library/LaunchAgents/${name}-${marker}.plist`; child_process.execSync(`launchctl unload -w ${agentFilePath}`); fs.unlinkSync(agentFilePath); return true; } catch (error) { console.error('Error uninstalling Launch Agent autostart:', error); return false; } } async isInstalled(marker) { try { const homeDir = process.env.HOME; if (!homeDir) { throw new Error('Could not determine user home directory'); } const agentFilePath = `${homeDir}/Library/LaunchAgents/${name}-${marker}.plist`; return fs.existsSync(agentFilePath); } catch (error) { console.error('Error checking if Launch Agent autostart is installed:', error); return false; } } }; exports.LaunchAgentAutostartService = LaunchAgentAutostartService; exports.LaunchAgentAutostartService = LaunchAgentAutostartService = __decorate([ (0, common_1.Injectable)() ], LaunchAgentAutostartService); //# sourceMappingURL=macos.service.js.map