Files
spacedrive/scripts/tauri.mjs
Vítor Vasconcellos ea92383b78 Improve file thumbnails and Quick Preview (+ some code clean-up and rust deps update) (#2758)
* Update rspc, prisma-client-rust, axum and tanstack-query
 - Deleted some unused examples and fully commented out frontend code
 - Implement many changes required due to the updates
 - Update most rust dependencies

* Re-enable p2p

* Fix server

* Auto format

* Fix injected script format
 - Update some github actions
 - Update pnpm lock file

* Fix devtools showing up when app opens
 - Fix million complaining about Sparkles component

* Fix sd-server

* Fix and improve thumbnails rendering
 - Fix core always saying a new thumbnail was generated even for files that it skiped thumbnail generation
 - Rewrite FileThumb and improve related components

* Ignore tmp files when running prettier

* Improve FileThumb component performance
 - Rework useExplorerDraggable and useExplorerItemData hooks due to reduce unecessary re-renders

* More fixes for thumb component
 - A couple of minor performance improvements to frontend code

* auto format

* Fix Thumbnail and QuickPreview

* Fix logic for when to show 'fail to load original' error message in QuickPreview
 - Updated prisma-client-rust, libp2p, tauri, tauri-specta, rspc and hyper

* Fix type checking
 - Format scripts

* Add script prettier config

* Fix serde missing feature
 - Use rust-libp2p spacedrive fork again
 - Update rspc

* Autoformat + fix pnpm lock

* Fix thumbnail first load again

* Autoformat

* autoformat

* Fix rust-libp2p fork url again?

* Remove usePathsInfiniteQuery hook

* Update tauri 2.0.6
2024-10-21 15:47:40 +00:00

136 lines
4.0 KiB
JavaScript
Executable File

#!/usr/bin/env node
import * as fs from 'node:fs/promises'
import * as path from 'node:path'
import { env, exit, platform, umask } from 'node:process'
import { setTimeout } from 'node:timers/promises'
import { fileURLToPath } from 'node:url'
import { parse as parseTOML } from 'smol-toml'
import { waitLockUnlock } from './utils/flock.mjs'
import { patchTauri } from './utils/patchTauri.mjs'
import { symlinkSharedLibsLinux } from './utils/shared.mjs'
import spawn from './utils/spawn.mjs'
if (/^(msys|mingw|cygwin)$/i.test(env.OSTYPE ?? '')) {
console.error(
'Bash for windows is not supported, please interact with this repo from Powershell or CMD'
)
exit(255)
}
// Limit file permissions
umask(0o026)
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
const [_, __, ...args] = process.argv
// NOTE: Must point to package root path
const __root = path.resolve(path.join(__dirname, '..'))
// Location for desktop app
const desktopApp = path.join(__root, 'apps', 'desktop')
// Location of the native dependencies
const nativeDeps = path.join(__root, 'apps', '.deps')
// Files to be removed when script finish executing
const __cleanup = /** @type {string[]} */ ([])
const cleanUp = () => Promise.all(__cleanup.map(file => fs.unlink(file).catch(() => {})))
process.on('SIGINT', cleanUp)
// Export environment variables defined in cargo.toml
const cargoConfig = await fs
.readFile(path.resolve(__root, '.cargo', 'config.toml'), { encoding: 'binary' })
.then(parseTOML)
if (cargoConfig.env && typeof cargoConfig.env === 'object')
for (const [name, value] of Object.entries(cargoConfig.env)) if (!env[name]) env[name] = value
// Default command
if (args.length === 0) args.push('build')
const targets = args
.filter((_, index, args) => {
if (index === 0) return false
const previous = args[index - 1]
return previous === '-t' || previous === '--target'
})
.flatMap(target => target.split(','))
const bundles = args
.filter((_, index, args) => {
if (index === 0) return false
const previous = args[index - 1]
return previous === '-b' || previous === '--bundles'
})
.flatMap(target => target.split(','))
let code = 0
if (process.platform === 'linux' && (args[0] === 'dev' || args[0] === 'build'))
await symlinkSharedLibsLinux(__root, nativeDeps)
try {
switch (args[0]) {
case 'dev': {
__cleanup.push(...(await patchTauri(__root, nativeDeps, targets, args)))
switch (process.platform) {
case 'linux':
case 'darwin':
void waitLockUnlock(path.join(__root, 'target', 'debug', '.cargo-lock')).then(
() => setTimeout(1000).then(cleanUp),
() => {}
)
break
}
break
}
case 'build': {
if (!env.NODE_OPTIONS || !env.NODE_OPTIONS.includes('--max_old_space_size')) {
env.NODE_OPTIONS = `--max_old_space_size=4096 ${env.NODE_OPTIONS ?? ''}`
}
env.GENERATE_SOURCEMAP = 'false'
__cleanup.push(...(await patchTauri(__root, nativeDeps, targets, args)))
}
}
await spawn('pnpm', ['exec', 'tauri', ...args], desktopApp)
if (args[0] === 'build' && bundles.some(bundle => bundle === 'deb' || bundle === 'all')) {
const linuxTargets = targets.filter(target => target.includes('-linux-'))
if (linuxTargets.length > 0)
for (const target of linuxTargets) {
env.TARGET = target
await spawn(path.join(__dirname, 'fix-deb.sh'), [], __dirname)
}
else if (process.platform === 'linux')
await spawn(path.join(__dirname, 'fix-deb.sh'), [], __dirname)
}
} catch (error) {
console.error(
`tauri ${args[0]} failed with exit code ${typeof error === 'number' ? error : 1}`
)
console.warn(
`If you got an error related to libav*/FFMpeg or Protoc/Protobuf you may need to re-run \`pnpm prep\``,
`If you got an error related to missing nasm you need to run ${
platform === 'win32' ? './scripts/setup.ps1' : './scripts/setup.sh'
}`
)
if (typeof error === 'number') {
code = error
} else {
if (error instanceof Error) console.error(error)
code = 1
}
} finally {
cleanUp()
exit(code)
}