close watcher

rdesktop
filip mertens 2 years ago
parent 6778a113f8
commit bea74d4124
  1. 4
      apps/1test/package.json
  2. 6
      apps/1test/src/electron/engine.ts
  3. 30
      apps/1test/src/electron/fsPlugin.ts
  4. 8
      apps/1test/src/electron/gitPlugin.ts
  5. 5
      apps/1test/src/index.ts
  6. 14
      apps/1test/src/renderer.ts
  7. 42
      apps/1test/yarn.lock

@ -39,6 +39,8 @@
"typescript": "~4.5.4" "typescript": "~4.5.4"
}, },
"dependencies": { "dependencies": {
"electron-squirrel-startup": "^1.0.0" "chokidar": "^3.5.3",
"electron-squirrel-startup": "^1.0.0",
"fix-path": "^4.0.0"
} }
} }

@ -2,6 +2,7 @@ import { Engine, PluginManager, Plugin } from '@remixproject/engine';
import { ipcMain, ipcRenderer } from 'electron'; import { ipcMain, ipcRenderer } from 'electron';
import { FSPlugin } from './fsPlugin'; import { FSPlugin } from './fsPlugin';
import { GitPlugin } from './gitPlugin'; import { GitPlugin } from './gitPlugin';
import { app } from 'electron';
const engine = new Engine() const engine = new Engine()
const appManager = new PluginManager() const appManager = new PluginManager()
@ -18,3 +19,8 @@ ipcMain.handle('engine:activatePlugin', async (event, arg) => {
} }
return await appManager.activatePlugin(arg) return await appManager.activatePlugin(arg)
}) })
app.on('window-all-closed', async () => {
await appManager.call('fs', 'closeWatch')
console.log('quit')
})

