Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
小 白蛋
Lens
Commits
d40071a9
Unverified
Commit
d40071a9
authored
3 years ago
by
Sebastian Malton
Committed by
GitHub
3 years ago
Browse files
Options
Download
Email Patches
Plain Diff
Fix CommandOverlay for extension API (#4673)
parent
58ffb8e3
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
src/extensions/as-legacy-globals-for-extension-api/as-legacy-global-function-for-extension-api.ts
+48
-0
...ension-api/as-legacy-global-function-for-extension-api.ts
src/extensions/as-legacy-globals-for-extension-api/as-legacy-global-object-for-extension-api.ts
+57
-0
...xtension-api/as-legacy-global-object-for-extension-api.ts
src/extensions/as-legacy-globals-for-extension-api/as-legacy-global-singleton-for-extension-api.ts
+59
-0
...nsion-api/as-legacy-global-singleton-for-extension-api.ts
src/extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api.ts
+29
-0
...s-for-extension-api/legacy-global-di-for-extension-api.ts
src/extensions/renderer-api/components.ts
+4
-1
src/extensions/renderer-api/components.ts
src/renderer/getDi.tsx
+9
-3
src/renderer/getDi.tsx
with
206 additions
and
4 deletions
+206
-4
src/extensions/as-legacy-globals-for-extension-api/as-legacy-global-function-for-extension-api.ts
0 → 100644
+
48
-
0
View file @
d40071a9
/**
* Copyright (c) 2021 OpenLens Authors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
import
type
{
Injectable
}
from
"
@ogre-tools/injectable
"
;
import
{
getLegacyGlobalDiForExtensionApi
}
from
"
./legacy-global-di-for-extension-api
"
;
type
TentativeTuple
<
T
>
=
T
extends
object
?
[
T
]
:
[
undefined
?];
type
FactoryType
=
<
TInjectable
extends
Injectable
<
unknown
,
TInstance
,
TInstantiationParameter
>
,
TInstantiationParameter
,
TInstance
extends
(...
args
:
unknown
[])
=>
any
,
TFunction
extends
(...
args
:
unknown
[])
=>
any
=
Awaited
<
ReturnType
<
TInjectable
[
"
instantiate
"
]
>
>
,
>
(
injectableKey
:
TInjectable
,
...
instantiationParameter
:
TentativeTuple
<
TInstantiationParameter
>
)
=>
(...
args
:
Parameters
<
TFunction
>
)
=>
ReturnType
<
TFunction
>
;
export
const
asLegacyGlobalFunctionForExtensionApi
:
FactoryType
=
(
injectableKey
,
...
instantiationParameter
)
=>
(...
args
)
=>
{
const
injected
=
getLegacyGlobalDiForExtensionApi
().
inject
(
injectableKey
,
...
instantiationParameter
,
);
return
injected
(...
args
);
};
This diff is collapsed.
Click to expand it.
src/extensions/as-legacy-globals-for-extension-api/as-legacy-global-object-for-extension-api.ts
0 → 100644
+
57
-
0
View file @
d40071a9
/**
* Copyright (c) 2021 OpenLens Authors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
import
type
{
Injectable
}
from
"
@ogre-tools/injectable
"
;
import
{
getLegacyGlobalDiForExtensionApi
}
from
"
./legacy-global-di-for-extension-api
"
;
type
TentativeTuple
<
T
>
=
T
extends
object
?
[
T
]
:
[
undefined
?];
export
const
asLegacyGlobalObjectForExtensionApi
=
<
TInjectable
extends
Injectable
<
unknown
,
unknown
,
TInstantiationParameter
>
,
TInstantiationParameter
,
>
(
injectableKey
:
TInjectable
,
...
instantiationParameter
:
TentativeTuple
<
TInstantiationParameter
>
)
=>
new
Proxy
(
{},
{
get
(
target
,
propertyName
)
{
if
(
propertyName
===
"
$$typeof
"
)
{
return
undefined
;
}
const
instance
:
any
=
getLegacyGlobalDiForExtensionApi
().
inject
(
injectableKey
,
...
instantiationParameter
,
);
const
propertyValue
=
instance
[
propertyName
];
if
(
typeof
propertyValue
===
"
function
"
)
{
return
function
(...
args
:
any
[])
{
return
propertyValue
.
apply
(
instance
,
args
);
};
}
return
propertyValue
;
},
},
)
as
ReturnType
<
TInjectable
[
"
instantiate
"
]
>
;
This diff is collapsed.
Click to expand it.
src/extensions/as-legacy-globals-for-extension-api/as-legacy-global-singleton-for-extension-api.ts
0 → 100644
+
59
-
0
View file @
d40071a9
/**
* Copyright (c) 2021 OpenLens Authors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
import
type
{
Injectable
}
from
"
@ogre-tools/injectable
"
;
import
{
getLegacyGlobalDiForExtensionApi
}
from
"
./legacy-global-di-for-extension-api
"
;
type
TentativeTuple
<
T
>
=
T
extends
object
?
[
T
]
:
[
undefined
?];
export
const
asLegacyGlobalSingletonForExtensionApi
=
<
TClass
extends
abstract
new
(...
args
:
any
[])
=>
any
,
TInjectable
extends
Injectable
<
unknown
,
unknown
,
TInstantiationParameter
>
,
TInstantiationParameter
,
>
(
Class
:
TClass
,
injectableKey
:
TInjectable
,
...
instantiationParameter
:
TentativeTuple
<
TInstantiationParameter
>
)
=>
new
Proxy
(
Class
,
{
construct
:
()
=>
{
throw
new
Error
(
"
A legacy singleton class must be created by createInstance()
"
);
},
get
:
(
target
:
any
,
propertyName
)
=>
{
if
(
propertyName
===
"
getInstance
"
||
propertyName
===
"
createInstance
"
)
{
return
()
=>
getLegacyGlobalDiForExtensionApi
().
inject
(
injectableKey
,
...
instantiationParameter
,
);
}
if
(
propertyName
===
"
resetInstance
"
)
{
return
()
=>
getLegacyGlobalDiForExtensionApi
().
purge
(
injectableKey
);
}
return
target
[
propertyName
];
},
})
as
InstanceType
<
TClass
>
&
{
getInstance
:
()
=>
InstanceType
<
TClass
>
;
createInstance
:
()
=>
InstanceType
<
TClass
>
;
resetInstance
:
()
=>
void
;
};
This diff is collapsed.
Click to expand it.
src/extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api.ts
0 → 100644
+
29
-
0
View file @
d40071a9
/**
* Copyright (c) 2021 OpenLens Authors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
import
type
{
DependencyInjectionContainer
}
from
"
@ogre-tools/injectable
"
;
let
legacyGlobalDi
:
DependencyInjectionContainer
;
export
const
setLegacyGlobalDiForExtensionApi
=
(
di
:
DependencyInjectionContainer
)
=>
{
legacyGlobalDi
=
di
;
};
export
const
getLegacyGlobalDiForExtensionApi
=
()
=>
legacyGlobalDi
;
This diff is collapsed.
Click to expand it.
src/extensions/renderer-api/components.ts
+
4
-
1
View file @
d40071a9
...
...
@@ -19,6 +19,9 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
import
commandOverlayInjectable
from
"
../../renderer/components/command-palette/command-overlay.injectable
"
;
import
{
asLegacyGlobalObjectForExtensionApi
}
from
"
../as-legacy-globals-for-extension-api/as-legacy-global-object-for-extension-api
"
;
// layouts
export
*
from
"
../../renderer/components/layout/main-layout
"
;
export
*
from
"
../../renderer/components/layout/setting-layout
"
;
...
...
@@ -36,7 +39,7 @@ export * from "../../renderer/components/switch";
export
*
from
"
../../renderer/components/input/input
"
;
// command-overlay
export
{
CommandOverlay
}
from
"
../../renderer/components/command-palette
"
;
export
const
CommandOverlay
=
asLegacyGlobalObjectForExtensionApi
(
commandOverlayInjectable
)
;
// other components
export
*
from
"
../../renderer/components/icon
"
;
...
...
This diff is collapsed.
Click to expand it.
src/renderer/getDi.tsx
+
9
-
3
View file @
d40071a9
...
...
@@ -20,14 +20,20 @@
*/
import
{
createContainer
}
from
"
@ogre-tools/injectable
"
;
import
{
setLegacyGlobalDiForExtensionApi
}
from
"
../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api
"
;
export
const
getDi
=
()
=>
createContainer
(
export
function
getDi
()
{
const
di
=
createContainer
(
getRequireContextForRendererCode
,
getRequireContextForCommonCode
,
getRequireContextForCommonExtensionCode
,
getRequireContextForCommonCode
,
);
setLegacyGlobalDiForExtensionApi
(
di
);
return
di
;
}
const
getRequireContextForRendererCode
=
()
=>
require
.
context
(
"
./
"
,
true
,
/
\.
injectable
\.(
ts|tsx
)
$/
);
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment