Skip to content

Commit 8e644db

Browse files
authored
remove kb fixed (keybase#24968)
* Revert "Revert "Remove kb (keybase#24964)" (keybase#24967)" This reverts commit 510ccd8. * always use invoke
1 parent 3705790 commit 8e644db

59 files changed

Lines changed: 974 additions & 852 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎shared/actions/chat2/index.tsx‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ import {NotifyPopup} from '../../native/notifications'
3333
import {isIOS} from '../../constants/platform'
3434
import {privateFolderWithUsers, teamFolder} from '../../constants/config'
3535
import {saveAttachmentToCameraRoll, showShareActionSheet} from '../platform-specific'
36+
import KB2 from '../../util/electron'
37+
38+
const {darwinCopyToChatTempUploadFile} = KB2.functions
3639

3740
const onConnect = async () => {
3841
try {
@@ -2325,10 +2328,8 @@ const attachFromDragAndDrop = async (
23252328
_: Container.TypedState,
23262329
action: Chat2Gen.AttachFromDragAndDropPayload
23272330
) => {
2328-
if (Platform.isDarwin) {
2329-
const paths = await Promise.all(
2330-
action.payload.paths.map(p => KB.kb.darwinCopyToChatTempUploadFile(p.path))
2331-
)
2331+
if (Platform.isDarwin && darwinCopyToChatTempUploadFile) {
2332+
const paths = await Promise.all(action.payload.paths.map(p => darwinCopyToChatTempUploadFile(p.path)))
23322333
return Chat2Gen.createAttachmentsUpload({
23332334
conversationIDKey: action.payload.conversationIDKey,
23342335
paths,

‎shared/actions/config-gen.tsx‎

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎shared/actions/fs/index.tsx‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ import {tlfToPreferredOrder} from '../../util/kbfs'
1818
import {errorToActionOrThrow} from './shared'
1919
import {NotifyPopup} from '../../native/notifications'
2020
import type {RPCError} from '../../util/errors'
21+
import KB2 from '../../util/electron'
22+
23+
const {darwinCopyToKBFSTempUploadFile} = KB2.functions
2124

2225
const clientID = Constants.makeUUID()
2326

@@ -437,9 +440,9 @@ const loadUploadStatus = async () => {
437440
}
438441

439442
const uploadFromDragAndDrop = async (_: Container.TypedState, action: FsGen.UploadFromDragAndDropPayload) => {
440-
if (Platform.isDarwin) {
443+
if (Platform.isDarwin && darwinCopyToKBFSTempUploadFile) {
441444
const localPaths = await Promise.all(
442-
action.payload.localPaths.map(async localPath => KB.kb.darwinCopyToKBFSTempUploadFile(localPath))
445+
action.payload.localPaths.map(async localPath => darwinCopyToKBFSTempUploadFile(localPath))
443446
)
444447
return localPaths.map(localPath =>
445448
FsGen.createUpload({

‎shared/actions/fs/platform-specific.desktop.tsx‎

Lines changed: 12 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -20,72 +20,10 @@ import logger from '../../logger'
2020
import {spawn, execFile, exec} from 'child_process'
2121
import {errorToActionOrThrow} from './shared'
2222
import * as RouteTreeGen from '../route-tree-gen'
23+
import * as Path from '../../util/path'
24+
import KB2 from '../../util/electron.desktop'
2325

24-
const {path} = KB
25-
26-
type pathType = 'file' | 'directory'
27-
28-
// pathToURL takes path and converts to (file://) url.
29-
// See https://github.com/sindresorhus/file-url
30-
function pathToURL(p: string): string {
31-
let goodPath = p.replace(/\\/g, '/')
32-
33-
// Windows drive letter must be prefixed with a slash
34-
if (!goodPath.startsWith('/')) {
35-
goodPath = '/' + goodPath
36-
}
37-
38-
return encodeURI('file://' + goodPath).replace(/#/g, '%23')
39-
}
40-
41-
const openInDefaultDirectory = async (openPath: string): Promise<void> => {
42-
return new Promise((resolve, reject) => {
43-
// Paths in directories might be symlinks, so resolve using
44-
// realpath.
45-
// For example /keybase/private/gabrielh,chris gets redirected to
46-
// /keybase/private/chris,gabrielh.
47-
fs.realpath(openPath, (err, resolvedPath) => {
48-
if (err) {
49-
reject(new Error(`No realpath for ${openPath}`))
50-
return
51-
}
52-
// Convert to URL for openExternal call.
53-
// We use openExternal instead of openItem because it
54-
// correctly focuses' the Finder, and also uses a newer
55-
// native API on macOS.
56-
const url = pathToURL(resolvedPath)
57-
logger.info('Open URL (directory):', url)
58-
59-
remote.shell
60-
.openExternal(url, {activate: true})
61-
.then(() => {
62-
logger.info('Opened directory:', openPath)
63-
resolve()
64-
})
65-
.catch(err => {
66-
reject(err)
67-
})
68-
})
69-
})
70-
}
71-
72-
async function getPathType(openPath: string): Promise<pathType> {
73-
return new Promise((resolve, reject) => {
74-
fs.stat(openPath, (err, stats) => {
75-
if (err) {
76-
reject(new Error(`Unable to open/stat file: ${openPath}`))
77-
return
78-
}
79-
if (stats.isFile()) {
80-
resolve('file')
81-
} else if (stats.isDirectory()) {
82-
resolve('directory')
83-
} else {
84-
reject(new Error(`Unable to open: Not a file or directory`))
85-
}
86-
})
87-
})
88-
}
26+
const {openInDefaultDirectory, openURL, getPathType} = KB2.functions
8927

9028
// _openPathInSystemFileManagerPromise opens `openPath` in system file manager.
9129
// If isFolder is true, it just opens it. Otherwise, it shows it in its parent
@@ -102,7 +40,7 @@ const _openPathInSystemFileManagerPromise = async (openPath: string, isFolder: b
10240
reject(new Error('unable to open item'))
10341
})
10442
} else {
105-
openInDefaultDirectory(openPath).then(resolve, reject)
43+
openInDefaultDirectory?.(openPath).then(resolve, reject)
10644
}
10745
} else {
10846
remote.shell.showItemInFolder(openPath)
@@ -112,8 +50,12 @@ const _openPathInSystemFileManagerPromise = async (openPath: string, isFolder: b
11250

11351
const openLocalPathInSystemFileManager = async (action: FsGen.OpenLocalPathInSystemFileManagerPayload) => {
11452
try {
115-
const pathType = await getPathType(action.payload.localPath)
116-
return _openPathInSystemFileManagerPromise(action.payload.localPath, pathType === 'directory')
53+
if (getPathType) {
54+
const pathType = await getPathType(action.payload.localPath)
55+
return _openPathInSystemFileManagerPromise(action.payload.localPath, pathType === 'directory')
56+
} else {
57+
throw new Error('impossible')
58+
}
11759
} catch (e) {
11860
return errorToActionOrThrow(e)
11961
}
@@ -127,7 +69,7 @@ const escapeBackslash = isWindows
12769
: (pathElem: string): string => pathElem
12870

12971
const _rebaseKbfsPathToMountLocation = (kbfsPath: Types.Path, mountLocation: string) =>
130-
path.resolve(mountLocation, Types.getPathElements(kbfsPath).slice(1).map(escapeBackslash).join(pathSep))
72+
Path.join(mountLocation, Types.getPathElements(kbfsPath).slice(1).map(escapeBackslash).join(pathSep))
13173

13274
const openPathInSystemFileManager = async (
13375
state: TypedState,
@@ -305,8 +247,7 @@ const uninstallDokan = (state: TypedState) => {
305247
}
306248

307249
const openSecurityPreferences = () => {
308-
remote.shell
309-
.openExternal('x-apple.systempreferences:com.apple.preference.security?General', {activate: true})
250+
openURL?.('x-apple.systempreferences:com.apple.preference.security?General', {activate: true})
310251
.then(() => {
311252
logger.info('Opened Security Preferences')
312253
})
@@ -448,7 +389,6 @@ function* platformSpecificSaga() {
448389
yield* Saga.chainAction2(FsGen.driverDisabling, uninstallKBFS)
449390
}
450391
yield* Saga.chainAction2(FsGen.openSecurityPreferences, openSecurityPreferences)
451-
yield* Saga.chainAction2(FsGen.openSecurityPreferences, openSecurityPreferences)
452392
yield* Saga.chainAction2(ConfigGen.changedFocus, changedFocus)
453393
yield* Saga.chainAction2(
454394
[FsGen.setSfmiBannerDismissed, FsGen.driverEnable, FsGen.driverDisable],

‎shared/actions/json/config.json‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,14 @@
147147
"component": "string",
148148
"param": "string"
149149
},
150+
"updateWindowShown": {
151+
"_description": "a window was shown",
152+
"component": "string"
153+
},
154+
"updateWindowMaxState": {
155+
"_description": "main electron window changed max/min",
156+
"max": "boolean"
157+
},
150158
"updateWindowState": {
151159
"_description": "main electron window wants to store its state",
152160
"windowState": "Types.WindowState"

‎shared/actions/platform-specific/index.desktop.tsx‎

Lines changed: 11 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ import * as Electron from 'electron'
77
import * as Saga from '../../util/saga'
88
import logger from '../../logger'
99
import {NotifyPopup} from '../../native/notifications'
10-
import {execFile} from 'child_process'
1110
import {getEngine} from '../../engine'
12-
import {isLinux, isWindows, socketPath, defaultUseNativeFrame} from '../../constants/platform.desktop'
11+
import {isLinux, isWindows, defaultUseNativeFrame} from '../../constants/platform.desktop'
1312
import {kbfsNotification} from '../../util/kbfs-notifications'
1413
import {quit} from '../../desktop/app/ctl.desktop'
1514
import {writeLogLinesToFile} from '../../util/forward-logs'
@@ -20,8 +19,7 @@ import {_getNavigator} from '../../constants/router2'
2019
import type {RPCError} from 'util/errors'
2120
import KB2 from '../../util/electron.desktop'
2221

23-
const {resolve} = KB.path
24-
const {env} = KB2
22+
const {showMainWindow, activeChanged, requestWindowsStartService} = KB2.functions
2523

2624
export function showShareActionSheet() {
2725
throw new Error('Show Share Action - unsupported on this platform')
@@ -32,13 +30,6 @@ export async function saveAttachmentToCameraRoll() {
3230
)
3331
}
3432

35-
const showMainWindow = () => {
36-
Electron.ipcRenderer
37-
.invoke('KBkeybase', {type: 'showMainWindow'})
38-
.then(() => {})
39-
.catch(() => {})
40-
}
41-
4233
export function displayNewMessageNotification() {
4334
throw new Error('Display new message notification not available on this platform')
4435
}
@@ -85,13 +76,7 @@ function* initializeInputMonitor(): Iterable<any> {
8576
const userActive = type === 'active'
8677
yield Saga.put(ConfigGen.createChangedActive({userActive}))
8778
// let node thread save file
88-
Electron.ipcRenderer
89-
.invoke('KBkeybase', {
90-
payload: {changedAtMs: Date.now(), isUserActive: userActive},
91-
type: 'activeChanged',
92-
})
93-
.then(() => {})
94-
.catch(() => {})
79+
activeChanged?.(Date.now(), userActive)
9580
}
9681
}
9782
}
@@ -107,7 +92,6 @@ export const dumpLogs = async (action?: ConfigGen.DumpLogsPayload) => {
10792
}
10893
}
10994

110-
// TODO move
11195
function* checkRPCOwnership(_: Container.TypedState, action: ConfigGen.DaemonHandshakePayload) {
11296
const waitKey = 'pipeCheckFail'
11397
yield Saga.put(
@@ -116,30 +100,9 @@ function* checkRPCOwnership(_: Container.TypedState, action: ConfigGen.DaemonHan
116100
try {
117101
logger.info('Checking RPC ownership')
118102

119-
const localAppData = String(env.LOCALAPPDATA)
120-
const binPath = localAppData ? resolve(localAppData, 'Keybase', 'keybase.exe') : 'keybase.exe'
121-
const args = ['pipeowner', socketPath]
122-
yield Saga.callUntyped(
123-
async () =>
124-
new Promise<void>((resolve, reject) => {
125-
execFile(binPath, args, {windowsHide: true}, (error, stdout) => {
126-
if (error) {
127-
logger.info(`pipeowner check result: ${stdout.toString()}`)
128-
// error will be logged in bootstrap check
129-
getEngine().reset()
130-
reject(error)
131-
return
132-
}
133-
const result = JSON.parse(stdout.toString())
134-
if (result.isOwner) {
135-
resolve(undefined)
136-
return
137-
}
138-
logger.info(`pipeowner check result: ${stdout.toString()}`)
139-
reject(new Error('pipeowner check failed'))
140-
})
141-
})
142-
)
103+
if (KB2.functions.winCheckRPCOwnership) {
104+
yield Saga.callUntyped(KB2.functions.winCheckRPCOwnership)
105+
}
143106
yield Saga.put(
144107
ConfigGen.createDaemonHandshakeWait({
145108
increment: false,
@@ -148,6 +111,8 @@ function* checkRPCOwnership(_: Container.TypedState, action: ConfigGen.DaemonHan
148111
})
149112
)
150113
} catch (error_) {
114+
// error will be logged in bootstrap check
115+
getEngine().reset()
151116
const error = error_ as RPCError
152117
yield Saga.put(
153118
ConfigGen.createDaemonHandshakeWait({
@@ -204,7 +169,7 @@ const onShutdown = (action: EngineGen.Keybase1NotifyServiceShutdownPayload) => {
204169

205170
const onConnected = () => {
206171
// Introduce ourselves to the service
207-
RPCTypes.configHelloIAmRpcPromise({details: KB2.helloDetails}).catch(() => {})
172+
RPCTypes.configHelloIAmRpcPromise({details: KB2.constants.helloDetails}).catch(() => {})
208173
}
209174

210175
const onOutOfDate = (action: EngineGen.Keybase1NotifySessionClientOutOfDatePayload) => {
@@ -239,10 +204,7 @@ const sendWindowsKBServiceCheck = (
239204
state.config.daemonHandshakeWaiters.size === 0 &&
240205
state.config.daemonHandshakeFailedReason === ConfigConstants.noKBFSFailReason
241206
) {
242-
Electron.ipcRenderer
243-
.invoke('KBkeybase', {type: 'requestWindowsStartService'})
244-
.then(() => {})
245-
.catch(() => {})
207+
requestWindowsStartService?.()
246208
}
247209
}
248210

@@ -448,7 +410,7 @@ function* checkNav(
448410
export function* platformConfigSaga() {
449411
yield* Saga.chainAction2(ConfigGen.setOpenAtLogin, setOpenAtLogin)
450412
yield* Saga.chainAction2(ConfigGen.setNotifySound, setNotifySound)
451-
yield* Saga.chainAction2(ConfigGen.showMain, showMainWindow)
413+
yield* Saga.chainAction2(ConfigGen.showMain, () => showMainWindow?.())
452414
yield* Saga.chainAction(ConfigGen.dumpLogs, dumpLogs)
453415
getEngine().registerCustomResponse('keybase.1.logsend.prepareLogsend')
454416
yield* Saga.chainAction(EngineGen.keybase1LogsendPrepareLogsend, prepareLogSend)

‎shared/actions/typed-actions-gen.tsx‎

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)