@ -4,6 +4,7 @@ import { Plugin } from '@remixproject/engine';
import fs from 'fs/promises' import fs from 'fs/promises'
import { Stats } from "fs"; import { Stats } from "fs";
import { Profile } from "@remixproject/plugin-utils"; import { Profile } from "@remixproject/plugin-utils";
import chokidar from 'chokidar'
const profile: Profile = { const profile: Profile = {
displayName: 'fs', displayName: 'fs',
@ -12,21 +13,28 @@ const profile: Profile = {
} }
export class FSPlugin extends Plugin { export class FSPlugin extends Plugin {
client: PluginClient client: FSPluginClient
constructor(){ constructor() {
super(profile) super(profile)
this.methods = ['closeWatch']
} }
onActivation(): void { onActivation(): void {
this.client = new FSPluginClient() this.client = new FSPluginClient()
} }
async closeWatch(): Promise<void> {
console.log('closeWatch')
await this.client.closeWatch()
}
} }
class FSPluginClient extends PluginClient { class FSPluginClient extends PluginClient {
constructor(){ watcher: chokidar.FSWatcher
constructor() {
super() super()
this.methods = ['readdir', 'readFile', 'writeFile', 'mkdir', 'rmdir', 'unlink', 'rename', 'stat', 'exists'] this.methods = ['readdir', 'readFile', 'writeFile', 'mkdir', 'rmdir', 'unlink', 'rename', 'stat', 'exists', 'watch', 'closeWatch']
createClient(this, profile) createClient(this, profile)
this.onload(() => { this.onload(() => {
console.log('fsPluginClient onload') console.log('fsPluginClient onload')
@ -70,6 +78,20 @@ class FSPluginClient extends PluginClient {
return fs.access(path).then(() => true).catch(() => false) return fs.access(path).then(() => true).catch(() => false)
} }
async watch(path: string): Promise<void> {
console.log('watch', path)
if(this.watcher) this.watcher.close()
this.watcher =
chokidar.watch(path).on('change', (path, stats) => {
console.log('change', path, stats)
this.emit('change', path, stats)
})
}
async closeWatch(): Promise<void> {
console.log('closeWatch')
if(this.watcher) this.watcher.close()
}
} }

@ -33,7 +33,13 @@ class GitPluginClient extends PluginClient {
} }
async log(path: string): Promise<string> { async log(path: string): Promise<string> {
const log = spawn('git', ['log'], { cwd: path }) const log = spawn('git', ['log'], {
cwd: path,
env: {
NODE_ENV: 'production',
PATH: process.env.PATH,
},
})
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
log.stdout.on('data', (data) => { log.stdout.on('data', (data) => {

@ -1,11 +1,16 @@
import { app, BrowserWindow } from 'electron'; import { app, BrowserWindow } from 'electron';
import path from 'path'; import path from 'path';
import fixPath from 'fix-path';
// This allows TypeScript to pick up the magic constants that's auto-generated by Forge's Webpack // This allows TypeScript to pick up the magic constants that's auto-generated by Forge's Webpack
// plugin that tells the Electron app where to look for the Webpack-bundled app code (depending on // plugin that tells the Electron app where to look for the Webpack-bundled app code (depending on
// whether you're running in development or production). // whether you're running in development or production).
declare const MAIN_WINDOW_WEBPACK_ENTRY: string; declare const MAIN_WINDOW_WEBPACK_ENTRY: string;
declare const MAIN_WINDOW_PRELOAD_WEBPACK_ENTRY: string; declare const MAIN_WINDOW_PRELOAD_WEBPACK_ENTRY: string;
console.log(process.env.PATH);
fixPath();
console.log(process.env.PATH);
// Handle creating/removing shortcuts on Windows when installing/uninstalling. // Handle creating/removing shortcuts on Windows when installing/uninstalling.
if (require('electron-squirrel-startup')) { if (require('electron-squirrel-startup')) {
app.quit(); app.quit();

@ -7,22 +7,28 @@ import { gitPlugin } from './remix/gitPlugin';
class MyAppManager extends PluginManager { class MyAppManager extends PluginManager {
onActivation(): void { onActivation(): void {
this.on('fs', 'loaded', async () => { this.on('fs', 'loaded', async () => {
const files = await this.call('fs', 'readdir', './src') const files = await this.call('fs', 'readdir', './')
console.log('files', files) console.log('files', files)
let exists = await this.call('fs', 'exists', './src') let exists = await this.call('fs', 'exists', '/Volumes/bunsen/code/rmproject2/remix-project/')
console.log('exists', exists) console.log('exists', exists)
exists = await this.call('fs', 'exists', './notexists') exists = await this.call('fs', 'exists', './notexists')
console.log('exists', exists) console.log('exists', exists)
// stat test // stat test
const stat = await this.call('fs', 'stat', './src') const stat = await this.call('fs', 'stat', '/Volumes/bunsen/code/rmproject2/remix-project/')
console.log('stat', stat) console.log('stat', stat)
// read file test // read file test
const content = await this.call('fs', 'readFile', './src/index.html') const content = await this.call('fs', 'readFile', './src/index.html')
console.log('content', content) console.log('content', content)
await this.call('fs', 'watch', '/Volumes/bunsen/code/rmproject2/remix-project/')
this.on('fs', 'change', (path: string, stats: any) => {
console.log('change', path, stats)
})
}) })
this.on('git', 'loaded', async () => { this.on('git', 'loaded', async () => {
const log = await this.call('git', 'log', './src') const log = await this.call('git', 'log', '/Volumes/bunsen/code/rmproject2/remix-project/')
console.log('log', log) console.log('log', log)
}) })
} }

@ -1090,6 +1090,11 @@ ansi-regex@^5.0.1:
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-5.0.1.tgz#082cb2c89c9fe8659a311a53bd6a4dc5301db304" resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-5.0.1.tgz#082cb2c89c9fe8659a311a53bd6a4dc5301db304"
integrity sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ== integrity sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==
ansi-regex@^6.0.1:
version "6.0.1"
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-6.0.1.tgz#3183e38fae9a65d7cb5e53945cd5897d0260a06a"
integrity sha512-n5M855fKb2SsfMIiFFoVrABHJC8QtHwVx+mHWP3QcEqBHYienj5dHSgjbxtC0WEZXYt4wcD6zrQElDPhFuZgfA==
ansi-styles@^3.2.1: ansi-styles@^3.2.1:
version "3.2.1" version "3.2.1"
resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-3.2.1.tgz#41fbb20243e50b12be0f04b8dedbf07520ce841d" resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-3.2.1.tgz#41fbb20243e50b12be0f04b8dedbf07520ce841d"
@ -1819,6 +1824,11 @@ default-gateway@^6.0.3:
dependencies: dependencies:
execa "^5.0.0" execa "^5.0.0"
default-shell@^2.0.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/default-shell/-/default-shell-2.2.0.tgz#31481c19747bfe59319b486591643eaf115a1864"
integrity sha512-sPpMZcVhRQ0nEMDtuMJ+RtCxt7iHPAMBU+I4tAlo5dU1sjRpNax0crj6nR3qKpvVnckaQ9U38enXcwW9nZJeCw==
defaults@^1.0.3: defaults@^1.0.3:
version "1.0.4" version "1.0.4"
resolved "https://registry.yarnpkg.com/defaults/-/defaults-1.0.4.tgz#b0b02062c1e2aa62ff5d9528f0f98baa90978d7a" resolved "https://registry.yarnpkg.com/defaults/-/defaults-1.0.4.tgz#b0b02062c1e2aa62ff5d9528f0f98baa90978d7a"
@ -2394,7 +2404,7 @@ execa@^1.0.0:
signal-exit "^3.0.0" signal-exit "^3.0.0"
strip-eof "^1.0.0" strip-eof "^1.0.0"
execa@^5.0.0: execa@^5.0.0, execa@^5.1.1:
version "5.1.1" version "5.1.1"
resolved "https://registry.yarnpkg.com/execa/-/execa-5.1.1.tgz#f80ad9cbf4298f7bd1d4c9555c21e93741c411dd" resolved "https://registry.yarnpkg.com/execa/-/execa-5.1.1.tgz#f80ad9cbf4298f7bd1d4c9555c21e93741c411dd"
integrity sha512-8uSpZZocAZRBAPIEINJj3Lo9HyGitllczc27Eh5YYojjMFMn8yHMDMaUHE2Jqfq05D/wucwI4JGURyXt1vchyg== integrity sha512-8uSpZZocAZRBAPIEINJj3Lo9HyGitllczc27Eh5YYojjMFMn8yHMDMaUHE2Jqfq05D/wucwI4JGURyXt1vchyg==
@ -2582,6 +2592,13 @@ find-up@^5.0.0:
locate-path "^6.0.0" locate-path "^6.0.0"
path-exists "^4.0.0" path-exists "^4.0.0"
fix-path@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/fix-path/-/fix-path-4.0.0.tgz#bc1d14f038edb734ac46944a45454106952ca429"
integrity sha512-g31GX207Tt+psI53ZSaB1egprYbEN0ZYl90aKcO22A2LmCNnFsSq3b5YpoKp3E/QEiWByTXGJOkFQG4S07Bc1A==
dependencies:
shell-path "^3.0.0"
flat-cache@^3.0.4: flat-cache@^3.0.4:
version "3.0.4" version "3.0.4"
resolved "https://registry.yarnpkg.com/flat-cache/-/flat-cache-3.0.4.tgz#61b0338302b2fe9f957dcc32fc2a87f1c3048b11" resolved "https://registry.yarnpkg.com/flat-cache/-/flat-cache-3.0.4.tgz#61b0338302b2fe9f957dcc32fc2a87f1c3048b11"
@ -5009,6 +5026,22 @@ shebang-regex@^3.0.0:
resolved "https://registry.yarnpkg.com/shebang-regex/-/shebang-regex-3.0.0.tgz#ae16f1644d873ecad843b0307b143362d4c42172" resolved "https://registry.yarnpkg.com/shebang-regex/-/shebang-regex-3.0.0.tgz#ae16f1644d873ecad843b0307b143362d4c42172"
integrity sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A== integrity sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==
shell-env@^4.0.0:
version "4.0.1"
resolved "https://registry.yarnpkg.com/shell-env/-/shell-env-4.0.1.tgz#883302d9426095d398a39b102a851adb306b8cb8"
integrity sha512-w3oeZ9qg/P6Lu6qqwavvMnB/bwfsz67gPB3WXmLd/n6zuh7TWQZtGa3iMEdmua0kj8rivkwl+vUjgLWlqZOMPw==
dependencies:
default-shell "^2.0.0"
execa "^5.1.1"
strip-ansi "^7.0.1"
shell-path@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/shell-path/-/shell-path-3.0.0.tgz#5c95bc68aade43c06082a0655cb5c97586e4feb0"
integrity sha512-HNIZ+W/3P0JuVTV03xjGqYKt3e3h0/Z4AH8TQWeth1LBtCusSjICgkdNdb3VZr6mI7ijE2AiFFpgkVMNKsALeQ==
dependencies:
shell-env "^4.0.0"
shell-quote@^1.7.3: shell-quote@^1.7.3:
version "1.8.1" version "1.8.1"
resolved "https://registry.yarnpkg.com/shell-quote/-/shell-quote-1.8.1.tgz#6dbf4db75515ad5bac63b4f1894c3a154c766680" resolved "https://registry.yarnpkg.com/shell-quote/-/shell-quote-1.8.1.tgz#6dbf4db75515ad5bac63b4f1894c3a154c766680"
@ -5228,6 +5261,13 @@ strip-ansi@^6.0.0, strip-ansi@^6.0.1:
dependencies: dependencies:
ansi-regex "^5.0.1" ansi-regex "^5.0.1"
strip-ansi@^7.0.1:
version "7.1.0"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-7.1.0.tgz#d5b6568ca689d8561370b0707685d22434faff45"
integrity sha512-iq6eVVI64nQQTRYq2KtEg2d2uU7LElhTJwsH4YzIHZshxlgZms/wIc4VoDQTlG/IvVIrBKG06CrZnp0qv7hkcQ==
dependencies:
ansi-regex "^6.0.1"
strip-bom@^3.0.0: strip-bom@^3.0.0:
version "3.0.0" version "3.0.0"
resolved "https://registry.yarnpkg.com/strip-bom/-/strip-bom-3.0.0.tgz#2334c18e9c759f7bdd56fdef7e9ae3d588e68ed3" resolved "https://registry.yarnpkg.com/strip-bom/-/strip-bom-3.0.0.tgz#2334c18e9c759f7bdd56fdef7e9ae3d588e68ed3"

Loading…
Cancel
Save