Skip to content

Commit

Permalink
chore: wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Dwynr committed Jul 29, 2024
1 parent 1d0096a commit caf1028
Show file tree
Hide file tree
Showing 36 changed files with 2,135 additions and 1,604 deletions.
Binary file added assets/icons/app/win32/dark/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/icons/app/win32/light/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/icons/tray/dark/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/icons/tray/dark/iconNotification.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/icons/tray/light/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/icons/tray/light/iconNotification.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
685 changes: 590 additions & 95 deletions package-lock.json

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"@typescript-eslint/eslint-plugin": "^6.20.0",
"@typescript-eslint/parser": "^6.20.0",
"cross-env": "^7.0.3",
"electron": "^31.1.0",
"electron": "^31.3.0",
"eslint": "^8.56.0",
"jest": "^29.7.0",
"rimraf": "^5.0.5",
Expand All @@ -56,11 +56,12 @@
"wait-on": "^7.2.0"
},
"dependencies": {
"@filen/s3": "^0.2.12",
"@filen/s3": "^0.2.13",
"@filen/sdk": "^0.1.134",
"@filen/sync": "^0.1.5",
"@filen/sync": "^0.1.8",
"@filen/web": "^0.1.2",
"@filen/webdav": "^0.2.19",
"@filen/webdav": "^0.2.20",
"axios": "^1.7.2",
"diskusage-ng": "^1.0.4",
"find-free-ports": "^3.1.1",
"fs-extra": "^11.2.0",
Expand Down
33 changes: 33 additions & 0 deletions src/assets/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { nativeImage, nativeTheme } from "electron"
import pathModule from "path"

export function getAppIcon(notificationCount: number) {
return nativeImage.createFromPath(
pathModule.join(
__dirname,
"..",
"..",
"assets",
"icons",
"app",
process.platform,
nativeTheme.shouldUseDarkColors ? "light" : "dark",
notificationCount > 0 ? `iconNotification${notificationCount > 9 ? 99 : notificationCount}.png` : "icon.png"
)
)
}

export function getTrayIcon(notificationCount: number) {
return nativeImage.createFromPath(
pathModule.join(
__dirname,
"..",
"..",
"assets",
"icons",
"tray",
nativeTheme.shouldUseDarkColors ? "light" : "dark",
notificationCount > 0 ? "iconNotification.png" : "icon.png"
)
)
}
8 changes: 1 addition & 7 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,7 @@ import { type FilenDesktopConfig } from "./types"
export let CONFIG: FilenDesktopConfig | null = null

export function setConfig(config: FilenDesktopConfig): void {
CONFIG = {
...config,
sdkConfig: {
...config.sdkConfig,
connectToSocket: true
}
}
CONFIG = config

console.log("Desktop config set")
}
Expand Down
55 changes: 41 additions & 14 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import { app, BrowserWindow, shell, protocol } from "electron"
import WebDAV from "./webdav"
import VirtualDrive from "./virtualDrive"
import Sync from "./sync"
import { app, BrowserWindow, shell, protocol, Tray, nativeTheme } from "electron"
import pathModule from "path"
import IPC from "./ipc"
import FilenSDK from "@filen/sdk"
import { waitForConfig } from "./config"
import Cloud from "./lib/cloud"
import FS from "./lib/fs"
import S3 from "./s3"
import url from "url"
import { IS_ELECTRON } from "./constants"
import Worker from "./worker"
import { getAppIcon, getTrayIcon } from "./assets"

if (IS_ELECTRON) {
// Needs to be here, otherwise Chromium's FileSystemAccess API won't work. Waiting for the electron team to fix it.
Expand All @@ -29,17 +27,16 @@ if (IS_ELECTRON) {
*/
export class FilenDesktop {
public driveWindow: BrowserWindow | null = null
public readonly webdav: WebDAV
public readonly virtualDrive: VirtualDrive
public readonly sync: Sync
public readonly ipc: IPC
public readonly sdk: FilenSDK
public readonly s3: S3
public readonly worker: Worker
public sdkInitialized: boolean = false
public readonly lib: {
cloud: Cloud
fs: FS
}
public notificationCount = 0
public tray: Tray | null = null

/**
* Creates an instance of FilenDesktop.
Expand All @@ -55,10 +52,7 @@ export class FilenDesktop {
cloud: new Cloud(this),
fs: new FS(this)
}
this.webdav = new WebDAV()
this.s3 = new S3()
this.virtualDrive = new VirtualDrive()
this.sync = new Sync(this)
this.worker = new Worker(this)
}

/**
Expand Down Expand Up @@ -96,6 +90,7 @@ export class FilenDesktop {

await app.whenReady()

// Handle frontend bundle loading in production via file://
protocol.interceptFileProtocol("file", (req, callback) => {
const url = req.url.slice(7)

Expand All @@ -110,7 +105,12 @@ export class FilenDesktop {
}
})

app.setUserTasks([])
app.setName("Filen")

await this.worker.start()
await this.createMainWindow()
await this.worker.invoke("restartSync")
}

private async createMainWindow(): Promise<void> {
Expand All @@ -126,10 +126,14 @@ export class FilenDesktop {
minWidth: 1280,
minHeight: 720,
titleBarStyle: "hidden",
icon: getAppIcon(this.notificationCount),
trafficLightPosition: {
x: 10,
y: 10
},
backgroundColor: "rgba(0, 0, 0, 0)",
hasShadow: true,
show: false,
webPreferences: {
backgroundThrottling: false,
autoplayPolicy: "no-user-gesture-required",
Expand All @@ -142,10 +146,28 @@ export class FilenDesktop {
}
})

this.tray = new Tray(getTrayIcon(this.notificationCount))
this.tray.setTitle("Filen")
this.tray.setContextMenu(null)
this.tray.setToolTip("Filen")

this.tray.on("click", () => {
this.driveWindow?.show()
})

this.driveWindow.setThumbarButtons([])

this.driveWindow.on("closed", () => {
this.driveWindow = null
})

// Handle different icons based on the user's theme (dark/light)
nativeTheme.on("updated", () => {
this.driveWindow?.setIcon(getAppIcon(this.notificationCount))
this.tray?.setImage(getTrayIcon(this.notificationCount))
})

// Open links in default external browser
this.driveWindow.webContents.setWindowOpenHandler(({ url }) => {
shell.openExternal(url)

Expand All @@ -163,6 +185,10 @@ export class FilenDesktop {
})
: "http://localhost:5173"
)

if (!app.commandLine.hasSwitch("hidden") && !process.argv.includes("--hidden")) {
this.driveWindow.show()
}
}
}

Expand All @@ -171,7 +197,8 @@ if (IS_ELECTRON) {
}

export { deserializeError, serializeError } from "@filen/sync"
export default FilenDesktop
export { DesktopAPI } from "./preload"
export * from "./utils"
export * from "./constants"

export default FilenDesktop
Loading

0 comments on commit caf1028

Please sign in to comment.